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