From 810728518c5aed2416b4b0f9b824306b66bfd73e Mon Sep 17 00:00:00 2001 From: Malaber Date: Mon, 13 Apr 2026 15:26:09 +0200 Subject: [PATCH 1/4] Simplify backend Docker images --- .dockerignore | 1 - .gitlab-ci.yml | 3 +++ README.md | 12 +++++------- docker/development/Dockerfile | 8 -------- docker/production/Dockerfile | 8 +++++++- docker/test/Dockerfile | 9 ++++++--- tasks.py | 13 +------------ 7 files changed, 22 insertions(+), 32 deletions(-) delete mode 100644 docker/development/Dockerfile diff --git a/.dockerignore b/.dockerignore index 5778f88..85f5647 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,6 @@ coverage/** docker/** .gitignore .hound.yml -.rspec .rubocop.yml docker-compose.yml README.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8dc62f8..787fcea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,9 @@ stages: - test - deploy +variables: + DOCKER_IMAGE_ENVS: "production test" + include: - project: 'turniere/turniere-infra' file: '/ci/pipeline.yaml' diff --git a/README.md b/README.md index ff52a51..68c6ad0 100644 --- a/README.md +++ b/README.md @@ -31,22 +31,20 @@ bundle exec rspec [Registry](https://gitlab.com/turniere/turniere-backend/container_registry) You can find all our Dockerfiles in the docker directory. -They depend on each other in the following order: `production` → `development` → `test` -This means, to build the `development` image, you have to build the `production` image first and tag it with the corresponding tag that is mentioned in the `FROM` line in the `development` Dockerfile. +They depend on each other in the following order: `production` → `test` +This means, to build `test` image, you have to build `production` image first and tag it with corresponding tag that is mentioned in `FROM` line in `test` Dockerfile. To build all images do: ```bash cd turniere-backend docker build -t registry.gitlab.com/turniere/turniere-backend/production -f docker/production/Dockerfile . -docker build -t registry.gitlab.com/turniere/turniere-backend/development -f docker/development/Dockerfile . docker build -t registry.gitlab.com/turniere/turniere-backend/test -f docker/test/Dockerfile . ``` -This is done to leave test and development dependencies out of the production container. -Also we have a dedicated test container which runs the tests reproducible when you start it, but can also run the normal rails server to somewhat debug problems occuring in the test suite if needed. +This is done to leave test and development dependencies out of production container. +Also we have dedicated test container which runs tests reproducible when you start it, but can also run normal rails server to debug problems occuring in test suite if needed. -While developing, if you want to use the development docker container, it should™ be sufficient to mount the root of this repository into the /app folder within the docker container to avoid building it over and over again. -**Only rebuilding the `development` container is not sufficient, as the `development` Dockerfile does not have a `COPY` Statement** +While developing, use `test` image as base container and mount root of this repository into `/app` to avoid rebuilding it over and over again. ## Generate diagrams diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile deleted file mode 100644 index 787544f..0000000 --- a/docker/development/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -# Build production container locally first with following tag -ARG base_commit -FROM registry.gitlab.com/turniere/turniere-backend/production/commits:$base_commit -WORKDIR /app -RUN apt-get update -qq && apt-get install -y python3 python3-pip && apt-get clean && python3 -m pip install --no-cache-dir invoke -RUN bundle config set with 'development' && bundle install -ENV RAILS_ENV development -CMD bundle exec rails db:migrate && bundle exec rails s -p 3000 -b 0.0.0.0 diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index 2740262..0566865 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -5,7 +5,13 @@ RUN apt-get update -qq && apt-get install -y openssl git build-essential libpq-d WORKDIR /app COPY Gemfile* /app/ RUN gem install bundler:2.3.13 && bundle config set deployment 'true' && bundle install -COPY . /app +COPY app /app/app +COPY bin /app/bin +COPY config /app/config +COPY db /app/db +COPY public /app/public +COPY script /app/script +COPY config.ru Rakefile /app/ # Duplicate production environment to beta environment COPY config/environments/production.rb config/environments/beta.rb ENV RAILS_ENV production diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index 759029b..fee0a89 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -1,7 +1,10 @@ -# Build development container locally first with following tag +# Build production container locally first with following tag ARG base_commit -FROM registry.gitlab.com/turniere/turniere-backend/development/commits:$base_commit +FROM registry.gitlab.com/turniere/turniere-backend/production/commits:$base_commit WORKDIR /app -RUN bundle config set with 'test' && bundle install +RUN apt-get update -qq && apt-get install -y python3 python3-pip && apt-get clean && python3 -m pip install --no-cache-dir invoke +RUN bundle config set with 'development test' && bundle install +COPY spec /app/spec +COPY .rspec /app/.rspec ENV RAILS_ENV test CMD bundle exec rails db:migrate && bundle exec rails spec diff --git a/tasks.py b/tasks.py index 512e5eb..dbb9e73 100644 --- a/tasks.py +++ b/tasks.py @@ -26,7 +26,6 @@ E2E_ALT_PASSWORD = "password123" E2E_ALT_USERNAME = "e2e-alt-user" PRODUCTION_TAG = "registry.gitlab.com/turniere/turniere-backend/production/commits:local" -DEVELOPMENT_TAG = "registry.gitlab.com/turniere/turniere-backend/development/commits:local" TEST_TAG = "registry.gitlab.com/turniere/turniere-backend/test/commits:local" BLACKBOX_COMPOSE_FILE = "docker-compose.blackbox.yml" BLACKBOX_PROJECT = "turniere-blackbox" @@ -642,15 +641,6 @@ def docker_build_production(c, tag=PRODUCTION_TAG): c.run(f"docker build -t {tag} -f docker/production/Dockerfile .", pty=True) -@task(name="docker-build-development") -def docker_build_development(c, tag=DEVELOPMENT_TAG): - """Build the development Docker image.""" - c.run( - f"docker build --build-arg base_commit=local -t {tag} -f docker/development/Dockerfile .", - pty=True, - ) - - @task(name="docker-build-test") def docker_build_test(c, tag=TEST_TAG): """Build the test Docker image.""" @@ -659,9 +649,8 @@ def docker_build_test(c, tag=TEST_TAG): @task(name="docker-build-all") def docker_build_all(c): - """Build the production, development, and test Docker images.""" + """Build the production and test Docker images.""" docker_build_production(c) - docker_build_development(c) docker_build_test(c) From 04cef9e2d35471e386fe7e55613271e0619f44a0 Mon Sep 17 00:00:00 2001 From: Malaber Date: Mon, 13 Apr 2026 15:49:00 +0200 Subject: [PATCH 2/4] Include invoke tasks in test image --- docker/test/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index fee0a89..dffc650 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -4,6 +4,7 @@ FROM registry.gitlab.com/turniere/turniere-backend/production/commits:$base_comm WORKDIR /app RUN apt-get update -qq && apt-get install -y python3 python3-pip && apt-get clean && python3 -m pip install --no-cache-dir invoke RUN bundle config set with 'development test' && bundle install +COPY tasks.py /app/tasks.py COPY spec /app/spec COPY .rspec /app/.rspec ENV RAILS_ENV test From f2c5e42a91b577fd0a5aa48e107eead9e8e1d4f2 Mon Sep 17 00:00:00 2001 From: Malaber Date: Mon, 13 Apr 2026 17:50:32 +0200 Subject: [PATCH 3/4] Fix backend test image contents --- .dockerignore | 3 +++ docker/production/Dockerfile | 8 +------- docker/test/Dockerfile | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.dockerignore b/.dockerignore index 85f5647..3bb6684 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,9 @@ .git tmp/** coverage/** +db/*.sqlite3 +db/*.sqlite3-* +db/*.sqlite3.* docker/** .gitignore .hound.yml diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index 0566865..2740262 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -5,13 +5,7 @@ RUN apt-get update -qq && apt-get install -y openssl git build-essential libpq-d WORKDIR /app COPY Gemfile* /app/ RUN gem install bundler:2.3.13 && bundle config set deployment 'true' && bundle install -COPY app /app/app -COPY bin /app/bin -COPY config /app/config -COPY db /app/db -COPY public /app/public -COPY script /app/script -COPY config.ru Rakefile /app/ +COPY . /app # Duplicate production environment to beta environment COPY config/environments/production.rb config/environments/beta.rb ENV RAILS_ENV production diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index dffc650..63bd222 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /app RUN apt-get update -qq && apt-get install -y python3 python3-pip && apt-get clean && python3 -m pip install --no-cache-dir invoke RUN bundle config set with 'development test' && bundle install COPY tasks.py /app/tasks.py +COPY e2e /app/e2e COPY spec /app/spec COPY .rspec /app/.rspec ENV RAILS_ENV test From 1ce15adaa5759db70e97daeff0ed320a0a46f5c3 Mon Sep 17 00:00:00 2001 From: Malaber Date: Mon, 13 Apr 2026 18:02:35 +0200 Subject: [PATCH 4/4] Trim production Docker context --- docker/production/Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index 2740262..0566865 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -5,7 +5,13 @@ RUN apt-get update -qq && apt-get install -y openssl git build-essential libpq-d WORKDIR /app COPY Gemfile* /app/ RUN gem install bundler:2.3.13 && bundle config set deployment 'true' && bundle install -COPY . /app +COPY app /app/app +COPY bin /app/bin +COPY config /app/config +COPY db /app/db +COPY public /app/public +COPY script /app/script +COPY config.ru Rakefile /app/ # Duplicate production environment to beta environment COPY config/environments/production.rb config/environments/beta.rb ENV RAILS_ENV production