Automatic build on release and push to Docker Hub #1002
Workflow file for this run
This file contains hidden or 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: Automatic build on release and push to Docker Hub | |
| on: | |
| push: | |
| tags: | |
| - "[0-9]+.[0-9]+.[0-9]+" | |
| - "[0-9]+.[0-9]+-dev[0-9]+" | |
| jobs: | |
| main: | |
| runs-on: large_runner | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| DOCKER_PLATFORMS: linux/amd64,linux/arm/v7,linux/arm64 | |
| DOCKER_IMAGE: haproxytech/haproxy-ubuntu | |
| DOCKER_IMAGE_UNIFIED: haproxytech/haproxy | |
| STABLE_BRANCH: "3.3" | |
| steps: | |
| - name: Login to Docker Hub | |
| id: login_docker | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Login to Container Registry | |
| id: login_ghcr | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Check out repo | |
| id: checkout | |
| uses: actions/checkout@v4 | |
| - name: Prepare env variables | |
| id: env | |
| run: | | |
| echo "BUILD_BRANCH=$(echo $GITHUB_REF | cut -d / -f 3 | cut -d. -f-2 | cut -d- -f1)" >> $GITHUB_ENV | |
| echo "BUILD_VER=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_ENV | |
| echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV | |
| echo "GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
| echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV | |
| - name: Build and push latest stable branch | |
| if: ${{ env.BUILD_BRANCH == env.STABLE_BRANCH }} | |
| id: docker_build_latest | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.BUILD_BRANCH }} | |
| file: ${{ env.BUILD_BRANCH }}/Dockerfile | |
| builder: ${{ steps.buildx.outputs.name }} | |
| platforms: ${{ env.DOCKER_PLATFORMS }} | |
| push: true | |
| labels: | | |
| org.opencontainers.image.authors=${{ github.repository_owner }} | |
| org.opencontainers.image.created=${{ env.BUILD_DATE }} | |
| org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | |
| org.opencontainers.image.ref.name=${{ env.GIT_REF }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ env.BUILD_VER }} | |
| tags: | | |
| ${{ env.DOCKER_IMAGE }}:latest | |
| ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-latest | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-${{ env.BUILD_VER }} | |
| ghcr.io/${{ github.repository }}:latest | |
| ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }} | |
| ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| - name: Move cache | |
| if: ${{ env.BUILD_BRANCH == env.STABLE_BRANCH }} | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| - name: Build and push latest stable branch for s6 | |
| if: ${{ env.BUILD_BRANCH == env.STABLE_BRANCH }} | |
| id: docker_build_latest_s6 | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.BUILD_BRANCH }} | |
| file: ${{ env.BUILD_BRANCH }}/Dockerfile.api | |
| builder: ${{ steps.buildx.outputs.name }} | |
| platforms: ${{ env.DOCKER_PLATFORMS }} | |
| push: true | |
| labels: | | |
| org.opencontainers.image.authors=${{ github.repository_owner }} | |
| org.opencontainers.image.created=${{ env.BUILD_DATE }} | |
| org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | |
| org.opencontainers.image.ref.name=${{ env.GIT_REF }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ env.BUILD_VER }} | |
| tags: | | |
| ${{ env.DOCKER_IMAGE }}:s6-latest | |
| ${{ env.DOCKER_IMAGE }}:s6-${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE }}:s6-${{ env.BUILD_VER }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-s6-latest | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-s6-${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-s6-${{ env.BUILD_VER }} | |
| ghcr.io/${{ github.repository }}:s6-latest | |
| ghcr.io/${{ github.repository }}:s6-${{ env.BUILD_BRANCH }} | |
| ghcr.io/${{ github.repository }}:s6-${{ env.BUILD_VER }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| - name: Move cache for s6 | |
| if: ${{ env.BUILD_BRANCH == env.STABLE_BRANCH }} | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| - name: Build and push everything else | |
| if: ${{ env.BUILD_BRANCH != env.STABLE_BRANCH }} | |
| id: docker_build_regular | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.BUILD_BRANCH }} | |
| file: ${{ env.BUILD_BRANCH }}/Dockerfile | |
| builder: ${{ steps.buildx.outputs.name }} | |
| platforms: ${{ env.DOCKER_PLATFORMS }} | |
| push: true | |
| labels: | | |
| org.opencontainers.image.authors=${{ github.repository_owner }} | |
| org.opencontainers.image.created=${{ env.BUILD_DATE }} | |
| org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | |
| org.opencontainers.image.ref.name=${{ env.GIT_REF }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ env.BUILD_VER }} | |
| tags: | | |
| ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-${{ env.BUILD_VER }} | |
| ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }} | |
| ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| - name: Move cache | |
| if: ${{ env.BUILD_BRANCH != env.STABLE_BRANCH }} | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| - name: Build and push everything else for s6 | |
| if: ${{ env.BUILD_BRANCH != env.STABLE_BRANCH }} | |
| id: docker_build_regular_s6 | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ env.BUILD_BRANCH }} | |
| file: ${{ env.BUILD_BRANCH }}/Dockerfile.api | |
| builder: ${{ steps.buildx.outputs.name }} | |
| platforms: ${{ env.DOCKER_PLATFORMS }} | |
| push: true | |
| labels: | | |
| org.opencontainers.image.authors=${{ github.repository_owner }} | |
| org.opencontainers.image.created=${{ env.BUILD_DATE }} | |
| org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} | |
| org.opencontainers.image.ref.name=${{ env.GIT_REF }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ env.BUILD_VER }} | |
| tags: | | |
| ${{ env.DOCKER_IMAGE }}:s6-${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE }}:s6-${{ env.BUILD_VER }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-s6-${{ env.BUILD_BRANCH }} | |
| ${{ env.DOCKER_IMAGE_UNIFIED }}:ubuntu-s6-${{ env.BUILD_VER }} | |
| ghcr.io/${{ github.repository }}:s6-${{ env.BUILD_BRANCH }} | |
| ghcr.io/${{ github.repository }}:s6-${{ env.BUILD_VER }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| - name: Move cache for s6 | |
| if: ${{ env.BUILD_BRANCH != env.STABLE_BRANCH }} | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache |