From 6f663ff62d945f573a0945524a953641586c2058 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 18:40:00 +0200 Subject: [PATCH 01/20] Don't cache apk add command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d999999..b3035ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM ruby:2.6.2-alpine -RUN apk add build-base tzdata sqlite sqlite-dev postgresql-dev && gem install tzinfo-data +RUN apk add --no-cache build-base tzdata sqlite sqlite-dev postgresql-dev && gem install tzinfo-data WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock From ebd555f2326d81dbeb8787f5673af9857eb852e1 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 18:40:17 +0200 Subject: [PATCH 02/20] Copy Gemfiles in one step --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b3035ca..4305b36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ FROM ruby:2.6.2-alpine RUN apk add --no-cache build-base tzdata sqlite sqlite-dev postgresql-dev && gem install tzinfo-data WORKDIR /app -COPY Gemfile /app/Gemfile -COPY Gemfile.lock /app/Gemfile.lock +COPY Gemfile* /app/ RUN bundle install --deployment --without development test COPY . /app ENV RAILS_ENV production From 7e2da71b53f7f9a54c936ae9131929c7481e1ed5 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 18:41:36 +0200 Subject: [PATCH 03/20] Move Dockerfile to production folder --- Dockerfile => docker/production/Dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Dockerfile => docker/production/Dockerfile (100%) diff --git a/Dockerfile b/docker/production/Dockerfile similarity index 100% rename from Dockerfile rename to docker/production/Dockerfile From bbfb9a355b7c993ff8ffb33e1aa33b67bf87ac09 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:07:57 +0200 Subject: [PATCH 04/20] Add development container Dockerfile --- docker/development/Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docker/development/Dockerfile diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile new file mode 100644 index 0000000..e78c64e --- /dev/null +++ b/docker/development/Dockerfile @@ -0,0 +1,6 @@ +# Build production container locally first with following tag +FROM registry.gitlab.com/turniere/turniere-backend/production +WORKDIR /app +RUN bundle install --deployment --with development +ENV RAILS_ENV development +CMD bundle exec rails db:migrate && bundle exec rails s -p 3000 -b 0.0.0.0 \ No newline at end of file From 3c9e159b16dc6716911cb5cb46717d9aae7f9b4f Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:08:22 +0200 Subject: [PATCH 05/20] Add test container Dockerfile --- docker/test/Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docker/test/Dockerfile diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile new file mode 100644 index 0000000..e3a2b0f --- /dev/null +++ b/docker/test/Dockerfile @@ -0,0 +1,6 @@ +# Build development container locally first with following tag +FROM registry.gitlab.com/turniere/turniere-backend/development +WORKDIR /app +RUN bundle install --deployment --with test +ENV RAILS_ENV test +CMD bundle exec rails db:migrate && bundle exec rails spec \ No newline at end of file From e6a4f88b244f41aafcc9d8d86196440667f02cdf Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:08:55 +0200 Subject: [PATCH 06/20] Build development & test containers in GitLab --- .gitlab-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6360e8d..2a045ad 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,14 +11,16 @@ rails spec: - bundle exec rails db:migrate RAILS_ENV=test - bundle exec rails spec -kaniko: +kaniko: stage: build image: name: gcr.io/kaniko-project/executor:debug entrypoint: [""] script: - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:latest --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG kubernetes: stage: deploy From 2ba17a02a0640536d73eed3995a33aaf55df80f9 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:56:04 +0200 Subject: [PATCH 07/20] Add test & spec folder to docker container It would have been nicer to also exclude the test and spec folder within the production container, saving some space within that, but the docker COPY statement doesn't allow for that without a workaround. So this is what we will do for now I guess. --- .dockerignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index a955123..f2ae362 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,4 @@ .git -test/** -spec/** tmp/** .gitignore .hound.yml From 2fb020679820a625b7cf1cbc8e081ca08ae42d56 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:56:20 +0200 Subject: [PATCH 08/20] Ignore coverage and docker folder in docker build --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index f2ae362..8a3ef0c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,7 @@ .git tmp/** +coverage/** +docker/** .gitignore .hound.yml .rspec From 103ea70f9aa807f13f5f0c908e8a363330b820df Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 19:58:31 +0200 Subject: [PATCH 09/20] Improve gitlab-ci.yml readability --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2a045ad..7b97ed5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,9 +18,9 @@ kaniko: entrypoint: [""] script: - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG kubernetes: stage: deploy From cffaafb6bd564c5a3ed95a22799b582b25134ac1 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 20:16:37 +0200 Subject: [PATCH 10/20] Swap build and test stage --- .gitlab-ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7b97ed5..8db289f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,8 @@ stages: - - test - build + - test - deploy -rails spec: - stage: test - image: ruby:2.6.2 - script: - - bundle install --path /cache - - bundle exec rails db:migrate RAILS_ENV=test - - bundle exec rails spec - kaniko: stage: build image: @@ -22,6 +14,14 @@ kaniko: - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG +rails spec: + stage: test + image: ruby:2.6.2 + script: + - bundle install --path /cache + - bundle exec rails db:migrate RAILS_ENV=test + - bundle exec rails spec + kubernetes: stage: deploy only: From 3c280a6b29202fbc927105a41e1c23590dcf57e3 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 20 Jun 2019 20:28:53 +0200 Subject: [PATCH 11/20] Run tests in image built one step above using latest tag This isn't optimal since theoretically there could be an image pushed just between building and downloading again, but variables cannot be used within gitlab-ci.yml so that is what we have to work with. If variables get introduced, we should lock this to the current commit sha. --- .gitlab-ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8db289f..4f9f414 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,10 +16,9 @@ kaniko: rails spec: stage: test - image: ruby:2.6.2 + image: registry.gitlab.com/turniere/turniere-backend/test script: - - bundle install --path /cache - - bundle exec rails db:migrate RAILS_ENV=test + - bundle exec rails db:migrate - bundle exec rails spec kubernetes: From 4fa4b1e1f7804da1dc6323a34e7c971eb2695c70 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sun, 23 Jun 2019 01:07:18 +0200 Subject: [PATCH 12/20] Enter app directory Otherwise bundler refuses to run and won't find rails or the tests. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4f9f414..7e3b9ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,7 @@ rails spec: stage: test image: registry.gitlab.com/turniere/turniere-backend/test script: + - cd /app - bundle exec rails db:migrate - bundle exec rails spec From d507f84dc8b1cf6e06d0fc2cabb9eaed00a89f54 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sun, 23 Jun 2019 01:37:51 +0200 Subject: [PATCH 13/20] Deploy newly renamed container --- kubernetes/deployment.yml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/deployment.yml.erb b/kubernetes/deployment.yml.erb index f475c53..2e30c60 100644 --- a/kubernetes/deployment.yml.erb +++ b/kubernetes/deployment.yml.erb @@ -17,7 +17,7 @@ spec: spec: containers: - name: backend-container - image: registry.gitlab.com/turniere/turniere-backend:<%= current_sha %> + image: registry.gitlab.com/turniere/turniere-backend/production/commits:<%= current_sha %> ports: - containerPort: 3000 env: From c22aafe037a132727d8023820f3842de5d7418d5 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 26 Sep 2019 16:12:11 +0200 Subject: [PATCH 14/20] Tag local versions of Docker Containers These are (hopefully) never pushed and therefore are always the most recent version. --- .gitlab-ci.yml | 6 +++--- docker/development/Dockerfile | 2 +- docker/test/Dockerfile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e3b9ec..aad5126 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,9 +10,9 @@ kaniko: entrypoint: [""] script: - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG --destination turniere-backend/production:local + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG --destination turniere-backend/development:local + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG --destination turniere-backend/test:local rails spec: stage: test diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index e78c64e..218aac3 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -1,5 +1,5 @@ # Build production container locally first with following tag -FROM registry.gitlab.com/turniere/turniere-backend/production +FROM turniere-backend/production:local WORKDIR /app RUN bundle install --deployment --with development ENV RAILS_ENV development diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index e3a2b0f..6ec8f14 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -1,5 +1,5 @@ # Build development container locally first with following tag -FROM registry.gitlab.com/turniere/turniere-backend/development +FROM turniere-backend/development:local WORKDIR /app RUN bundle install --deployment --with test ENV RAILS_ENV test From 7f2dc1f1c1c70c56511a7562041a99497c4cf382 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 26 Sep 2019 16:16:21 +0200 Subject: [PATCH 15/20] Manually retag pushed images locally --- .gitlab-ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aad5126..72ef709 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,13 +10,16 @@ kaniko: entrypoint: [""] script: - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG --destination turniere-backend/production:local - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG --destination turniere-backend/development:local - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG --destination turniere-backend/test:local + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG + - docker tag $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA turniere-backend/production:local + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG + - docker tag $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA turniere-backend/development:local + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG + - docker tag $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA turniere-backend/test:local rails spec: stage: test - image: registry.gitlab.com/turniere/turniere-backend/test + image: turniere-backend/test:local script: - cd /app - bundle exec rails db:migrate From 5e559e1522cecbfc22aee93d894ef5a1972912ce Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 27 Sep 2019 11:09:19 +0200 Subject: [PATCH 16/20] Revert Dockerfile to use latest version of image As it is built locally within one step and never pulled between steps, this should not be a problem --- docker/development/Dockerfile | 2 +- docker/test/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index 218aac3..e78c64e 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -1,5 +1,5 @@ # Build production container locally first with following tag -FROM turniere-backend/production:local +FROM registry.gitlab.com/turniere/turniere-backend/production WORKDIR /app RUN bundle install --deployment --with development ENV RAILS_ENV development diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index 6ec8f14..e3a2b0f 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -1,5 +1,5 @@ # Build development container locally first with following tag -FROM turniere-backend/development:local +FROM registry.gitlab.com/turniere/turniere-backend/development WORKDIR /app RUN bundle install --deployment --with test ENV RAILS_ENV test From 0f951248936d2cf81108082692aead85e9d6b039 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 27 Sep 2019 11:09:36 +0200 Subject: [PATCH 17/20] Remove not working docker tag commands --- .gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 72ef709..1df959c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,11 +11,8 @@ kaniko: script: - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/production/Dockerfile --destination $CI_REGISTRY_IMAGE/production --destination $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/production/branches:$CI_COMMIT_REF_SLUG - - docker tag $CI_REGISTRY_IMAGE/production/commits:$CI_COMMIT_SHA turniere-backend/production:local - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/development/Dockerfile --destination $CI_REGISTRY_IMAGE/development --destination $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/development/branches:$CI_COMMIT_REF_SLUG - - docker tag $CI_REGISTRY_IMAGE/development/commits:$CI_COMMIT_SHA turniere-backend/development:local - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG - - docker tag $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA turniere-backend/test:local rails spec: stage: test From 699b451f26ad456699fd104a783d2931aeb11e84 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 27 Sep 2019 11:10:02 +0200 Subject: [PATCH 18/20] Explicitly define current commit sha as test image --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1df959c..0d95a74 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ kaniko: rails spec: stage: test - image: turniere-backend/test:local + image: $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA script: - cd /app - bundle exec rails db:migrate From e79136e67b5bd6f902b76f582dc10b8327cb00db Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 27 Sep 2019 14:25:39 +0200 Subject: [PATCH 19/20] Add Docker related information to readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index accf4b1..313266b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,28 @@ Development (without mail confirmation and separate database): $ RAILS_ENV=development rails server ``` +## Docker +[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. +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. + +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** + + ## Generate diagrams ```bash $ rails diagram:all_with_engines From fd8b93d386dc0f2d1b34d19a427f7511a408c9b0 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Wed, 9 Oct 2019 12:44:46 +0200 Subject: [PATCH 20/20] Add Tags for use with shared runners --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0d95a74..a4b4188 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,8 @@ stages: - deploy kaniko: + tags: + - docker stage: build image: name: gcr.io/kaniko-project/executor:debug @@ -15,6 +17,8 @@ kaniko: - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/docker/test/Dockerfile --destination $CI_REGISTRY_IMAGE/test --destination $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE/test/branches:$CI_COMMIT_REF_SLUG rails spec: + tags: + - docker stage: test image: $CI_REGISTRY_IMAGE/test/commits:$CI_COMMIT_SHA script: @@ -23,6 +27,8 @@ rails spec: - bundle exec rails spec kubernetes: + tags: + - turniere-deploy stage: deploy only: - master