|
| 1 | +name: Release Docker Image |
| 2 | + |
| 3 | +run-name: Release Docker Image ${{ github.event_name == 'workflow_dispatch' && '(manual)' || '(auto-deploy)' }} |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: | |
| 14 | + Version (of the form "1.2.3") or Branch (of the form "origin/branch-name"). |
| 15 | + Leave empty to bump the latest version. |
| 16 | + type: string |
| 17 | + version_level: |
| 18 | + description: The level of the version to bump. |
| 19 | + type: choice |
| 20 | + default: 'minor' |
| 21 | + required: true |
| 22 | + options: |
| 23 | + - 'major' |
| 24 | + - 'minor' |
| 25 | + - 'patch' |
| 26 | + build_local: |
| 27 | + type: boolean |
| 28 | + default: false |
| 29 | + description: Uses build-cloud by default. If Build Cloud is down, set this to true to build locally. |
| 30 | + dry_run: |
| 31 | + description: If true, the workflow will not push the image to the registry. |
| 32 | + type: boolean |
| 33 | + default: false |
| 34 | + |
| 35 | + |
| 36 | +env: |
| 37 | + GOPRIVATE: github.com/docker |
| 38 | + NAME: dockerhub-mcp |
| 39 | + VERSION_LEVEL: ${{ inputs.version_level || 'minor' }} |
| 40 | + |
| 41 | +jobs: |
| 42 | + release: |
| 43 | + name: Release Service |
| 44 | + permissions: |
| 45 | + pull-requests: write |
| 46 | + # This permission is required to update the PR body content |
| 47 | + repository-projects: write |
| 48 | + # These permissions are needed to interact with GitHub's OIDC Token |
| 49 | + # endpoint. We need it in order to make requests to AWS ECR for image |
| 50 | + # mirroring. |
| 51 | + id-token: write |
| 52 | + contents: read |
| 53 | + runs-on: ubuntu-latest |
| 54 | + # Internally the create-release action attempts to push a commit to |
| 55 | + # cloud-manifests in a loop to avoid race-conditions. However, this could |
| 56 | + # have the side-effect of making the action hang for ever if we come across |
| 57 | + # a scenario that we haven't thought of. This timeout makes sure to fail the |
| 58 | + # workflow if that happens. |
| 59 | + timeout-minutes: 10 |
| 60 | + steps: |
| 61 | + - name: Setup |
| 62 | + uses: docker/actions/setup-go@33488d0ac7cf5f3616b656b8f2bf28b45467976c #v1.17.0 |
| 63 | + id: setup_go |
| 64 | + with: |
| 65 | + app_id: ${{ secrets.HUB_PLATFORM_APP_ID }} |
| 66 | + app_private_key: ${{ secrets.HUB_PLATFORM_APP_PRIVATE_KEY }} |
| 67 | + go_version: '1.24' |
| 68 | + |
| 69 | + - name: Checkout |
| 70 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 |
| 71 | + with: |
| 72 | + token: ${{ steps.setup_go.outputs.token }} |
| 73 | + fetch-depth: 0 |
| 74 | + |
| 75 | + - name: Bump Version |
| 76 | + id: bump_version |
| 77 | + uses: docker/actions/bump-version@132452b833c5fae71bc674fe54384c9242173f96 # v2.5.0 |
| 78 | + with: |
| 79 | + name: ${{ env.NAME }} |
| 80 | + level: ${{ env.VERSION_LEVEL }} |
| 81 | + |
| 82 | + |
| 83 | + - name: Get Release Version |
| 84 | + id: release_version |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + if [[ '${{ steps.bump_version.outcome }}' == 'success' ]]; then |
| 88 | + echo "version=${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_OUTPUT |
| 89 | + echo "tag=${{ steps.bump_version.outputs.new_tag }}" >> $GITHUB_OUTPUT |
| 90 | + elif [[ '${{ steps.bump_version.outcome }}' == 'success' ]]; then |
| 91 | + echo "version=${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_OUTPUT |
| 92 | + elif [[ '${{ inputs.version }}' != '' ]]; then |
| 93 | + echo "Using already provided version: ${{ inputs.version }}." |
| 94 | + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 95 | + else |
| 96 | + echo "Unable to compute version for staging environment." |
| 97 | + exit 42 |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Hub Login |
| 101 | + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc #v2 |
| 102 | + with: |
| 103 | + username: dockerbuildbot |
| 104 | + password: ${{ secrets.DOCKERBUILDBOT_WRITE_PAT }} |
| 105 | + |
| 106 | + - name: Setup Hydrobuild |
| 107 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3 |
| 108 | + if: ${{ ! inputs.build_local }} |
| 109 | + with: |
| 110 | + version: "lab:latest" |
| 111 | + driver: cloud |
| 112 | + endpoint: docker/platform-experience |
| 113 | + install: true |
| 114 | + |
| 115 | + - name: Check Docker image exists |
| 116 | + id: hub_image_exists |
| 117 | + shell: bash |
| 118 | + run: | |
| 119 | + if docker manifest inspect docker/${{ env.NAME }}:${{ steps.bump_version.outputs.new_version }}; then |
| 120 | + echo 'exists=true' >> $GITHUB_OUTPUT |
| 121 | + else |
| 122 | + echo 'exists=false' >> $GITHUB_OUTPUT |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Ensure attestations are supported |
| 126 | + shell: bash |
| 127 | + # docker buildx inspect | grep Driver |
| 128 | + # Driver: docker |
| 129 | + # indicates that we need to enable containerd so |
| 130 | + # we can compute sboms. |
| 131 | + run: | |
| 132 | + driver=$(docker buildx inspect | grep "Driver:") |
| 133 | + if [[ "$driver" == *"docker"* ]]; then |
| 134 | + echo "detected driver, needs containerd snapshotter enabled: $driver" |
| 135 | + sudo mkdir -p /etc/docker |
| 136 | + if [ -f /etc/docker/daemon.json ]; then |
| 137 | + cat /etc/docker/daemon.json | jq '. + {"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json |
| 138 | + else |
| 139 | + echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json |
| 140 | + fi |
| 141 | + sudo systemctl restart docker |
| 142 | + fi |
| 143 | + |
| 144 | + |
| 145 | + - name: Set up QEMU |
| 146 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3 |
| 147 | + |
| 148 | + - name: Set up Docker Buildx |
| 149 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3 |
| 150 | + - name: Build and push service image |
| 151 | + id: build_and_push |
| 152 | + if: steps.hub_image_exists.outputs.exists == 'false' |
| 153 | + uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5 |
| 154 | + with: |
| 155 | + context: . |
| 156 | + file: Dockerfile |
| 157 | + build-args: | |
| 158 | + SERVICE_NAME=${{ env.NAME }} |
| 159 | + SERVICE_VERSION=${{ steps.release_version.outputs.version }} |
| 160 | + push: ${{ inputs.dry_run != 'true' }} |
| 161 | + tags: | |
| 162 | + docker/${{ env.NAME }}:${{ steps.release_version.outputs.version }} |
| 163 | + docker/${{ env.NAME }}:latest |
| 164 | + labels: | |
| 165 | + org.opencontainers.image.revision=${{ github.event.pull_request.head.sha || github.event.after || github.event.release.tag_name }} |
| 166 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 167 | + com.docker.image.source.entrypoint=Dockerfile |
| 168 | + provenance: mode=max |
| 169 | + sbom: true |
| 170 | + platforms: linux/amd64,linux/arm64 |
| 171 | + |
| 172 | + - name: Delete git tag created by this workflow |
| 173 | + if: failure() && steps.bump_version.outputs.new_tag != '' |
| 174 | + shell: bash |
| 175 | + run: | |
| 176 | + git push --delete origin ${{ steps.bump_version.outputs.new_tag }} |
| 177 | + |
| 178 | + |
0 commit comments