From a606a02ab7f242ef06716ea99860c01a781e35c3 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 17:44:20 +0100 Subject: [PATCH 1/9] Group log lines and make the output less verbose https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#grouping-log-lines --- action.yml | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index 9cabe6b..87ce437 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,7 @@ runs: - name: Set commit tag and image name shell: bash run: | + echo "::group::Set commit tag and image name" if [ "${{ github.event_name }}" = "release" ]; then export COMMIT_TAG=${GITHUB_REF:10} # export COMMIT_TAG=v2.3.0 # debug @@ -45,10 +46,13 @@ runs: else echo "COMMIT_TAG=latest" >> $GITHUB_ENV fi + echo "::endgroup::" - name: "Build the Docker image" shell: bash run: | + echo "::group::Build the Docker image" + # expand commands set -x @@ -81,25 +85,23 @@ runs: --label org.opencontainers.image.created=${BUILD_DATE} \ --label org.opencontainers.image.source=${GITHUB_URL} \ --label org.opencontainers.image.revision=${GITHUB_SHA} - - echo - echo "Inspecting the image ..." - echo + echo "::endgroup::" + echo "::group::Inspecting the image" docker images docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} | jq '.[].Config.Labels' + echo "::endgroup::" - name: "Push the Docker image to ghcr.io" shell: bash run: | + echo "::group::Pushing the Docker image to ghcr.io ..." + # expand commands set -x - - echo - echo "Pushing the Docker image to ghcr.io ..." - echo - docker push ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + echo "::endgroup::" - name: "Push the Docker image to docker.io" shell: bash @@ -107,18 +109,15 @@ runs: DOCKER_TOKEN: ${{ inputs.docker_io_token }} run: | if [ -z "${DOCKER_TOKEN}" ]; then - echo - echo "NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed." - echo + echo "::warning::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed." else + echo "::group::Pushing the Docker image to docker.io ..." + # expand commands set -x - echo - echo "Pushing the Docker image to docker.io ..." - echo - echo "${DOCKER_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin - docker push docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + docker push --quiet docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + echo "::endgroup::" fi From 733dbafe1fe1f8a944bda69a42c786de431d8c10 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 17:49:16 +0100 Subject: [PATCH 2/9] Update action.yml --- action.yml | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/action.yml b/action.yml index 87ce437..08c4b71 100644 --- a/action.yml +++ b/action.yml @@ -38,37 +38,33 @@ runs: - name: Set commit tag and image name shell: bash run: | - echo "::group::Set commit tag and image name" + echo "::group::Set commit tag and image name" if [ "${{ github.event_name }}" = "release" ]; then export COMMIT_TAG=${GITHUB_REF:10} # export COMMIT_TAG=v2.3.0 # debug echo "COMMIT_TAG=${COMMIT_TAG//v/}" >> $GITHUB_ENV # remove "v" suffix + echo "Tagging with ${COMMIT_TAG//v/}" else echo "COMMIT_TAG=latest" >> $GITHUB_ENV + echo "Tagging with latest" fi echo "::endgroup::" - name: "Build the Docker image" shell: bash + env: + DOCKER_BUILDKIT: 1 run: | - echo "::group::Build the Docker image" - - # expand commands - set -x - - docker -v - export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") export GITHUB_URL=https://github.com/${{ github.repository }} - echo - echo "Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} ..." - echo + echo "::group::Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} ..." # https://docs.docker.com/develop/develop-images/build_enhancements/ # https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources - DOCKER_BUILDKIT=1 \ - docker build . \ + set -x + + docker build . \ --cache-from ${{ inputs.repository }}/${{ inputs.image_name }}:latest \ --build-arg BUILDKIT_INLINE_CACHE=1 \ \ @@ -85,6 +81,8 @@ runs: --label org.opencontainers.image.created=${BUILD_DATE} \ --label org.opencontainers.image.source=${GITHUB_URL} \ --label org.opencontainers.image.revision=${GITHUB_SHA} + set +x + echo "::endgroup::" echo "::group::Inspecting the image" @@ -97,10 +95,10 @@ runs: run: | echo "::group::Pushing the Docker image to ghcr.io ..." - # expand commands set -x - docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + set +x + echo "::endgroup::" - name: "Push the Docker image to docker.io" @@ -112,12 +110,11 @@ runs: echo "::warning::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed." else echo "::group::Pushing the Docker image to docker.io ..." - - # expand commands - set -x - echo "${DOCKER_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin + set -x docker push --quiet docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + set +x + echo "::endgroup::" fi From 8a3ca90c44e889b5c0ba63f6bc725d705f979056 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:00:47 +0100 Subject: [PATCH 3/9] Merge into a single composite step --- action.yml | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index 08c4b71..0d494c5 100644 --- a/action.yml +++ b/action.yml @@ -32,12 +32,14 @@ runs: shell: bash env: GITHUB_TOKEN: ${{ inputs.github_token }} + DOCKER_BUILDKIT: 1 + DOCKER_IO_TOKEN: ${{ inputs.docker_io_token }} + run: | + echo "::group::Log in to the GitHub Container registry (ghcr.io)" echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + echo "::endgroup::" - - name: Set commit tag and image name - shell: bash - run: | echo "::group::Set commit tag and image name" if [ "${{ github.event_name }}" = "release" ]; then export COMMIT_TAG=${GITHUB_REF:10} @@ -50,11 +52,6 @@ runs: fi echo "::endgroup::" - - name: "Build the Docker image" - shell: bash - env: - DOCKER_BUILDKIT: 1 - run: | export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") export GITHUB_URL=https://github.com/${{ github.repository }} @@ -90,9 +87,6 @@ runs: docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} | jq '.[].Config.Labels' echo "::endgroup::" - - name: "Push the Docker image to ghcr.io" - shell: bash - run: | echo "::group::Pushing the Docker image to ghcr.io ..." set -x @@ -101,16 +95,11 @@ runs: echo "::endgroup::" - - name: "Push the Docker image to docker.io" - shell: bash - env: - DOCKER_TOKEN: ${{ inputs.docker_io_token }} - run: | - if [ -z "${DOCKER_TOKEN}" ]; then + if [ -z "${DOCKER_IO_TOKEN}" ]; then echo "::warning::NOT pushing the Docker image to docker.io ... Provide 'docker_io_token' if needed." else echo "::group::Pushing the Docker image to docker.io ..." - echo "${DOCKER_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin + echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin set -x docker push --quiet docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} From d8e248eb64deb73ac40289999dd04069aed5c742 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:02:57 +0100 Subject: [PATCH 4/9] Update action.yml --- action.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 0d494c5..6b5b7ca 100644 --- a/action.yml +++ b/action.yml @@ -43,13 +43,12 @@ runs: echo "::group::Set commit tag and image name" if [ "${{ github.event_name }}" = "release" ]; then export COMMIT_TAG=${GITHUB_REF:10} - # export COMMIT_TAG=v2.3.0 # debug - echo "COMMIT_TAG=${COMMIT_TAG//v/}" >> $GITHUB_ENV # remove "v" suffix - echo "Tagging with ${COMMIT_TAG//v/}" + export COMMIT_TAG=${COMMIT_TAG//v/} else - echo "COMMIT_TAG=latest" >> $GITHUB_ENV - echo "Tagging with latest" + export COMMIT_TAG=latest fi + + echo "Tagging with ${COMMIT_TAG}" echo "::endgroup::" export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") From 64c9988e85b4ecaafbbbdbc5ec7678baf7d22af7 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:05:14 +0100 Subject: [PATCH 5/9] Fix references to COMMIT_TAG env variable --- action.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 6b5b7ca..ab98044 100644 --- a/action.yml +++ b/action.yml @@ -54,7 +54,7 @@ runs: export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") export GITHUB_URL=https://github.com/${{ github.repository }} - echo "::group::Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} ..." + echo "::group::Building the Docker image: ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} ..." # https://docs.docker.com/develop/develop-images/build_enhancements/ # https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources @@ -67,8 +67,8 @@ runs: --build-arg BUILD_DATE=${BUILD_DATE} \ --build-arg GITHUB_SHA=${GITHUB_SHA} \ \ - --tag ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} \ - --tag docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} \ + --tag ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} \ + --tag docker.io/${{ inputs.image_name }}:${COMMIT_TAG} \ \ --label org.label-schema.build-date=${BUILD_DATE} \ --label org.label-schema.vcs-url=${GITHUB_URL} \ @@ -83,13 +83,13 @@ runs: echo "::group::Inspecting the image" docker images - docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} | jq '.[].Config.Labels' + docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Labels' echo "::endgroup::" echo "::group::Pushing the Docker image to ghcr.io ..." set -x - docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} set +x echo "::endgroup::" @@ -101,7 +101,7 @@ runs: echo "${DOCKER_IO_TOKEN}" | docker login docker.io -u "${{ github.actor }}" --password-stdin set -x - docker push --quiet docker.io/${{ inputs.image_name }}:${{ env.COMMIT_TAG }} + docker push --quiet docker.io/${{ inputs.image_name }}:${COMMIT_TAG} set +x echo "::endgroup::" From 53ae5de0cba095ad5fa6cf90aa2202fb07d8e0e6 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:13:32 +0100 Subject: [PATCH 6/9] docker build . --quiet --- action.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index ab98044..4273e2a 100644 --- a/action.yml +++ b/action.yml @@ -36,7 +36,7 @@ runs: DOCKER_IO_TOKEN: ${{ inputs.docker_io_token }} run: | - echo "::group::Log in to the GitHub Container registry (ghcr.io)" + echo "::group::Logging into the GitHub Container registry (ghcr.io) ..." echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin echo "::endgroup::" @@ -58,9 +58,8 @@ runs: # https://docs.docker.com/develop/develop-images/build_enhancements/ # https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources - set -x - - docker build . \ + time docker build . \ + --quiet \ --cache-from ${{ inputs.repository }}/${{ inputs.image_name }}:latest \ --build-arg BUILDKIT_INLINE_CACHE=1 \ \ @@ -77,16 +76,16 @@ runs: --label org.opencontainers.image.created=${BUILD_DATE} \ --label org.opencontainers.image.source=${GITHUB_URL} \ --label org.opencontainers.image.revision=${GITHUB_SHA} - set +x echo "::endgroup::" - echo "::group::Inspecting the image" + echo "::group::Inspecting the image ..." docker images docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Labels' + docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Env' echo "::endgroup::" - echo "::group::Pushing the Docker image to ghcr.io ..." + echo "::group::Pushing the Docker image to ${{ inputs.repository }} ..." set -x docker push --quiet ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} From a3a67d62d531521f5b73c35383daee7c133ba752 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:17:25 +0100 Subject: [PATCH 7/9] Verbose "docker build" --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 4273e2a..cdee1f6 100644 --- a/action.yml +++ b/action.yml @@ -58,8 +58,7 @@ runs: # https://docs.docker.com/develop/develop-images/build_enhancements/ # https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources - time docker build . \ - --quiet \ + docker build . \ --cache-from ${{ inputs.repository }}/${{ inputs.image_name }}:latest \ --build-arg BUILDKIT_INLINE_CACHE=1 \ \ @@ -75,7 +74,8 @@ runs: \ --label org.opencontainers.image.created=${BUILD_DATE} \ --label org.opencontainers.image.source=${GITHUB_URL} \ - --label org.opencontainers.image.revision=${GITHUB_SHA} + --label org.opencontainers.image.revision=${GITHUB_SHA} \ + | tee echo "::endgroup::" From 628042bbcf84d58737b8e33f81f4a5a66a460b0c Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:18:35 +0100 Subject: [PATCH 8/9] Set GITHUB_SHA env variable --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5a45c03..c3797bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,10 @@ RUN apk update \ && apk -a info curl \ && apk add curl -# these two are passed as build args and stored as env variables +# these two are passed as build args ARG BUILD_DATE ARG GITHUB_SHA +ENV GITHUB_SHA=$GITHUB_SHA + RUN env | sort From c49557bed47909511d0edbf539312e4f33d60d73 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Mon, 13 Sep 2021 18:20:46 +0100 Subject: [PATCH 9/9] Update action.yml --- action.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index cdee1f6..8fa76a2 100644 --- a/action.yml +++ b/action.yml @@ -59,6 +59,7 @@ runs: # https://docs.docker.com/develop/develop-images/build_enhancements/ # https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources docker build . \ + --quiet \ --cache-from ${{ inputs.repository }}/${{ inputs.image_name }}:latest \ --build-arg BUILDKIT_INLINE_CACHE=1 \ \ @@ -74,15 +75,19 @@ runs: \ --label org.opencontainers.image.created=${BUILD_DATE} \ --label org.opencontainers.image.source=${GITHUB_URL} \ - --label org.opencontainers.image.revision=${GITHUB_SHA} \ - | tee + --label org.opencontainers.image.revision=${GITHUB_SHA} echo "::endgroup::" echo "::group::Inspecting the image ..." docker images + + echo "Labels:" docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Labels' + + echo "Env variables:" docker image inspect ${{ inputs.repository }}/${{ inputs.image_name }}:${COMMIT_TAG} | jq '.[].Config.Env' + echo "::endgroup::" echo "::group::Pushing the Docker image to ${{ inputs.repository }} ..."