From 1ae00ad802f6cac9ca024f09e336d9c10d2166a7 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 16 Jul 2024 17:21:55 +0000 Subject: [PATCH 1/5] fix: added multi tag image build --- ci-templates/build.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index a60e871..9b3ac81 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -15,13 +15,20 @@ name: gcr.io/kaniko-project/executor:debug entrypoint: [""] script: - - export DOCKER_TAG=$APP_VERSION - | - if [ "$CI_COMMIT_REF_NAME" = "main" ]; then + if [ "$CI_COMMIT_REF_NAME" = "fix/multi-tag-image" ]; then echo "Pushing Docker image with tag 'latest'" - export DOCKER_TAG=latest + /kaniko/executor + --context "${CI_PROJECT_DIR}" + --dockerfile "${CI_PROJECT_DIR}/Dockerfile" + --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" + --destination "${CI_REGISTRY_IMAGE}:latest" + else + /kaniko/executor + --context "${CI_PROJECT_DIR}" + --dockerfile "${CI_PROJECT_DIR}/Dockerfile" + --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" fi - - /kaniko/executor --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" .angular_build: extends: .default -- GitLab From c22bd4634c09687122382e79ed0717c40e4e0576 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 16 Jul 2024 17:26:45 +0000 Subject: [PATCH 2/5] fix: added fix for multiline command --- ci-templates/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index 9b3ac81..72a801f 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -16,17 +16,17 @@ entrypoint: [""] script: - | - if [ "$CI_COMMIT_REF_NAME" = "fix/multi-tag-image" ]; then + if [ "$CI_COMMIT_REF_NAME" = "main" ]; then echo "Pushing Docker image with tag 'latest'" - /kaniko/executor - --context "${CI_PROJECT_DIR}" - --dockerfile "${CI_PROJECT_DIR}/Dockerfile" - --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" + /kaniko/executor \ + --context "${CI_PROJECT_DIR}" \ + --dockerfile "${CI_PROJECT_DIR}/Dockerfile" \ + --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" \ --destination "${CI_REGISTRY_IMAGE}:latest" else - /kaniko/executor - --context "${CI_PROJECT_DIR}" - --dockerfile "${CI_PROJECT_DIR}/Dockerfile" + /kaniko/executor \ + --context "${CI_PROJECT_DIR}" \ + --dockerfile "${CI_PROJECT_DIR}/Dockerfile" \ --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" fi -- GitLab From 24c824a907804c374085ae38f26feaba98b79dcd Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 16 Jul 2024 17:30:25 +0000 Subject: [PATCH 3/5] debug: using side branch for tests --- ci-templates/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index 72a801f..a80bdc6 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -16,7 +16,7 @@ entrypoint: [""] script: - | - if [ "$CI_COMMIT_REF_NAME" = "main" ]; then + if [ "$CI_COMMIT_REF_NAME" = "fix/multi-tag-image" ]; then echo "Pushing Docker image with tag 'latest'" /kaniko/executor \ --context "${CI_PROJECT_DIR}" \ -- GitLab From dbde13bcadb59892c1d964ff3bb3ebc09d666837 Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 16 Jul 2024 17:38:13 +0000 Subject: [PATCH 4/5] fix: replace / with - in tags --- ci-templates/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index a80bdc6..e1154e2 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -15,19 +15,20 @@ name: gcr.io/kaniko-project/executor:debug entrypoint: [""] script: + - export BRANCH_NAME=$(echo "$CI_COMMIT_REF_NAME" | tr '/' '-') - | if [ "$CI_COMMIT_REF_NAME" = "fix/multi-tag-image" ]; then echo "Pushing Docker image with tag 'latest'" /kaniko/executor \ --context "${CI_PROJECT_DIR}" \ --dockerfile "${CI_PROJECT_DIR}/Dockerfile" \ - --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" \ + --destination "${CI_REGISTRY_IMAGE}:$BRANCH_NAME" \ --destination "${CI_REGISTRY_IMAGE}:latest" else /kaniko/executor \ --context "${CI_PROJECT_DIR}" \ --dockerfile "${CI_PROJECT_DIR}/Dockerfile" \ - --destination "${CI_REGISTRY_IMAGE}:$APP_VERSION" + --destination "${CI_REGISTRY_IMAGE}:$BRANCH_NAME" fi .angular_build: -- GitLab From 12c305ef63155460dfc0e695e23270e8c572ebca Mon Sep 17 00:00:00 2001 From: Dimitrios Giannopoulos Date: Tue, 16 Jul 2024 17:42:46 +0000 Subject: [PATCH 5/5] fix: corrected condition to trigger for main only --- ci-templates/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-templates/build.yml b/ci-templates/build.yml index e1154e2..42d7a53 100644 --- a/ci-templates/build.yml +++ b/ci-templates/build.yml @@ -17,7 +17,7 @@ script: - export BRANCH_NAME=$(echo "$CI_COMMIT_REF_NAME" | tr '/' '-') - | - if [ "$CI_COMMIT_REF_NAME" = "fix/multi-tag-image" ]; then + if [ "$CI_COMMIT_REF_NAME" = "main" ]; then echo "Pushing Docker image with tag 'latest'" /kaniko/executor \ --context "${CI_PROJECT_DIR}" \ -- GitLab