From 4029e22cf6e78c394c5c9d9af990f1af80d0505c Mon Sep 17 00:00:00 2001 From: alberhander Date: Mon, 8 Feb 2021 16:51:31 +0100 Subject: [PATCH 1/2] add docker labels --- .github/workflows/main.yml | 9 ++++----- .github/workflows/master.yml | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 10caa2a8..4de9ec71 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,12 +62,11 @@ jobs: - name: Build image run: | - echo ${GITHUB_SHA::7} - echo ${GITHUB_REF##*/} - docker build -f private/Dockerfile -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/}--${GITHUB_SHA::7} . + BRANCH_NAME="${GITHUB_REF#refs/heads/}" + docker build -f private/Dockerfile --label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${GITHUB_SHA} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}--${GITHUB_SHA::7} . - name: Upload image run: | - docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/} + docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME} docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} - docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/}--${GITHUB_SHA::7} + docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}--${GITHUB_SHA::7} diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 69a44750..880e5e49 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -27,7 +27,7 @@ jobs: run: | echo ${GITHUB_SHA::7} echo ${GITHUB_REF##*/} - docker build -f private/Dockerfile -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:latest -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} . + docker build -f private/Dockerfile --label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${GITHUB_SHA} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:latest -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_REF##*/}--${GITHUB_SHA::7} . - name: Setup gcloud authentication uses: google-github-actions/setup-gcloud@master From 352a9e0d3c5a54b7a1ff8c7bf509e07d559abc60 Mon Sep 17 00:00:00 2001 From: alberhander Date: Mon, 8 Feb 2021 16:56:43 +0100 Subject: [PATCH 2/2] replacing slashes in docker tags --- .github/workflows/main.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4de9ec71..ae6d897f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,11 +62,14 @@ jobs: - name: Build image run: | - BRANCH_NAME="${GITHUB_REF#refs/heads/}" + BRANCH_NAME=${GITHUB_REF#refs/heads/} + BRANCH_NAME=${BRANCH_NAME//\//-} + echo "Building sql-api image from branch: $BRANCH_NAME, commit: ${GITHUB_SHA::7}..." docker build -f private/Dockerfile --label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${GITHUB_SHA} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}--${GITHUB_SHA::7} . - - name: Upload image - run: | + echo 'Pushing images to the registry...' docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME} docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}--${GITHUB_SHA::7} + +