Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions bin/docker-debug-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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'
15 changes: 13 additions & 2 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions docker-compose.override.yml.example
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
services:
db:
image: postgres:14
image: postgres:17
environment:
- POSTGRES_DB
- POSTGRES_PASSWORD
- POSTGRES_USER
Comment thread
danhalson marked this conversation as resolved.
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 5s
timeout: 5s
retries: 5
start_period: 5s
ports:
- "5434:5432"
volumes:
Expand All @@ -16,9 +22,12 @@ services:
target: builder
image: editor-api:builder
depends_on:
- db
db:
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
Expand Down Expand Up @@ -46,3 +55,5 @@ services:

volumes:
postgres-data:
bundle-data:
node_modules: