Publish major (image:x
) and minor (image:x.y
) tags of the Docker images
#26
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: docker-image | |
on: | |
push: | |
tags: | |
- "*" | |
branches: | |
- "main" | |
pull_request: | |
branches: | |
- "main" | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and export | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x | |
cache-from: type=registry,ref=${{ vars.DOCKERHUB_IMAGE }}:buildcache | |
cache-to: type=registry,ref=${{ vars.DOCKERHUB_IMAGE }}:buildcache,mode=max | |
push: true | |
tags: ${{ vars.DOCKERHUB_IMAGE }}:${{ github.sha }} | |
- name: Push semver tags | |
if: github.ref_type == 'tag' | |
run: | | |
GITHUB_REF=${{ github.ref }} | |
GITHUB_TAG=${GITHUB_REF#refs/tags/} | |
TAGS="" | |
if [ "${GITHUB_TAG}" != *-* ]; then # if not a pre-release | |
TAGS+=" --tag ${{ vars.DOCKERHUB_IMAGE }}:${GITHUB_TAG%%.*}" # major version tag (e.g. 1) | |
TAGS+=" --tag ${{ vars.DOCKERHUB_IMAGE }}:${GITHUB_TAG%.*}" # major.minor version tag (e.g. 1.2) | |
fi | |
TAGS+=" --tag ${{ vars.DOCKERHUB_IMAGE }}:${GITHUB_TAG}" # full version tag (e.g. 1.2.3-rc.4) | |
docker buildx imagetools create ${TAGS} ${{ vars.DOCKERHUB_IMAGE }}:${{ github.sha }} | |
- name: Push "latest" tag | |
if: github.ref == 'refs/heads/main' | |
run: | | |
docker buildx imagetools create \ | |
--tag ${{ vars.DOCKERHUB_IMAGE }}:latest \ | |
${{ vars.DOCKERHUB_IMAGE }}:${{ github.sha }} | |
- name: Update repo description | |
if: github.ref == 'refs/heads/main' | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
repository: ${{ vars.DOCKERHUB_IMAGE }} |