diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index a0d52db..3820da2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -28,24 +28,27 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} - tags: | - # set latest tag for main branch - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', env.RELEASE_BRANCH) }} - type=sha,format=long,prefix= - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Get variables id: vars run: | + echo "latest_image_tag=$(make print-latest-image-tag)" >> "$GITHUB_OUTPUT" echo "aws_cli_version=$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[1]}')" >> "$GITHUB_OUTPUT" echo "alpine_version=$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[2]}')" >> "$GITHUB_OUTPUT" + echo "static_tag=$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[1]}')-alpine$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[2]}')" >> "$GITHUB_OUTPUT" + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ steps.vars.outputs.static_tag }},enable=${{ github.ref == format('refs/heads/{0}', env.RELEASE_BRANCH) }} + # set latest tag for main branch and if the static_tag is the latest version configured in the Makefile + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', env.RELEASE_BRANCH) && steps.vars.outputs.static_tag == steps.vars.outputs.latest_image_tag }} + type=sha,format=long,prefix=${{ steps.vars.outputs.static_tag }}- - name: Build Docker image uses: docker/build-push-action@v5 @@ -75,24 +78,27 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} - tags: | - # set latest tag for main branch - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', env.RELEASE_BRANCH) }} - type=sha,format=long,prefix= - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Get variables id: vars run: | + echo "latest_image_tag=$(make print-latest-image-tag)" >> "$GITHUB_OUTPUT" echo "aws_cli_version=$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[1]}')" >> "$GITHUB_OUTPUT" echo "alpine_version=$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[2]}')" >> "$GITHUB_OUTPUT" + echo "static_tag=$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[1]}')-alpine$(echo "${{ matrix.tag }}" | awk '{split($0,a,"-"); print a[2]}')" >> "$GITHUB_OUTPUT" + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ steps.vars.outputs.static_tag }},enable=${{ github.ref == format('refs/heads/{0}', env.RELEASE_BRANCH) }} + # set latest tag for main branch and if the static_tag is the latest version configured in the Makefile + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', env.RELEASE_BRANCH) && steps.vars.outputs.static_tag == steps.vars.outputs.latest_image_tag }} + type=sha,format=long,prefix=${{ steps.vars.outputs.static_tag }}- - name: Build Docker image uses: docker/build-push-action@v5 diff --git a/Makefile b/Makefile index 4bc3065..cf80d61 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ AUTHOR ?= sparkfabrik IMAGE_NAME ?= docker-alpine-aws-cli PLATFORM ?= "linux/amd64" +LATEST_VERSION ?= 2.15.14-alpine3.18 build: build-2.15.14-3.18 @@ -37,3 +38,6 @@ build-template: --build-arg ALPINE_VERSION=$(ALPINE_VERSION) \ --build-arg AWS_CLI_VERSION=$(AWS_CLI_VERSION) \ -t $(AUTHOR)/$(IMAGE_NAME):$(AWS_CLI_VERSION)-alpine$(ALPINE_VERSION) + +print-latest-image-tag: + @echo $(LATEST_VERSION)