|
| 1 | +name: Build on release and push to Docker Hub |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - "v*" |
| 6 | +jobs: |
| 7 | + main: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + permissions: |
| 10 | + contents: read |
| 11 | + packages: write |
| 12 | + env: |
| 13 | + DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 |
| 14 | + DOCKER_IMAGE: haproxytech/haproxy-unified-gateway |
| 15 | + LATEST_BRANCH: "dev" |
| 16 | + steps: |
| 17 | + - name: Login to Docker Hub |
| 18 | + id: login_docker |
| 19 | + uses: docker/login-action@v1 |
| 20 | + with: |
| 21 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 22 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 23 | + |
| 24 | + - name: Login to Container Registry |
| 25 | + id: login_ghcr |
| 26 | + uses: docker/login-action@v1 |
| 27 | + with: |
| 28 | + registry: ghcr.io |
| 29 | + username: ${{ github.actor }} |
| 30 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Set up QEMU |
| 33 | + uses: docker/setup-qemu-action@v1 |
| 34 | + |
| 35 | + - name: Set up Docker Buildx |
| 36 | + id: buildx |
| 37 | + uses: docker/setup-buildx-action@v1 |
| 38 | + |
| 39 | + - name: Cache Docker layers |
| 40 | + uses: actions/cache@v4 |
| 41 | + with: |
| 42 | + path: /tmp/.buildx-cache |
| 43 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-buildx- |
| 46 | +
|
| 47 | + - name: Check out repo |
| 48 | + id: checkout |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + |
| 53 | + - name: Prepare env variables |
| 54 | + id: env |
| 55 | + run: | |
| 56 | + echo "BUILD_BRANCH=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g' | cut -d. -f-2)" >> $GITHUB_ENV |
| 57 | + echo "BUILD_VER=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's:^v::g')" >> $GITHUB_ENV |
| 58 | + echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV |
| 59 | + echo "GIT_SHA=$(git rev-parse --short HEAD | cut -c1-7)" >> $GITHUB_ENV |
| 60 | + echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV |
| 61 | + echo "LATEST_BRANCH=$(curl -sfSL 'https://raw.githubusercontent.com/haproxytech/haproxy-unified-gateway/master/documentation/doc.yaml' 2>/dev/null | awk -F: '/^active_version/ {gsub(/^ /,"",$2); print $2}' || echo $LATEST_BRANCH)" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + - name: Build and push latest stable branch |
| 64 | + if: ${{ env.BUILD_BRANCH == env.LATEST_BRANCH }} |
| 65 | + id: docker_build_latest |
| 66 | + uses: docker/build-push-action@v2 |
| 67 | + with: |
| 68 | + context: . |
| 69 | + file: build/Dockerfile |
| 70 | + builder: ${{ steps.buildx.outputs.name }} |
| 71 | + platforms: ${{ env.DOCKER_PLATFORMS }} |
| 72 | + push: true |
| 73 | + labels: | |
| 74 | + org.opencontainers.image.authors=${{ github.repository_owner }} |
| 75 | + org.opencontainers.image.created=${{ env.BUILD_DATE }} |
| 76 | + org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} |
| 77 | + org.opencontainers.image.ref.name=${{ env.GIT_REF }} |
| 78 | + org.opencontainers.image.revision=${{ env.GIT_SHA }} |
| 79 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 80 | + org.opencontainers.image.version=${{ env.BUILD_VER }} |
| 81 | + tags: | |
| 82 | + ${{ env.DOCKER_IMAGE }}:latest |
| 83 | + ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }} |
| 84 | + ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }} |
| 85 | + ghcr.io/${{ github.repository }}:latest |
| 86 | + ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }} |
| 87 | + ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }} |
| 88 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 89 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 90 | + |
| 91 | + - name: Build and push everything else |
| 92 | + if: ${{ env.BUILD_BRANCH != env.LATEST_BRANCH }} |
| 93 | + id: docker_build_regular |
| 94 | + uses: docker/build-push-action@v2 |
| 95 | + with: |
| 96 | + context: . |
| 97 | + file: build/Dockerfile |
| 98 | + builder: ${{ steps.buildx.outputs.name }} |
| 99 | + platforms: ${{ env.DOCKER_PLATFORMS }} |
| 100 | + push: true |
| 101 | + labels: | |
| 102 | + org.opencontainers.image.authors=${{ github.repository_owner }} |
| 103 | + org.opencontainers.image.created=${{ env.BUILD_DATE }} |
| 104 | + org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} |
| 105 | + org.opencontainers.image.ref.name=${{ env.GIT_REF }} |
| 106 | + org.opencontainers.image.revision=${{ env.GIT_SHA }} |
| 107 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 108 | + org.opencontainers.image.version=${{ env.BUILD_VER }} |
| 109 | + tags: | |
| 110 | + ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_BRANCH }} |
| 111 | + ${{ env.DOCKER_IMAGE }}:${{ env.BUILD_VER }} |
| 112 | + ghcr.io/${{ github.repository }}:${{ env.BUILD_BRANCH }} |
| 113 | + ghcr.io/${{ github.repository }}:${{ env.BUILD_VER }} |
| 114 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 115 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 116 | + |
| 117 | + - name: Move cache |
| 118 | + run: | |
| 119 | + rm -rf /tmp/.buildx-cache |
| 120 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments