Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #2421 to release/v1.7 for Update build rule for nightly image #2422

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading