From a1c192330abc122568adf89e1862e9e2ee08ac90 Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Thu, 2 Feb 2023 08:11:18 +0600 Subject: [PATCH 1/5] use CI/CD templates for docker-build --- .gitlab-ci.yml | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3be72010..571a340d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,20 +1,9 @@ -# When using dind, it's wise to use the overlayfs driver for -# improved performance. -variables: - DOCKER_DRIVER: overlay2 - DOCKER_TLS_CERTDIR: "/certs" - -default: - image: docker:19.03.12 +include: + - project: "e/infra/templates/infra-ci-cd-templates" + ref: main + file: "docker-build.yaml" - services: - - docker:19.03.12-dind - before_script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - tags: - - generic_privileged - -.build-docker: +.build:docker: script: - echo "TARGET $TARGET, BRANCH $CI_COMMIT_BRANCH, COMMIT_REF_SLUG $CI_COMMIT_REF_SLUG, COMMIT_TAG $CI_COMMIT_TAG" - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_REF_SLUG" . @@ -27,7 +16,7 @@ build-branch: SUBPATH: '' only: - branches - extends: .build-docker + extends: .build:docker build-branch-selfhost: stage: build @@ -37,7 +26,7 @@ build-branch-selfhost: only: - branches when: manual - extends: .build-docker + extends: .build:docker build-tag: stage: build @@ -46,7 +35,7 @@ build-tag: SUBPATH: '' only: - tags - extends: .build-docker + extends: .build:docker build-tag-selfhost: stage: build @@ -55,4 +44,4 @@ build-tag-selfhost: SUBPATH: '/selfhost' only: - tags - extends: .build-docker + extends: .build:docker -- GitLab From 7caeb1a46868e2856e5f52b36ae79a9b604695ef Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Thu, 2 Feb 2023 08:17:15 +0600 Subject: [PATCH 2/5] switch to CI_COMMIT_TAG for docker image tag CI_COMMIT_REF_SLUG replaces dots with dashes but CI_COMMIT_TAG keeps the dots --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 571a340d..dd645e23 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,8 @@ include: .build:docker: script: - echo "TARGET $TARGET, BRANCH $CI_COMMIT_BRANCH, COMMIT_REF_SLUG $CI_COMMIT_REF_SLUG, COMMIT_TAG $CI_COMMIT_TAG" - - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_REF_SLUG" . - - docker push "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_REF_SLUG" + - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_TAG" . + - docker push "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_TAG" build-branch: stage: build -- GitLab From 89a5f7e83e38578bd31502fd6e1fcb97a0ab8a30 Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Thu, 2 Feb 2023 08:33:47 +0600 Subject: [PATCH 3/5] create and use separate template for tag and branch --- .gitlab-ci.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dd645e23..b5dfbae3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,11 +3,19 @@ include: ref: main file: "docker-build.yaml" -.build:docker: +.build-branch:docker: + extends: .build:docker + script: + - echo "TARGET $TARGET, BRANCH $CI_COMMIT_BRANCH, COMMIT_REF_SLUG $CI_COMMIT_REF_SLUG" + - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_REF_SLUG" . + - docker push --all-tags "$CI_REGISTRY_IMAGE" + +.build-tag:docker: + extends: .build:docker script: - echo "TARGET $TARGET, BRANCH $CI_COMMIT_BRANCH, COMMIT_REF_SLUG $CI_COMMIT_REF_SLUG, COMMIT_TAG $CI_COMMIT_TAG" - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_TAG" . - - docker push "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_TAG" + - docker push --all-tags "$CI_REGISTRY_IMAGE" build-branch: stage: build @@ -16,7 +24,7 @@ build-branch: SUBPATH: '' only: - branches - extends: .build:docker + extends: .build-branch:docker build-branch-selfhost: stage: build @@ -26,7 +34,7 @@ build-branch-selfhost: only: - branches when: manual - extends: .build:docker + extends: .build-branch:docker build-tag: stage: build @@ -35,7 +43,7 @@ build-tag: SUBPATH: '' only: - tags - extends: .build:docker + extends: .build-tag:docker build-tag-selfhost: stage: build @@ -44,4 +52,4 @@ build-tag-selfhost: SUBPATH: '/selfhost' only: - tags - extends: .build:docker + extends: .build-tag:docker -- GitLab From ad9cd36c57796442e04cee63d1e335cac552748c Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Thu, 2 Feb 2023 09:01:45 +0600 Subject: [PATCH 4/5] update echo to give proper message --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5dfbae3..596de0b0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,14 +6,14 @@ include: .build-branch:docker: extends: .build:docker script: - - echo "TARGET $TARGET, BRANCH $CI_COMMIT_BRANCH, COMMIT_REF_SLUG $CI_COMMIT_REF_SLUG" + - echo "Building $TARGET target for $CI_COMMIT_BRANCH branch using $CI_COMMIT_REF_SLUG as docker image tag" - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_REF_SLUG" . - docker push --all-tags "$CI_REGISTRY_IMAGE" .build-tag:docker: extends: .build:docker script: - - echo "TARGET $TARGET, BRANCH $CI_COMMIT_BRANCH, COMMIT_REF_SLUG $CI_COMMIT_REF_SLUG, COMMIT_TAG $CI_COMMIT_TAG" + - echo "Building $TARGET target for $CI_COMMIT_TAG tag using $CI_COMMIT_TAG as docker image tag" - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_TAG" . - docker push --all-tags "$CI_REGISTRY_IMAGE" -- GitLab From 3d9d047292e3579db520b0ae882a75f02f2ff6d2 Mon Sep 17 00:00:00 2001 From: Fazle Rabbi Date: Thu, 2 Feb 2023 09:46:48 +0600 Subject: [PATCH 5/5] add SUBPATH to fix docker push --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 596de0b0..21fa5a90 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,14 +8,14 @@ include: script: - echo "Building $TARGET target for $CI_COMMIT_BRANCH branch using $CI_COMMIT_REF_SLUG as docker image tag" - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_REF_SLUG" . - - docker push --all-tags "$CI_REGISTRY_IMAGE" + - docker push --all-tags "$CI_REGISTRY_IMAGE$SUBPATH" .build-tag:docker: extends: .build:docker script: - echo "Building $TARGET target for $CI_COMMIT_TAG tag using $CI_COMMIT_TAG as docker image tag" - docker build --target $TARGET --pull -t "$CI_REGISTRY_IMAGE$SUBPATH:$CI_COMMIT_TAG" . - - docker push --all-tags "$CI_REGISTRY_IMAGE" + - docker push --all-tags "$CI_REGISTRY_IMAGE$SUBPATH" build-branch: stage: build -- GitLab