|
| 1 | +name: tags |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + multiarch-to-dockerhub-tag: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v2 |
| 15 | + |
| 16 | + # Parse the ref to get the clean tag name. |
| 17 | + - id: get_version |
| 18 | + uses: battila7/get-version-action@v2 |
| 19 | + - run: echo Current tag ${{ steps.get_version.outputs.version }} |
| 20 | + |
| 21 | + # Setup qEMU for arm64 |
| 22 | + - name: Set up QEMU |
| 23 | + uses: docker/setup-qemu-action@v1 |
| 24 | + with: |
| 25 | + platforms: arm64 |
| 26 | + |
| 27 | + # We use buildx instead of regular build so we can take advantage of Docker layer cache via GithubActions's cache |
| 28 | + # Also buildx offers multi-arch builds |
| 29 | + - name: Set up Docker Buildx |
| 30 | + id: buildx |
| 31 | + uses: docker/setup-buildx-action@v1 |
| 32 | + |
| 33 | + # Setup the Github Actions cache. |
| 34 | + - name: Cache Docker layers |
| 35 | + uses: actions/cache@v2 |
| 36 | + with: |
| 37 | + path: /tmp/.buildx-cache |
| 38 | + key: ${{ runner.os }}-buildxarch-${{ github.sha }} |
| 39 | + restore-keys: | |
| 40 | + ${{ runner.os }}-buildxarch- |
| 41 | +
|
| 42 | + - name: Login to DockerHub |
| 43 | + uses: docker/login-action@v1 |
| 44 | + with: |
| 45 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 46 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 47 | + |
| 48 | + # the arm64 is of course much slower due to qemu, so build and push amd64 **first** |
| 49 | + # due to the way manifests work, the gap between this and the complete push below |
| 50 | + # could result in pull failures or inconsistencies for arm64, such is life. |
| 51 | + # further duplicated by building both release and debug builds |
| 52 | + - name: Build and push amd64 Release Docker Image to DockerHub |
| 53 | + uses: docker/build-push-action@v2 |
| 54 | + with: |
| 55 | + build-args: DEBUG_BUILD=0,BASE_IMAGE_SUFFIX="" |
| 56 | + builder: ${{ steps.buildx.outputs.name }} |
| 57 | + context: . |
| 58 | + file: ./Dockerfile |
| 59 | + platforms: linux/amd64 |
| 60 | + tags: rpardini/docker-registry-proxy:${{ steps.get_version.outputs.version }} |
| 61 | + push: true |
| 62 | + cache-from: type=local,src=/tmp/.buildx-cache/release |
| 63 | + # first run does not export the cache |
| 64 | + |
| 65 | + - name: Build and push amd64 Debug Docker Image to DockerHub |
| 66 | + uses: docker/build-push-action@v2 |
| 67 | + with: |
| 68 | + build-args: DEBUG_BUILD=1,BASE_IMAGE_SUFFIX="-debug" |
| 69 | + builder: ${{ steps.buildx.outputs.name }} |
| 70 | + context: . |
| 71 | + file: ./Dockerfile |
| 72 | + platforms: linux/amd64 |
| 73 | + tags: rpardini/docker-registry-proxy:${{ steps.get_version.outputs.version }}-debug |
| 74 | + push: true |
| 75 | + cache-from: type=local,src=/tmp/.buildx-cache/debug |
| 76 | + # first run does not export the cache |
| 77 | + |
| 78 | + # Do it all again with both archs. the amd64 will be a huge cache hit |
| 79 | + # this will update the manifest have both arches |
| 80 | + - name: Build and push multiarch Release Docker Image to DockerHub |
| 81 | + uses: docker/build-push-action@v2 |
| 82 | + with: |
| 83 | + build-args: DEBUG_BUILD=0,BASE_IMAGE_SUFFIX="" |
| 84 | + builder: ${{ steps.buildx.outputs.name }} |
| 85 | + context: . |
| 86 | + file: ./Dockerfile |
| 87 | + platforms: linux/arm64,linux/amd64 |
| 88 | + tags: rpardini/docker-registry-proxy:${{ steps.get_version.outputs.version }} |
| 89 | + push: true |
| 90 | + cache-from: type=local,src=/tmp/.buildx-cache/release |
| 91 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache/release |
| 92 | + |
| 93 | + - name: Build and push multiarch Debug Docker Image to DockerHub |
| 94 | + uses: docker/build-push-action@v2 |
| 95 | + with: |
| 96 | + build-args: DEBUG_BUILD=1,BASE_IMAGE_SUFFIX="-debug" |
| 97 | + builder: ${{ steps.buildx.outputs.name }} |
| 98 | + context: . |
| 99 | + file: ./Dockerfile |
| 100 | + platforms: linux/arm64,linux/amd64 |
| 101 | + tags: rpardini/docker-registry-proxy:${{ steps.get_version.outputs.version }}-debug |
| 102 | + push: true |
| 103 | + cache-from: type=local,src=/tmp/.buildx-cache/debug |
| 104 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache/debug |
| 105 | + |
0 commit comments