Skip to content

Commit

Permalink
Update build rule for nightly image (#2421)
Browse files Browse the repository at this point in the history
* fix: update build rule for nightly

Signed-off-by: hlts2 <[email protected]>

* fix: indent and deleted unnecessary tag

Signed-off-by: hlts2 <[email protected]>

* fix: update tag name when tag is unknown

Signed-off-by: hlts2 <[email protected]>

* fix: add secondary tags for build performance

Signed-off-by: hlts2 <[email protected]>

* fix: argument order

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 authored Feb 27, 2024
1 parent e1b09fe commit 1d4efd8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
57 changes: 32 additions & 25 deletions .github/actions/determine-docker-image-tag/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
13 changes: 4 additions & 9 deletions .github/actions/docker-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion Makefile.d/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d4efd8

Please sign in to comment.