Merge branch 'TUR-70-backend-docker-cache' into 'master'

TUR-70 backend Docker image cleanup

Closes TUR-70

See merge request turniere/turniere-backend!38
This commit is contained in:
Daniel Schädler 2026-04-13 16:31:16 +00:00
commit 798eb56657
7 changed files with 27 additions and 32 deletions

View File

@ -1,10 +1,12 @@
.git
tmp/**
coverage/**
db/*.sqlite3
db/*.sqlite3-*
db/*.sqlite3.*
docker/**
.gitignore
.hound.yml
.rspec
.rubocop.yml
docker-compose.yml
README.md

View File

@ -3,6 +3,9 @@ stages:
- test
- deploy
variables:
DOCKER_IMAGE_ENVS: "production test"
include:
- project: 'turniere/turniere-infra'
file: '/ci/pipeline.yaml'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,7 +1,12 @@
# 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 tasks.py /app/tasks.py
COPY e2e /app/e2e
COPY spec /app/spec
COPY .rspec /app/.rspec
ENV RAILS_ENV test
CMD bundle exec rails db:migrate && bundle exec rails spec

View File

@ -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)