From 1d4efd8eeeb8df3520c87352f7aac75c28babbf3 Mon Sep 17 00:00:00 2001 From: Hiroto Funakoshi Date: Tue, 27 Feb 2024 13:57:34 +0900 Subject: [PATCH] Update build rule for nightly image (#2421) * fix: update build rule for nightly Signed-off-by: hlts2 * fix: indent and deleted unnecessary tag Signed-off-by: hlts2 * fix: update tag name when tag is unknown Signed-off-by: hlts2 * fix: add secondary tags for build performance Signed-off-by: hlts2 * fix: argument order Signed-off-by: hlts2 --------- Signed-off-by: hlts2 --- .../determine-docker-image-tag/action.yaml | 57 +++++++++++-------- .github/actions/docker-build/action.yaml | 13 ++--- Makefile.d/docker.mk | 2 +- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/.github/actions/determine-docker-image-tag/action.yaml b/.github/actions/determine-docker-image-tag/action.yaml index 1705c2972d..9354f38698 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,21 +80,28 @@ 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" + 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}') + 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 ffd4d0757d..a688286cb0 100644 --- a/.github/actions/docker-build/action.yaml +++ b/.github/actions/docker-build/action.yaml @@ -94,13 +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 [[ "${tag}" = "nightly" ]] && (! [[ "$GITHUB_REF" =~ ^refs/heads/main$ ]] || ! [[ "$GITHUB_REF" =~ ^refs/heads/master$ ]]); then - continue - fi + 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 @@ -109,8 +104,8 @@ 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 }} 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 @@ -129,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 }} 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