|
1 | 1 | name: Publish Docker image |
| 2 | + |
| 3 | +env: |
| 4 | + IMAGE_NAME: docker.io/botsudo/capistrano |
| 5 | + HUB_TOOL_VERSION: 0.4.6 |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
2 | 10 | on: |
3 | 11 | push: |
4 | 12 | tags: |
5 | | - - 'latest' |
6 | | - - '*.*.*' |
| 13 | + - "latest" |
| 14 | + - "*.*.*" |
7 | 15 |
|
8 | 16 | jobs: |
9 | | - push_to_registry: |
| 17 | + build-image: |
| 18 | + environment: |
| 19 | + name: Docker Hub |
| 20 | + url: https://hub.docker.com/r/botsudo/capistrano |
| 21 | + runs-on: ubuntu-latest |
| 22 | + name: Build the Docker image |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + max-parallel: 4 |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + # All non supported by base image are commented |
| 29 | + # This is an example for the base image ruby (alpine variant) |
| 30 | + - { platform: "linux/arm64", internal-tag: "arm64" } |
| 31 | + - { platform: "linux/amd64", internal-tag: "amd64" } |
| 32 | + - { platform: "linux/arm/v7", internal-tag: "armv7" } |
| 33 | + - { platform: "linux/arm/v6", internal-tag: "armv6" } |
| 34 | + - { platform: "linux/ppc64le", internal-tag: "ppc64le" } |
| 35 | + - { platform: "linux/riscv64", internal-tag: "riscv64" } |
| 36 | + - { platform: "linux/s390x", internal-tag: "s390x" } |
| 37 | + - { platform: "linux/386", internal-tag: "386" } |
| 38 | + #- { platform: "linux/mips64le", internal-tag: "mips64le" } |
| 39 | + #- { platform: "linux/mips64", internal-tag: "mips64" } |
| 40 | + steps: |
| 41 | + - name: Checkout repository |
| 42 | + uses: actions/checkout@v4 |
| 43 | + # https://github.com/docker/setup-qemu-action |
| 44 | + - name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v3 |
| 46 | + # https://github.com/docker/setup-buildx-action |
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v3 |
| 49 | + - name: Login to DockerHub |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: docker.io |
| 53 | + username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }} |
| 54 | + password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }} |
| 55 | + - name: Build and push image |
| 56 | + run: make docker-build |
| 57 | + env: |
| 58 | + DOCKER_BUILDKIT: 1 |
| 59 | + BUILDKIT_MULTI_PLATFORM: "false" |
| 60 | + PLATFORM: ${{ matrix.platform }} |
| 61 | + IMAGE_TAG: "${{ env.IMAGE_NAME }}:${{ matrix.internal-tag }}-symfony" |
| 62 | + ACTION: push |
| 63 | + # Disable provenance to remove the attestation from the pushed image |
| 64 | + # See: https://github.com/docker/buildx/issues/1509 |
| 65 | + # It makes: ${{ env.IMAGE_NAME }}:<arch>-symfony a manifest list |
| 66 | + # And docker manifest create does not like that |
| 67 | + EXTRA_ARGS: "--provenance=false" |
| 68 | + |
| 69 | + create-final-image: |
| 70 | + environment: |
| 71 | + name: Docker Hub |
| 72 | + url: https://hub.docker.com/r/botsudo/capistrano |
| 73 | + runs-on: ubuntu-latest |
| 74 | + needs: build-image |
| 75 | + name: Create the image manifest |
| 76 | + steps: |
| 77 | + - name: Login to DockerHub |
| 78 | + uses: docker/login-action@v3 |
| 79 | + with: |
| 80 | + registry: docker.io |
| 81 | + username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }} |
| 82 | + password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }} |
| 83 | + - name: Create the manifest |
| 84 | + run: | |
| 85 | + docker manifest create ${{ env.IMAGE_NAME }}:symfony \ |
| 86 | + ${{ env.IMAGE_NAME }}:arm64-symfony \ |
| 87 | + ${{ env.IMAGE_NAME }}:amd64-symfony \ |
| 88 | + ${{ env.IMAGE_NAME }}:armv7-symfony \ |
| 89 | + ${{ env.IMAGE_NAME }}:armv6-symfony \ |
| 90 | + ${{ env.IMAGE_NAME }}:ppc64le-symfony \ |
| 91 | + ${{ env.IMAGE_NAME }}:riscv64-symfony \ |
| 92 | + ${{ env.IMAGE_NAME }}:s390x-symfony \ |
| 93 | + ${{ env.IMAGE_NAME }}:386-symfony \ |
| 94 | + --amend |
| 95 | + - name: Push the manifest |
| 96 | + run: docker manifest push ${{ env.IMAGE_NAME }}:symfony |
| 97 | + - name: Inspect the manifest |
| 98 | + run: docker manifest inspect ${{ env.IMAGE_NAME }}:symfony |
| 99 | + |
| 100 | + tags-cleanup: |
10 | 101 | environment: |
11 | | - name: Docker Hub |
12 | | - url: https://hub.docker.com/r/botsudo/capistrano |
13 | | - name: Push Docker image to Docker Hub |
| 102 | + name: Docker Hub |
| 103 | + url: https://hub.docker.com/r/botsudo/capistrano |
14 | 104 | runs-on: ubuntu-latest |
| 105 | + needs: create-final-image |
| 106 | + name: Cleanup build tags |
15 | 107 | steps: |
16 | | - - name: Check out the repository |
17 | | - uses: actions/checkout@v4 |
18 | | - - name: Login to DockerHub |
19 | | - uses: docker/login-action@v3 |
20 | | - with: |
21 | | - registry: docker.io |
22 | | - username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }} |
23 | | - password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }} |
24 | | - - name: Get the version |
25 | | - id: get_version |
26 | | - run: echo ::set-output name=VERSION::$(make version) |
27 | | - - name: Build action image |
28 | | - run: make docker-build |
29 | | - env: |
30 | | - IMAGE_TAG: docker.io/botsudo/capistrano:${{ steps.get_version.outputs.VERSION }}-symfony |
31 | | - - name: Sign and push docker image |
32 | | - uses: sudo-bot/action-docker-sign@latest |
33 | | - with: |
34 | | - image-ref: "docker.io/botsudo/capistrano:${{ steps.get_version.outputs.VERSION }}-symfony" |
35 | | - private-key-id: "${{ secrets.DOCKER_PRIVATE_KEY_ID }}" |
36 | | - private-key: ${{ secrets.DOCKER_PRIVATE_KEY }} |
37 | | - private-key-passphrase: ${{ secrets.DOCKER_PRIVATE_KEY_PASSPHRASE }} |
| 108 | + - name: Install Docker hub-tool |
| 109 | + run: | |
| 110 | + curl -sL https://github.com/docker/hub-tool/releases/download/v${{ env.HUB_TOOL_VERSION }}/hub-tool-linux-amd64.tar.gz -o hub-tool-linux.tar.gz |
| 111 | + tar --strip-components=1 -xzf ./hub-tool-linux.tar.gz |
| 112 | + ./hub-tool --version |
| 113 | + - name: Login hub-tool |
| 114 | + run: | |
| 115 | + # Fool the login command (https://github.com/docker/hub-tool/pull/198) |
| 116 | + # ./hub-tool login |
| 117 | + # Token commands thank to https://stackoverflow.com/a/59334315/5155484 |
| 118 | + HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"$DOCKER_USERNAME\", \"password\": \"$DOCKER_PASSWORD\"}" https://hub.docker.com/v2/users/login/ | jq -r .token) |
| 119 | + USERNAME="$(printf '%s:' "$DOCKER_USERNAME" | base64 -w0)" |
| 120 | + USER_PASS="$(printf '%s:%s' "$DOCKER_USERNAME" "$DOCKER_PASSWORD" | base64 -w0)" |
| 121 | + mkdir -p ~/.docker/ |
| 122 | + printf '{"auths": {"hub-tool": {"auth": "%s"}, "hub-tool-refresh-token": {"auth": "%s"}, "hub-tool-token": { "auth": "%s", "identitytoken": "%s"}}}' \ |
| 123 | + "$USER_PASS" "$USERNAME" \ |
| 124 | + "$USERNAME" "$HUB_TOKEN" \ |
| 125 | + > ~/.docker/config.json |
| 126 | + env: |
| 127 | + DOCKER_USERNAME: ${{ secrets.DOCKER_REPOSITORY_LOGIN }} |
| 128 | + DOCKER_PASSWORD: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }} |
| 129 | + - name: Remove the temporary images via hub-tool |
| 130 | + run: | |
| 131 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:arm64-symfony || true |
| 132 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:amd64-symfony || true |
| 133 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:armv7-symfony || true |
| 134 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:armv6-symfony || true |
| 135 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:ppc64le-symfony || true |
| 136 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:riscv64-symfony || true |
| 137 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:s390x-symfony || true |
| 138 | + ./hub-tool tag rm --verbose --force ${{ env.IMAGE_NAME }}:386-symfony || true |
| 139 | + ./hub-tool tag ls --verbose ${{ env.IMAGE_NAME }} |
| 140 | + - name: Logout hub-tool |
| 141 | + if: always() |
| 142 | + run: rm ~/.docker/config.json |
0 commit comments