From cc95bcc793064d6fefd76f4bd968c4d395d707c5 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 Oct 2021 13:40:49 -0400 Subject: [PATCH] Gitlab CI/CD dind Update --- .gitlab-ci.yml | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1987f50..07e76f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,7 @@ stages: - test - build - push + - deploy PythonTests: stage: test @@ -28,43 +29,62 @@ PythonTests: script: - python3 manage.py test -before_script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - DockerBuild: stage: build image: docker:latest + variables: + DOCKER_HOST: tcp://docker:2375 + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" services: - name: docker:dind + alias: docker + command: ["--tls=false"] + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - - docker pull $CI_REGISTRY_IMAGE:latest || true - - docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . + - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH || true + - docker build --network host --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -PushLatest: - variables: - GIT_STRATEGY: none +PushProduction: stage: push image: docker:latest + variables: + GIT_STRATEGY: none + DOCKER_HOST: tcp://docker:2375 + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" services: - name: docker:dind + alias: docker + command: ["--tls=false"] only: - production + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest - - docker push $CI_REGISTRY_IMAGE:latest + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH PushDevelop: - variables: - GIT_STRATEGY: none stage: push image: docker:latest + variables: + GIT_STRATEGY: none + DOCKER_HOST: tcp://docker:2375 + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" services: - name: docker:dind + alias: docker + command: ["--tls=false"] only: - develop + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:develop - - docker push $CI_REGISTRY_IMAGE:develop + - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH + - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH