Skip to content
Open
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
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.git
.circleci
.github
.DS_Store
coverage
log/*
tmp/*
!log/.keep
Expand Down
23 changes: 15 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
FROM ruby:4.0.4

RUN dpkg --add-architecture i386 \
Expand All @@ -19,24 +20,30 @@ RUN dpkg --add-architecture i386 \
chromium-driver \
&& rm -rf /var/lib/apt/lists/*

RUN gem install bundler -v 2.2.21

WORKDIR /app

COPY Gemfile Gemfile.lock ./
RUN bundle _2.2.21_ install --jobs=4 --retry=3
ENV BUNDLE_GEMFILE=/app/Gemfile \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3

COPY Gemfile Gemfile.lock .ruby-version ./

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the .ruby-version file here? the version is already defined by the base image

RUN --mount=type=cache,target=/usr/local/bundle/cache,sharing=locked \
bundle install

# Dual-boot: Gemfile.next targets the Rails version we're upgrading to.
# Remove this block (and Gemfile.next / Gemfile.next.lock) once the upgrade lands.
COPY Gemfile.next Gemfile.next.lock ./
RUN BUNDLE_GEMFILE=Gemfile.next bundle _2.2.21_ install --jobs=4 --retry=3
RUN --mount=type=cache,target=/usr/local/bundle/cache,sharing=locked \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this Dockerfile is installing both current and next gems but we don't share the image between the web and web-next services

we can instead use a build ARG and only install the gems for that service to speed this up, check the "Dual-Boot Rails" section in this blogpost https://www.fastruby.io/blog/dual-boot-and-docker.html

BUNDLE_GEMFILE=/app/Gemfile.next bundle install

COPY . .
COPY --chmod=0755 docker/entrypoint.sh /usr/local/bin/entrypoint.sh

COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
COPY . .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip copying all the code inside the container since we are using a mounted volume anyway that replaces that with the actual code?


EXPOSE 3000

HEALTHCHECK --interval=10s --timeout=3s --start-period=60s --retries=6 \
CMD curl -fsS http://localhost:3000/up || exit 1

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
11 changes: 3 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ services:
tty: true

web_next:
# Reuse the image built for `web` (compose tags it <project>-web, i.e.
# audit-web) instead of building a second image. Only BUNDLE_GEMFILE
# differs, so a separate build is unnecessary. (Not using `extends` here:
# it merges array fields like `ports` instead of overriding them, which
# would leak web's 3000:3000 mapping into this service too.)
image: audit-web
build: .
platform: linux/amd64
# Distinct pidfile: web and web_next share the same bind-mounted /app, so
# they'd otherwise race on tmp/pids/server.pid and refuse to boot together.
Expand All @@ -53,12 +48,12 @@ services:
DATABASE_HOST: db
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
BUNDLE_GEMFILE: Gemfile.next
BUNDLE_GEMFILE: /app/Gemfile.next
depends_on:
db:
condition: service_healthy
web:
condition: service_started
condition: service_healthy
stdin_open: true
tty: true

Expand Down
Loading