From d0dcfad9d9b6838f9a82a88bc41fd04d71c8e49a Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Tue, 22 Dec 2020 11:47:16 -0600 Subject: [PATCH] fix: Optimize layer order and docker ignores --- .dockerignore | 5 +++++ .gitlab-ci.yml | 19 ++++++++++++++++--- Dockerfile | 11 +++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..dbf33606 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +_build +cover +.elixir_ls +*.dump +.journal-* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a8dc4af5..0f62e8a9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,9 +33,9 @@ deploy_to_tags: - npm install - npx semantic-release -deploy_to_registry: - stage: deploy - needs: ['test'] +build_image_for_commit: + stage: test + needs: [] image: "docker:19.03.12" services: - name: docker:19.03.12-dind @@ -45,6 +45,19 @@ deploy_to_registry: - docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD - docker pull $CI_REGISTRY_IMAGE:latest || true - docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + +deploy_commit_image_to_tag: + stage: deploy + needs: ['test'] + image: "docker:19.03.12" + services: + - name: docker:19.03.12-dind + only: + - tags + script: + - docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG diff --git a/Dockerfile b/Dockerfile index 3241c068..b68db368 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,6 @@ ENV MIX_HOME=/opt/mix RUN mix local.hex --force \ && mix local.rebar --force -WORKDIR /root/app - -ADD ./ /root/app/ - EXPOSE 4000 ARG MIX_ENV=prod @@ -19,8 +15,15 @@ RUN echo ${MIX_ENV} ENV MIX_ENV=$MIX_ENV ENV PORT=4000 +WORKDIR /root/app + +ADD ./mix.exs /root/app/mix.exs +ADD ./mix.lock /root/app/mix.lock RUN mix deps.get RUN mix deps.compile + +ADD ./ /root/app/ + RUN MAKE=cmake mix compile RUN mix phx.digest