Simplify backend Docker images
This commit is contained in:
parent
a88a4b4e51
commit
810728518c
|
|
@ -4,7 +4,6 @@ coverage/**
|
||||||
docker/**
|
docker/**
|
||||||
.gitignore
|
.gitignore
|
||||||
.hound.yml
|
.hound.yml
|
||||||
.rspec
|
|
||||||
.rubocop.yml
|
.rubocop.yml
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
README.md
|
README.md
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ stages:
|
||||||
- test
|
- test
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
|
variables:
|
||||||
|
DOCKER_IMAGE_ENVS: "production test"
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- project: 'turniere/turniere-infra'
|
- project: 'turniere/turniere-infra'
|
||||||
file: '/ci/pipeline.yaml'
|
file: '/ci/pipeline.yaml'
|
||||||
|
|
|
||||||
12
README.md
12
README.md
|
|
@ -31,22 +31,20 @@ bundle exec rspec
|
||||||
[Registry](https://gitlab.com/turniere/turniere-backend/container_registry)
|
[Registry](https://gitlab.com/turniere/turniere-backend/container_registry)
|
||||||
|
|
||||||
You can find all our Dockerfiles in the docker directory.
|
You can find all our Dockerfiles in the docker directory.
|
||||||
They depend on each other in the following order: `production` → `development` → `test`
|
They depend on each other in the following order: `production` → `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.
|
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:
|
To build all images do:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd turniere-backend
|
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/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 .
|
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.
|
This is done to leave test and development dependencies out of 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.
|
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.
|
While developing, use `test` image as base container and mount root of this repository into `/app` to avoid rebuilding it over and over again.
|
||||||
**Only rebuilding the `development` container is not sufficient, as the `development` Dockerfile does not have a `COPY` Statement**
|
|
||||||
|
|
||||||
|
|
||||||
## Generate diagrams
|
## Generate diagrams
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -5,7 +5,13 @@ RUN apt-get update -qq && apt-get install -y openssl git build-essential libpq-d
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY Gemfile* /app/
|
COPY Gemfile* /app/
|
||||||
RUN gem install bundler:2.3.13 && bundle config set deployment 'true' && bundle install
|
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
|
# Duplicate production environment to beta environment
|
||||||
COPY config/environments/production.rb config/environments/beta.rb
|
COPY config/environments/production.rb config/environments/beta.rb
|
||||||
ENV RAILS_ENV production
|
ENV RAILS_ENV production
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
# Build development container locally first with following tag
|
# Build production container locally first with following tag
|
||||||
ARG base_commit
|
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
|
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
|
ENV RAILS_ENV test
|
||||||
CMD bundle exec rails db:migrate && bundle exec rails spec
|
CMD bundle exec rails db:migrate && bundle exec rails spec
|
||||||
|
|
|
||||||
13
tasks.py
13
tasks.py
|
|
@ -26,7 +26,6 @@ E2E_ALT_PASSWORD = "password123"
|
||||||
E2E_ALT_USERNAME = "e2e-alt-user"
|
E2E_ALT_USERNAME = "e2e-alt-user"
|
||||||
|
|
||||||
PRODUCTION_TAG = "registry.gitlab.com/turniere/turniere-backend/production/commits:local"
|
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"
|
TEST_TAG = "registry.gitlab.com/turniere/turniere-backend/test/commits:local"
|
||||||
BLACKBOX_COMPOSE_FILE = "docker-compose.blackbox.yml"
|
BLACKBOX_COMPOSE_FILE = "docker-compose.blackbox.yml"
|
||||||
BLACKBOX_PROJECT = "turniere-blackbox"
|
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)
|
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")
|
@task(name="docker-build-test")
|
||||||
def docker_build_test(c, tag=TEST_TAG):
|
def docker_build_test(c, tag=TEST_TAG):
|
||||||
"""Build the test Docker image."""
|
"""Build the test Docker image."""
|
||||||
|
|
@ -659,9 +649,8 @@ def docker_build_test(c, tag=TEST_TAG):
|
||||||
|
|
||||||
@task(name="docker-build-all")
|
@task(name="docker-build-all")
|
||||||
def docker_build_all(c):
|
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_production(c)
|
||||||
docker_build_development(c)
|
|
||||||
docker_build_test(c)
|
docker_build_test(c)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue