diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index fa6f0e9..2acb852 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -46,6 +46,16 @@ jobs: run: | version=`make read-release-version` echo version=$version >> $GITHUB_OUTPUT + - name: Determine quay image expiry + id: quay-expiry + run: | + if [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then + echo "expiry=never" >> $GITHUB_OUTPUT + echo "Setting expiry to 'never' for release tag ${{ github.ref_name }}" + else + echo "expiry=3w" >> $GITHUB_OUTPUT + echo "Setting expiry to '3w' for non-release ref ${{ github.ref_name }}" + fi - name: Build and Push Image if: github.repository_owner == 'kuadrant' id: build-image @@ -61,6 +71,7 @@ jobs: GIT_SHA=${{ github.sha }} DIRTY=false VERSION=${{ steps.release.outputs.version }} + QUAY_IMAGE_EXPIRY=${{ steps.quay-expiry.outputs.expiry }} - name: Print Image URL run: | echo "Image(s) pushed:" diff --git a/Dockerfile b/Dockerfile index de3bb10..7280e26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,4 +38,9 @@ WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532 +# Quay image expiry +ARG QUAY_IMAGE_EXPIRY +ENV QUAY_IMAGE_EXPIRY=${QUAY_IMAGE_EXPIRY:-never} +LABEL quay.expires-after=$QUAY_IMAGE_EXPIRY + ENTRYPOINT ["/manager"] diff --git a/Makefile b/Makefile index 1cf656c..fdff8dc 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,12 @@ # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) VERSION ?= 0.0.0 +# QUAY_IMAGE_EXPIRY defines when to expire the built quay images. +# The time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively, +# from the time the image is built. +QUAY_IMAGE_EXPIRY ?= never + + # IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. # This variable is used to construct full image tags for bundle and catalog images. # @@ -147,6 +153,7 @@ docker-build: ## Build docker image with the manager. --build-arg GIT_SHA=$(GIT_SHA) \ --build-arg DIRTY=$(DIRTY) \ --build-arg VERSION=v$(VERSION) \ + --build-arg QUAY_IMAGE_EXPIRY=$(QUAY_IMAGE_EXPIRY) \ -t ${IMG} . .PHONY: docker-push