[Docker] Add a devcontainer

This removes the need for all the ruby-lsp setup stuff.

ruby-lsp will try to install the debug gem which contains native code, add that to the gemfile so it doesn't cause trouble.

I'm probably going to remove the rubocop/test compose services at some point. With devcontainers you are just able to run the commands directly.
This commit is contained in:
Earlopain 2024-01-12 20:50:24 +00:00
parent 5c14472878
commit fa9fb531f7
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
8 changed files with 69 additions and 29 deletions

View File

@ -0,0 +1,28 @@
{
"name": "E621ng project development",
"dockerComposeFile": "../docker-compose.yml",
"service": "e621",
"workspaceFolder": "/app",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {}
},
"postAttachCommand": {
// Workaround for https://github.com/microsoft/vscode-remote-release/issues/6810
// Put it back into the Dockerfile once that is resolved
"git-safe-dir": "git config --global --add safe.directory /app"
},
"postCreateCommand": {
"bash-completion": "apk --no-cache add bash-completion && echo 'source /etc/bash/bash_completion.sh' >> ~/.bash_profile"
},
"customizations": {
"vscode": {
"extensions": [
"Shopify.ruby-lsp",
"Vue.volar"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
}
}
}
}

View File

@ -3,7 +3,7 @@
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": ["Shopify.ruby-lsp"],
"recommendations": ["ms-vscode-remote.remote-containers"],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"[ruby]": {
"editor.formatOnSave": false
},
// Trick ruby-lsp into not doing any updates
"rubyLsp.bundleGemfile": "Gemfile",
}

View File

@ -22,8 +22,6 @@ RUN apk --no-cache add ffmpeg vips \
WORKDIR /app
RUN git config --global --add safe.directory $(pwd)
ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2
ENV RUBY_YJIT_ENABLE=1

View File

@ -46,6 +46,7 @@ group :development, :test do
end
group :development do
gem "debug", require: false
gem "rubocop", require: false
gem "rubocop-erb", require: false
gem "rubocop-rails", require: false

View File

@ -109,6 +109,9 @@ GEM
crass (1.0.6)
dalli (3.2.6)
date (3.3.4)
debug (1.9.1)
irb (~> 1.10)
reline (>= 0.3.8)
diffy (3.4.2)
domain_name (0.6.20231109)
dotenv (2.8.1)
@ -147,6 +150,10 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.7.1)
irb (1.11.1)
rdoc
reline (>= 0.4.2)
json (2.7.0)
jsonapi-renderer (0.2.2)
kgio (2.11.4)
@ -202,6 +209,8 @@ GEM
racc
pg (1.5.4)
prism (0.19.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
puma (6.4.0)
nio4r (~> 2.0)
@ -245,12 +254,16 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rdoc (6.6.2)
psych (>= 4.0.0)
recaptcha (5.16.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.18.0)
connection_pool
regexp_parser (2.8.2)
reline (0.4.2)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.1)
@ -320,6 +333,7 @@ GEM
sorbet-runtime (0.5.11188)
streamio-ffmpeg (3.0.2)
multi_json (~> 1.8)
stringio (3.1.0)
thor (1.3.0)
timeout (0.4.1)
tzinfo (2.0.6)
@ -354,6 +368,7 @@ DEPENDENCIES
bcrypt
bootsnap
dalli
debug
diffy
dotenv-rails
draper

View File

@ -4,19 +4,14 @@
* Latest version of Docker ([download](https://docs.docker.com/get-docker)).
* Latest version of Docker Compose ([download](https://docs.docker.com/compose/install))
* Git ([download](https://git-scm.com/downloads))
If you are on Windows Docker Compose is already included, you do not need to install it yourself.
If you are on Linux/MacOS you can probably use your package manager.
### Windows development environment
It is recommended to work exclusively inside of WSL for performance and compatibility reasons. You can use something like [Remote Development for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) for this. All following instructions will assume that you are in a Linux environment.
### Installation
1. Install the [prerequisites](#prerequisites) to your host.
1. If on Windows, [set up WSL 2](https://learn.microsoft.com/en-us/windows/wsl/install) and open a terminal.
1. [Install git](https://git-scm.com/download/linux).
1. Download and install the [prerequisites](#prerequisites).
1. Clone the repo with `git clone https://github.com/e621ng/e621ng.git`.
1. `cd` into the repo.
1. Copy the sample environment file with `cp .env.sample .env`.
@ -30,36 +25,32 @@ It is recommended to work exclusively inside of WSL for performance and compatib
Note: When gems or js packages are updated you need to execute `docker compose build` to reflect them in the container.
### Development environment
This repo provides a Dev Container configuration. You can use something like the [Dev Container extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) to make use of it. Simply install it, open the folder in VSCode, and click the button in the bottom right to open the folder in the Dev Container.
#### <a id="docker-troubleshooting"></a>I followed the above instructions but it doesn't work, what should I do?
Try this:
1. `docker compose down -v` to remove all volumes.
1. `docker compose build --no-cache` to rebuild the image from scratch.
1. Follow the [instructions](#installation) starting from step 7.
1. Follow the [instructions](#installation) starting from step 5.
#### <a id="windows-executable-bit"></a>Why are there a bunch of changes I can't revert?
You're most likely using Windows. Give this a shot, it tells Git to stop tracking file mode changes:
`git config core.fileMode false`
#### <a id="development-tools"></a>Things to aid you during development
`docker compose run --rm tests` to execute the test suite.
`bin/rails tests` to execute the test suite.
`docker compose run --rm rubocop` to run the linter.
`bundle exec rubocop` to run the linter.
The postgres server accepts outside connections which you can use to access it with a local client. Use `localhost:34517` to connect to a database named `e621_development` with the user `e621`. Leave the password blank, anything will work.
#### Ruby LSP
This repo comes with [Ruby LSP](https://github.com/Shopify/ruby-lsp) preconfigured, install its [VSCode extension](https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp) and follow the instructions if you want to make use of it. The only requirement is that the Ruby version used by e621 is installed.
I recommend [rbenv](https://github.com/rbenv/rbenv) to manage your Ruby versions:
1. Install rbenv with [rbenv-installer](https://github.com/rbenv/rbenv-installer), or follow the [installation instructions](https://github.com/rbenv/rbenv#installation) on the rbenv repo.
1. Install the [necessary dependencies](https://github.com/rbenv/ruby-build/wiki#suggested-build-environment) to build ruby.
1. Run `rbenv install`
1. Install dependencies needed for bundler to install all gems. You can get an idea of those from the [Dockerfile](https://github.com/e621ng/e621ng/blob/master/Dockerfile#L3).
For Ubuntu and derivatives you can just run `apt install cmake pkg-config libpq-dev`.
1. Run `bundle install` to validate that everything can install correctly.
1. Restart VSCode for good measure and you should be ready to go.
## Production Setup
Installation follows the same steps as the docker compose file. Ubuntu 20.04 is the current installation target.

View File

@ -15,6 +15,8 @@ x-environment: &common-env
DANBOORU_REPLACEMENT_FILE_SECRET: b35bc54cdc0d0436fc5867c7ef88f9b10a37ae20a06b37e67614fe60019d7bb1
SECRET_TOKEN: 1c58518a891eff4520cadc59afa9e378a9325f1247544ff258096e497f095f45
SESSION_SECRET_KEY: 44b4f44e9f253c406cbe727d403d500c1cecff943e4d2aea8f5447f28846fffe
# Hide annoying output from libvips on corrupt files
VIPS_WARNING: "0"
x-depends-on: &common-depends-on
opensearch:
@ -144,8 +146,6 @@ services:
environment:
<<: *common-env
RAILS_ENV: test
# Hide annoying output from libvips on corrupt files
VIPS_WARNING: "0"
volumes:
- .:/app
- ./docker/danbooru_local_config.rb:/app/config/danbooru_local_config.rb