From eeb85e947728af5f1e8411576c179c722bf32d95 Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Tue, 18 Nov 2025 14:08:05 +0000 Subject: [PATCH 01/10] Bump docker postgres to v17 --- Dockerfile | 19 ++++++++++--------- docker-compose.yml | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5de430110..940893138 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM ruby:3.2-slim-bullseye as base +FROM ruby:3.2-slim-bullseye AS base RUN gem install bundler \ && apt-get update \ && apt-get upgrade --yes \ && apt-get install --yes --no-install-recommends \ libpq5 libxml2 libxslt1.1 libvips \ curl gnupg graphviz nodejs \ - && echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ - && curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ + && mkdir -p /usr/share/keyrings \ + && curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg \ + && echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ && apt-get update \ - && apt-get install --yes --no-install-recommends postgresql-client-15 \ + && apt-get install --yes --no-install-recommends postgresql-client-17 \ && rm -rf /var/lib/apt/lists/* /var/lib/apt/archives/*.deb ENV TZ='Europe/London' ENV RUBYOPT='-W:no-deprecated -W:no-experimental' @@ -31,11 +32,11 @@ FROM builder AS dev-container RUN apt-get update \ && apt-get install --yes --no-install-recommends sudo git vim zsh ssh curl less RUN sh -c "$(curl -L https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \ - -t robbyrussell \ - -p git -p docker-compose -p yarn \ - -p https://github.com/zsh-users/zsh-autosuggestions \ - # -p https://github.com/marlonrichert/zsh-autocomplete \ - -p https://github.com/unixorn/fzf-zsh-plugin + -t robbyrussell \ + -p git -p docker-compose -p yarn \ + -p https://github.com/zsh-users/zsh-autosuggestions \ + # -p https://github.com/marlonrichert/zsh-autocomplete \ + -p https://github.com/unixorn/fzf-zsh-plugin RUN chsh -s $(which zsh) ${USER} # Slim application image without development dependencies diff --git a/docker-compose.yml b/docker-compose.yml index 3ab356b16..0e0ee7972 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: db: - image: postgres:14 + image: postgres:17 environment: - POSTGRES_DB - POSTGRES_PASSWORD From f172284f11295b25d7f542b8976105c6f817d255 Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Tue, 18 Nov 2025 14:10:56 +0000 Subject: [PATCH 02/10] Add a healthcheck to the db container and ensure the api depends on that --- docker-compose.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0e0ee7972..893365b57 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,12 @@ services: - POSTGRES_DB - POSTGRES_PASSWORD - POSTGRES_USER + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"] + interval: 5s + timeout: 5s + retries: 5 + start_period: 5s ports: - "5434:5432" volumes: @@ -16,7 +22,8 @@ services: target: builder image: editor-api:builder depends_on: - - db + db: + condition: service_healthy volumes: - .:/app # This is here to avoid rails finding stale pid-files in tmp/pids and then From 2ba55b56792d56897e18e9f839e1ccd873ed8475 Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Tue, 18 Nov 2025 14:12:15 +0000 Subject: [PATCH 03/10] Move the bundle and node_moduels to volumes for easier installs, automate install & db migrations via the entrypoints --- bin/docker-debug-entrypoint.sh | 15 +++++++++++++-- bin/docker-entrypoint.sh | 15 +++++++++++++-- docker-compose.yml | 4 ++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/bin/docker-debug-entrypoint.sh b/bin/docker-debug-entrypoint.sh index 8494d46f5..64ae62b41 100755 --- a/bin/docker-debug-entrypoint.sh +++ b/bin/docker-debug-entrypoint.sh @@ -1,4 +1,15 @@ #!/bin/bash +set -euo pipefail # Use strict-mode in based to ensure errors are surfaced early -rails db:prepare -rdbg -n -o -c -- bin/rails s -p 3009 -b '0.0.0.0' +# Check if bundle install needs to be run +bundle check >/dev/null 2>&1 || bundle install --jobs "${BUNDLE_JOBS:-4}" + +# Check if yarn install needs to be run +if [ -f package.json ] && command -v yarn >/dev/null 2>&1; then + yarn install --check-files --frozen-lockfile || yarn install --check-files +fi + +# Prepare the database +bundle exec rails db:prepare + +exec rdbg -n -o -c -- bundle exec rails s -p 3009 -b '0.0.0.0' diff --git a/bin/docker-entrypoint.sh b/bin/docker-entrypoint.sh index b99a8f559..1333b6af5 100755 --- a/bin/docker-entrypoint.sh +++ b/bin/docker-entrypoint.sh @@ -1,4 +1,15 @@ #!/bin/bash +set -euo pipefail # Use strict-mode in based to ensure errors are surfaced early -rails db:prepare -rails server --port 3009 --binding 0.0.0.0 +# Check if bundle install needs to be run +bundle check >/dev/null 2>&1 || bundle install --jobs "${BUNDLE_JOBS:-4}" + +# Check if yarn install needs to be run +if [ -f package.json ] && command -v yarn >/dev/null 2>&1; then + yarn install --check-files --frozen-lockfile || yarn install --check-files +fi + +# Prepare the database +bundle exec rails db:prepare + +exec bundle exec rails server --port 3009 --binding 0.0.0.0 diff --git a/docker-compose.yml b/docker-compose.yml index 893365b57..0b24e365c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,6 +26,8 @@ services: condition: service_healthy volumes: - .:/app + - bundle-data:/usr/local/bundle + - node-modules:/app/node_modules # This is here to avoid rails finding stale pid-files in tmp/pids and then # thinking it is already running: - type: tmpfs @@ -53,3 +55,5 @@ services: volumes: postgres-data: + bundle-data: + node-modules: From 32959a45a0ce435d26fbbba1e8afb2a16ecb667d Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Tue, 18 Nov 2025 14:12:49 +0000 Subject: [PATCH 04/10] Add an example override and update docs for dev containers --- README.md | 37 +++++++++++++++++++++++++++-- docker-compose.override.yml.example | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) create mode 120000 docker-compose.override.yml.example diff --git a/README.md b/README.md index 5b78b07c6..926511633 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,48 @@ Start the application and its dependencies via docker: docker-compose up ``` +### Using the dev-container + +There is a dedicated image called `dev-container`, and the easiest way to use this is to use the override: + +`cp docker-compose.override.yml.example docker-compose.override.yml` + +Now when you run `docker compose up -d` it will always use the `dev-container` image. + +When adding a vscode project the dev-container should be automatically found and a dialog will show asking if +you want to use this, but failing that you can open the cmd palette with `cmd + shift + p` and call: + +`Dev Containers: Reopen in Container` + +If there's an issue, do check the logs, but you can run: + +`Dev Containers: Rebuild and Reopen in Container` + +and there's also a 'without cache' variant, to ensure packages are re-built. + #### Updating gems inside the container -This can be done with the `bin/with-builder.sh` script: +If running inside a dev-container: + +``` +bundle install +``` + +or outside with: + +``` +docker compose run --rm --no-deps api bundle install +``` + +This can also be done with the `bin/with-builder.sh` script: ``` ./bin/with-builder.sh bundle update ``` -which should update the Gems in the container, without the need for rebuilding. +which should update the Gems in the container. + +None of these methods require rebuilding. ### Seeding diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example new file mode 120000 index 000000000..7f5d2839b --- /dev/null +++ b/docker-compose.override.yml.example @@ -0,0 +1 @@ +.devcontainer/docker-compose.yml \ No newline at end of file From 466a3a0e422310e9732cf982775f7c8b9e12e798 Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Tue, 18 Nov 2025 14:39:54 +0000 Subject: [PATCH 05/10] Force copilot to be installed to prevent corrupted state resulting in tikTokenizerWorker.js error --- .devcontainer/devcontainer.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 83da04eea..1d9ac61b4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -39,7 +39,7 @@ "shutdownAction": "none", // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "", + "postCreateCommand": "code --install-extension GitHub.copilot-chat --force", // Configure tool-specific properties. "customizations": { @@ -67,7 +67,9 @@ "shopify.ruby-lsp", "koichisasada.vscode-rdbg", "postman.postman-for-vscode", - "ninoseki.vscode-mogami" + "ninoseki.vscode-mogami", + "GitHub.copilot", + "GitHub.copilot-chat" ], "settings": { "terminal.integrated.defaultProfile.linux": "zsh", @@ -79,7 +81,7 @@ } } } - } + }, // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "devcontainer" From 63265aae67245eac0f59010688287604112dba9c Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Wed, 19 Nov 2025 11:23:32 +0000 Subject: [PATCH 06/10] Remove postCreate --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1d9ac61b4..4373f9fe9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -39,7 +39,7 @@ "shutdownAction": "none", // Uncomment the next line to run commands after the container is created. - "postCreateCommand": "code --install-extension GitHub.copilot-chat --force", + // "postCreateCommand": "", // Configure tool-specific properties. "customizations": { From a3ac6b5a23276665e78393889c1c2eb963248e8e Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Thu, 20 Nov 2025 18:02:35 +0000 Subject: [PATCH 07/10] Correct override example to use node-modules --- .devcontainer/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index c43b9d2cd..5fe9ce9d6 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -11,4 +11,4 @@ services: - node_modules:/app/node_modules volumes: - node_modules: null + node-modules: null From f23d08a3e316ccd8b3062451a93c7af50f2d434d Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Thu, 20 Nov 2025 18:04:15 +0000 Subject: [PATCH 08/10] Fix override example file --- docker-compose.override.yml.example | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) mode change 120000 => 100644 docker-compose.override.yml.example diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example deleted file mode 120000 index 7f5d2839b..000000000 --- a/docker-compose.override.yml.example +++ /dev/null @@ -1 +0,0 @@ -.devcontainer/docker-compose.yml \ No newline at end of file diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example new file mode 100644 index 000000000..5fe9ce9d6 --- /dev/null +++ b/docker-compose.override.yml.example @@ -0,0 +1,14 @@ +services: + api: + build: + context: . + target: dev-container + command: bash bin/docker-debug-entrypoint.sh + volumes: + # - ${HOME}/.bashrc:/root/.bashrc:ro # Map a ~/.bashrc in your home directory for customising bash + - ${HOME}/.ssh:/root/.ssh:ro # To share any ssh keys with the container + - /var/run/docker.sock:/var/run/docker.sock + - node_modules:/app/node_modules + +volumes: + node-modules: null From 9ddbff3dc3678f35a45a7ae311a1a11588661282 Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Thu, 20 Nov 2025 18:09:30 +0000 Subject: [PATCH 09/10] Using node_modules as the real thing is named node_modules --- docker-compose.override.yml.example | 2 +- docker-compose.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example index 5fe9ce9d6..c43b9d2cd 100644 --- a/docker-compose.override.yml.example +++ b/docker-compose.override.yml.example @@ -11,4 +11,4 @@ services: - node_modules:/app/node_modules volumes: - node-modules: null + node_modules: null diff --git a/docker-compose.yml b/docker-compose.yml index 0b24e365c..96d326615 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: volumes: - .:/app - bundle-data:/usr/local/bundle - - node-modules:/app/node_modules + - node_modules:/app/node_modules # This is here to avoid rails finding stale pid-files in tmp/pids and then # thinking it is already running: - type: tmpfs @@ -56,4 +56,4 @@ services: volumes: postgres-data: bundle-data: - node-modules: + node_modules: From d8cae8b00a2f62a3e2cf553856541e57555bbd56 Mon Sep 17 00:00:00 2001 From: Dan Halson Date: Thu, 20 Nov 2025 18:15:13 +0000 Subject: [PATCH 10/10] Should also use underscore --- .devcontainer/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 5fe9ce9d6..c43b9d2cd 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -11,4 +11,4 @@ services: - node_modules:/app/node_modules volumes: - node-modules: null + node_modules: null