Skip to content

Fix Docker setup - #98

Open
mateusdeap wants to merge 18 commits into
mainfrom
fix-docker-setup
Open

Fix Docker setup#98
mateusdeap wants to merge 18 commits into
mainfrom
fix-docker-setup

Conversation

@mateusdeap

Copy link
Copy Markdown
Member

What is this PR:

  • Bug fix
  • Feature
  • Chore

Description:
This updates the docker setup for the audit app. Changes docker-compose.yml to build web_next and adds several improvements that help avoid issues with changing dependencies, undesired cache busting when changing application code and also implements caching when running bundle install

The changes that are actually needed are only the ones configuring web_next to get built from the Dockerfile and removing the version pinning on the bundle install command. The rest is just improvements that I'm suggesting here

How has this been tested?

  • Automated tests
  • Manual tests

What manual tests have been run?
Delete all your local images of for the audit app and attempt to setup the app as in the README.

The rest are standard docker features that require no testing, as long as images build successfully and docker compose up spins up both containers without issues.

This just ensures BuildKit uses the latest version of Dockerfile syntax
This lets us drop the options in the command and also guarantees these
options are set when running bundler commands inside the container.
Using an absolute path for BUNDLE_GEMFILE also guarantees bundler
commands work properly in subdirectories inside the container
This prevents cache busting the entrypoint copy on changes to the
application code.
service_started doesn't prevent race conditions since the web service
may have started and db operations might still be working. Rails
provides an `/up` endpoint which guarantees the _app_ is up. Only after
that is it safe to run the entrypoint script
Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
@mateusdeap
mateusdeap requested a review from arielj August 4, 2026 12:16

@arielj arielj left a comment

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 left some questions, I'm not sure I understand some of the code

Comment thread bin/docker/setup Outdated
Comment thread bin/docker/setup Outdated
Comment thread bin/docker/setup Outdated
@mateusdeap

Copy link
Copy Markdown
Member Author

@arielj I've removed the branches that were in there to run in CI. I also fixed the permissions on the bon/docker/run script

@mateusdeap
mateusdeap requested a review from arielj August 10, 2026 17:40

@arielj arielj left a comment

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'm trying to run this locally, just clonned the project

when I run the setup command I get a db connection error:

== Copy .env ==
== Setup Database ==

== Copying sample files ==
== Build images ==
[+] Building 1.4s (14/14) FINISHED                                                                                                                                                                                                            
 => [internal] load local bake definitions                                                                                                                                                                                               0.0s
 => => reading from stdin 565B                                                                                                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                     0.0s
 => => transferring dockerfile: 812B                                                                                                                                                                                                     0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                                                                                                                                                                0.6s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ecfaec9ed6d810b56388c508f4121597bfbba70d41a6dfeee4d8cad5f295fc32                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/ruby:4.0.4                                                                                                                                                                            0.6s
 => [internal] load .dockerignore                                                                                                                                                                                                        0.0s
 => => transferring context: 178B                                                                                                                                                                                                        0.0s
 => [stage-0 1/5] FROM docker.io/library/ruby:4.0.4@sha256:8b9d39df3e5a2e6b8a488fd07e58d9589ab8fbce79afdabf8b141eb359eafeea                                                                                                              0.0s
 => [internal] load build context                                                                                                                                                                                                        0.0s
 => => transferring context: 172B                                                                                                                                                                                                        0.0s
 => CACHED [stage-0 2/5] RUN dpkg --add-architecture i386   && apt-get update -qq   && apt-get install -y --no-install-recommends     libpq-dev     postgresql-client     imagemagick     fontconfig     libxrender1     libxext6     x  0.0s
 => CACHED [stage-0 3/5] WORKDIR /app                                                                                                                                                                                                    0.0s
 => CACHED [stage-0 4/5] COPY Gemfile Gemfile.lock Gemfile.next Gemfile.next.lock .ruby-version ./                                                                                                                                       0.0s
 => CACHED [stage-0 5/5] RUN --mount=type=cache,target=/usr/local/bundle/cache,sharing=locked   bundle install                                                                                                                           0.0s
 => exporting to image                                                                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                                                                  0.0s
 => => writing image sha256:addd9713b549af2444cc134c2a49c94032cc23c8211e42b588e9e96d1737d14f                                                                                                                                             0.0s
 => => naming to docker.io/library/audit-web                                                                                                                                                                                             0.0s
 => resolving provenance for metadata file                                                                                                                                                                                               0.0s
[+] Building 1/1
 ✔ audit-web  Built                                                                                                                                                                                                                      0.0s 
connection to server at "127.0.0.1", port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?
Couldn't create 'vulnerable-gems-development' database. Please check your configuration.
bin/rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: Connection refused (ActiveRecord::ConnectionNotEstablished)
	Is the server running on that host and accepting TCP/IP connections?


Caused by:
PG::ConnectionBad: connection to server at "127.0.0.1", port 5432 failed: Connection refused (PG::ConnectionBad)
	Is the server running on that host and accepting TCP/IP connections?

Tasks: TOP => db:create
(See full trace by running task with --trace)

== Command [" rails db:create db:migrate"] failed ==

if I ignore that and start the app anyway, I have to create the db and run migrations but then it fails saying there's no V8 runtime:

Image

Attempting to reuse the web image presumes it already exists locally.
Furthermore, it's better to have them build separately since their
dependencies can be different
Provides a build context and pass in the needed build args
We don't run these images in CI and the setup script was using root
permissions without a clear reason. Removed the tests on the CI
environment to fix both issues

@arielj arielj left a comment

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.

Added some comments

Comment thread bin/docker/setup
Comment on lines +25 to +26
cp ".env.sample", ".env.local"
system! "ln -s .env.local .env.test"

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.

we should add these files to the .gitignore file

Comment thread README.md

- `db` — Postgres 16
- `web` — the app on http://localhost:3000, running against the default `Gemfile` (currently Rails 8.1)
- `web_next` — the same image, but with `BUNDLE_GEMFILE=Gemfile.next`, on http://localhost:3001 (see "Dual-boot Rails upgrades" below)

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 line is being removed but it's the only line that mentions that the "next" server runs in port 3001

when you run the "next" app, the log shows port 3000 (which is the one inside the container)

BUNDLE_GEMFILE=Gemfile.next bin/docker/start
[+] Running 1/1
 ✔ Container audit-db-1  Running                                                                                                                                                                                                         0.0s 
Attaching to web_next-1
web_next-1  | => Booting Puma
web_next-1  | => Rails 8.1.3 application starting in development 
web_next-1  | => Run `bin/rails server --help` for more startup options
web_next-1  | Puma starting in single mode...
web_next-1  | * Puma version: 8.0.2 ("Into the Arena")
web_next-1  | * Ruby version: ruby 4.0.4 (2026-05-12 revision b89eb1bcbf) +PRISM [x86_64-linux]
web_next-1  | *  Min threads: 5
web_next-1  | *  Max threads: 5
web_next-1  | *  Environment: development
web_next-1  | *          PID: 1
web_next-1  | * Listening on http://0.0.0.0:3000
web_next-1  | Use Ctrl-C to stop

but if you click that link, it fails, because docker is exposing it as 3001 instead

I think we should change the command of the web-next service to include "-p 3001" and the port to be "3001:3001", so then the logs shows Listening on http://0.0.0.0:3001 with the correct port and clicking it opens the browser in the correct url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants