From 2e725117cec16015568c77905ec2ab025eed6c37 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 27 Feb 2024 11:26:51 +0900 Subject: [PATCH 1/5] fix: update build rule for nightly Signed-off-by: hlts2 --- .github/actions/docker-build/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index ffd4d0757d..2a8f39c633 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -98,7 +98,7 @@ runs: extra_tags="-t ${IMAGE_NAME}:${PRIMARY_TAG} -t ${ALTER_IMAGE_NAME}:${PRIMARY_TAG}" else for tag in ${TAGS}; do - if [[ "${tag}" = "nightly" ]] && (! [[ "$GITHUB_REF" =~ ^refs/heads/main$ ]] || ! [[ "$GITHUB_REF" =~ ^refs/heads/master$ ]]); then + if [[ "${tag}" = "nightly" ]] && ! ([[ "$GITHUB_REF" =~ ^refs/heads/main$ ]] || [[ "$GITHUB_REF" =~ ^refs/heads/master$ ]]); then continue fi extra_tags="${extra_tags} -t ${IMAGE_NAME}:${tag} -t ${ALTER_IMAGE_NAME}:${tag}" From 017d231cb3e2c94a434e96999affe5c5223ff654 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 27 Feb 2024 12:20:00 +0900 Subject: [PATCH 2/5] fix: indent and deleted unnecessary tag Signed-off-by: hlts2 --- .../determine-docker-image-tag/action.yaml | 43 +++++++++---------- .github/actions/docker-build/action.yaml | 3 -- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/actions/determine-docker-image-tag/action.yaml b/.github/actions/determine-docker-image-tag/action.yaml index 1705c2972d..cf1641f2a9 100644 --- a/.github/actions/determine-docker-image-tag/action.yaml +++ b/.github/actions/determine-docker-image-tag/action.yaml @@ -38,24 +38,24 @@ runs: id: determine_tag_name run: | if [[ "$GITHUB_REF" =~ ^refs/tags/.* ]]; then - # The following is the priority of tags: - # tag -> release/vx.x tag (release branch build tag) -> commit hash tag -> vx.x -> latest tag - # When a tag is created, the image build for the tag may not be finished. - # In that case, the CI container will use the tag for the release branch. - # At the timing of the creation of the tag, the vx.x points to the previous version, so the priority is lowered. - # (At the timing of the start of the image build for tag, vx.x and tag are equal.) - tag=$(echo $GITHUB_REF | sed -e 's:^refs/tags/::') # e.g) v1.7.6 - tags="${tag}" + # The following is the priority of tags: + # tag -> release/vx.x tag (release branch build tag) -> commit hash tag -> vx.x -> latest tag + # When a tag is created, the image build for the tag may not be finished. + # In that case, the CI container will use the tag for the release branch. + # At the timing of the creation of the tag, the vx.x points to the previous version, so the priority is lowered. + # (At the timing of the start of the image build for tag, vx.x and tag are equal.) + tag=$(echo $GITHUB_REF | sed -e 's:^refs/tags/::') # e.g) v1.7.6 + tags="${tag}" - release_branch_tag="release/${major_minor_tag}" # e.g) release/v1.7 - tags="${tags} ${release_branch_tag}" + release_branch_tag="release/${major_minor_tag}" # e.g) release/v1.7 + tags="${tags} ${release_branch_tag}" - major_minor_tag="$(echo "${tag}" | sed -E 's/^v?([0-9]+\.[0-9]+).*$/v\1/')" # e.g) v.1.7 - tags="${tags} ${major_minor_tag}" + major_minor_tag="$(echo "${tag}" | sed -E 's/^v?([0-9]+\.[0-9]+).*$/v\1/')" # e.g) v.1.7 + tags="${tags} ${major_minor_tag}" - commit_hash_tag=${GITHUB_SHA::8} - tags="${tags} ${commit_hash_tag}" - tags="${tags} latest" + commit_hash_tag=${GITHUB_SHA::8} + tags="${tags} ${commit_hash_tag}" + tags="${tags} latest" elif [[ "${{ github.event_name }}" = "pull_request" || "${{ github.event_name }}" = "pull_request_target" ]]; then # The following is the priority of tags: @@ -80,14 +80,13 @@ runs: tags="${tags} nightly" elif [[ "$GITHUB_REF" =~ ^refs/heads/release/v([0-9]+)\.([0-9]+)$ ]]; then - # The following is the priority of tags: - # release/vx.x tag (release branch build tag) -> commit hash tag -> nightly tag - release_branch_tag=$(echo $GITHUB_REF | sed -e 's:^refs/heads/::') # e.g) release/v1.7 - tags="${release_branch_tag}" + # The following is the priority of tags: + # release/vx.x tag (release branch build tag) -> commit hash tag -> nightly tag + release_branch_tag=$(echo $GITHUB_REF | sed -e 's:^refs/heads/::') # e.g) release/v1.7 + tags="${release_branch_tag}" - commit_hash_tag=${GITHUB_SHA::8} - tags="${tags} ${commit_hash_tag}" - tags="${tags} nightly" + commit_hash_tag=${GITHUB_SHA::8} + tags="${tags} ${commit_hash_tag}" else tags="unknown" fi diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index 2a8f39c633..bfa466bd72 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -98,9 +98,6 @@ runs: extra_tags="-t ${IMAGE_NAME}:${PRIMARY_TAG} -t ${ALTER_IMAGE_NAME}:${PRIMARY_TAG}" else for tag in ${TAGS}; do - if [[ "${tag}" = "nightly" ]] && ! ([[ "$GITHUB_REF" =~ ^refs/heads/main$ ]] || [[ "$GITHUB_REF" =~ ^refs/heads/master$ ]]); then - continue - fi extra_tags="${extra_tags} -t ${IMAGE_NAME}:${tag} -t ${ALTER_IMAGE_NAME}:${tag}" done fi From 7cd750419488ecedc74d32669bd9be1dc7ff5245 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 27 Feb 2024 12:30:39 +0900 Subject: [PATCH 3/5] fix: update tag name when tag is unknown Signed-off-by: hlts2 --- .github/actions/determine-docker-image-tag/action.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/actions/determine-docker-image-tag/action.yaml b/.github/actions/determine-docker-image-tag/action.yaml index cf1641f2a9..fafa5f781d 100644 --- a/.github/actions/determine-docker-image-tag/action.yaml +++ b/.github/actions/determine-docker-image-tag/action.yaml @@ -88,7 +88,12 @@ runs: commit_hash_tag=${GITHUB_SHA::8} tags="${tags} ${commit_hash_tag}" else - tags="unknown" + tag_prefix="unknown/${{ github.event_name }}" + if [[ "$GITHUB_BASE_REF" != "" ]]; then + tags="${tag_prefix}/${GITHUB_BASE_REF}" + else + tags="${tag_prefix}/${GITHUB_SHA::8}" + fi fi primary_tag=$(echo ${tags} | awk '{print $1}') From 3e6757d5b5ffc8a9ce156052efb78579dbb08d50 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 27 Feb 2024 12:51:49 +0900 Subject: [PATCH 4/5] fix: add secondary tags for build performance Signed-off-by: hlts2 --- .github/actions/determine-docker-image-tag/action.yaml | 7 +++++-- .github/actions/docker-build/action.yaml | 8 +++----- Makefile.d/docker.mk | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/actions/determine-docker-image-tag/action.yaml b/.github/actions/determine-docker-image-tag/action.yaml index fafa5f781d..9354f38698 100644 --- a/.github/actions/determine-docker-image-tag/action.yaml +++ b/.github/actions/determine-docker-image-tag/action.yaml @@ -96,9 +96,12 @@ runs: fi fi primary_tag=$(echo ${tags} | awk '{print $1}') + secondary_tags=$(echo ${tags} | awk '{$1=""; print substr($0,2)}') echo "Determined tags: ${tags}" echo "Primary tag: ${primary_tag}" + echo "Secondary tags: ${secondary_tags}" - echo "TAGS=${tags}" >> $GITHUB_OUTPUT - echo "PRIMARY_TAG=${primary_tag}" >> $GITHUB_OUTPUT + echo "TAGS=${tags}" >> $GITHUB_OUTPUT + echo "PRIMARY_TAG=${primary_tag}" >> $GITHUB_OUTPUT + echo "SECONDARY_TAGS=${secondary_tags}" >> $GITHUB_OUTPUT diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index bfa466bd72..9584b4b4d1 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -94,10 +94,8 @@ runs: shell: bash id: add_extra_tags run: | - if [[ "${{ github.event_name }}" = "pull_request" || "${{ github.event_name }}" = "pull_request_target" ]]; then - extra_tags="-t ${IMAGE_NAME}:${PRIMARY_TAG} -t ${ALTER_IMAGE_NAME}:${PRIMARY_TAG}" - else - for tag in ${TAGS}; do + if [[ "${{ github.event_name }}" != "pull_request" && "${{ github.event_name }}" != "pull_request_target" ]]; then + for tag in ${SECONDARY_TAGS}; do extra_tags="${extra_tags} -t ${IMAGE_NAME}:${tag} -t ${ALTER_IMAGE_NAME}:${tag}" done fi @@ -106,7 +104,7 @@ runs: env: IMAGE_NAME: ${{ steps.image_name.outputs.IMAGE_NAME }} ALTER_IMAGE_NAME: ${{ steps.image_name.outputs.ALTER_IMAGE_NAME }} - TAGS: ${{ steps.determine_tag_name.outputs.TAGS }} + SECONDARY_TAGS: ${{ steps.determine_tag_name.outputs.SECONDARY_TAGS }} PRIMARY_TAG: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }} - name: Build and Push shell: bash diff --git a/Makefile.d/docker.mk b/Makefile.d/docker.mk index 059faea074..7ecadeb5b7 100644 --- a/Makefile.d/docker.mk +++ b/Makefile.d/docker.mk @@ -53,11 +53,11 @@ ifeq ($(REMOTE),true) --build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \ --build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \ --build-arg MAINTAINER=$(MAINTAINER) \ - $(EXTRA_ARGS) \ --sbom=true \ --provenance=mode=max \ -t $(CRORG)/$(IMAGE):$(TAG) \ -t $(GHCRORG)/$(IMAGE):$(TAG) \ + $(EXTRA_ARGS) \ --output type=registry,oci-mediatypes=true,compression=zstd,compression-level=5,force-compression=true,push=true \ -f $(DOCKERFILE) . else From ccba5151835d6d88416420be7ee558ea95d03488 Mon Sep 17 00:00:00 2001 From: hlts2 Date: Tue, 27 Feb 2024 12:55:05 +0900 Subject: [PATCH 5/5] fix: argument order Signed-off-by: hlts2 --- .github/actions/docker-build/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/docker-build/action.yaml b/.github/actions/docker-build/action.yaml index 9584b4b4d1..a688286cb0 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -104,8 +104,8 @@ runs: env: IMAGE_NAME: ${{ steps.image_name.outputs.IMAGE_NAME }} ALTER_IMAGE_NAME: ${{ steps.image_name.outputs.ALTER_IMAGE_NAME }} - SECONDARY_TAGS: ${{ steps.determine_tag_name.outputs.SECONDARY_TAGS }} PRIMARY_TAG: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }} + SECONDARY_TAGS: ${{ steps.determine_tag_name.outputs.SECONDARY_TAGS }} - name: Build and Push shell: bash id: build_and_push @@ -124,5 +124,5 @@ runs: PLATFORMS: ${{ steps.determine_platforms.outputs.PLATFORMS }} BUILDER: ${{ inputs.builder }} LABEL_OPTS: "--label org.opencontainers.image.url=${{ github.event.repository.html_url }} --label org.opencontainers.image.source=${{ github.event.repository.html_url }} --label org.opencontainers.image.revision=${{ github.sha }}" - EXTRA_TAGS: ${{ steps.add_extra_tags.outputs.EXTRA_TAGS }} PRIMARY_TAG: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }} + EXTRA_TAGS: ${{ steps.add_extra_tags.outputs.EXTRA_TAGS }}