@@ -3,9 +3,10 @@ name: Release Docker Image
33run-name : Release Docker Image ${{ github.event_name == 'workflow_dispatch' && inputs.service || '(auto-deploy)' }}
44
55on :
6- push :
7- branches :
8- - main
6+ # TODO: Uncomment this when wf is ready to be triggered by push
7+ # push:
8+ # branches:
9+ # - main
910
1011 workflow_dispatch :
1112 inputs :
1415 Version (of the form "1.2.3") or Branch (of the form "origin/branch-name").
1516 Leave empty to bump the latest version.
1617 type : string
18+ version_level :
19+ description : The level of the version to bump.
20+ type : choice
21+ default : ' minor'
22+ required : false
23+ options :
24+ - ' major'
25+ - ' minor'
26+ - ' patch'
1727 build_local :
1828 type : boolean
1929 default : false
5969 timeout-minutes : 10
6070 steps :
6171 - name : Setup
62- uses : docker/actions/setup-go@setup-go/v1
72+ uses : docker/actions/setup-go@33488d0ac7cf5f3616b656b8f2bf28b45467976c # v1.17.0
6373 id : setup_go
6474 with :
6575 app_id : ${{ secrets.HUB_PLATFORM_APP_ID }}
@@ -70,32 +80,25 @@ jobs:
7080 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
7181 with :
7282 token : ${{ steps.setup_go.outputs.token }}
73- fetch-depth : 0
83+ fetch-depth : 0
7484
7585 - name : Bump Version
7686 id : bump_version
77- if : github.event_name == 'push' && inputs.version == ''
78- uses : docker/actions/bump-version@bump-version/v1.1.0
87+ uses : docker/actions/bump-version@132452b833c5fae71bc674fe54384c9242173f96 # v2.5.0
7988 with :
8089 name : ${{ env.NAME }}
90+ level : ${{ inputs.version_level }}
8191
82- - name : Get Latest Version
83- id : latest_version
84- if : github.event_name != 'push' && inputs.version == ''
85- uses : docker/actions/bump-version@bump-version/v1.1.0
86- with :
87- name : ${{ env.NAME }}
88- include_tag : false
8992
9093 - name : Get Release Version
9194 id : release_version
9295 shell : bash
9396 run : |
9497 if [[ '${{ steps.bump_version.outcome }}' == 'success' ]]; then
95- echo "version=${{ steps.bump_version.outputs.next_version_number }}" >> $GITHUB_OUTPUT
96- echo "tag=${{ steps.bump_version.outputs.next_version }}" >> $GITHUB_OUTPUT
97- elif [[ '${{ steps.latest_version .outcome }}' == 'success' ]]; then
98- echo "version=${{ steps.latest_version .outputs.latest_version_number }}" >> $GITHUB_OUTPUT
98+ echo "version=${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_OUTPUT
99+ echo "tag=${{ steps.bump_version.outputs.new_tag }}" >> $GITHUB_OUTPUT
100+ elif [[ '${{ steps.bump_version .outcome }}' == 'success' ]]; then
101+ echo "version=${{ steps.bump_version .outputs.new_version }}" >> $GITHUB_OUTPUT
99102 elif [[ '${{ inputs.version }}' != '' ]]; then
100103 echo "Using already provided version: ${{ inputs.version }}."
101104 echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
@@ -105,13 +108,13 @@ jobs:
105108 fi
106109
107110 - name : Hub Login
108- uses : docker/login-action@v2
111+ uses : docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
109112 with :
110113 username : dockerbuildbot
111114 password : ${{ secrets.DOCKERBUILDBOT_WRITE_PAT }}
112115
113116 - name : Setup Hydrobuild
114- uses : docker/setup-buildx-action@v3
117+ uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
115118 if : ${{ ! inputs.build_local }}
116119 with :
117120 version : " lab:latest"
@@ -123,7 +126,7 @@ jobs:
123126 id : hub_image_exists
124127 shell : bash
125128 run : |
126- if docker manifest inspect docker/${{ env.NAME }}:${{ steps.latest_version .outputs.latest_version_number }}; then
129+ if docker manifest inspect docker/${{ env.NAME }}:${{ steps.bump_version .outputs.new_version }}; then
127130 echo 'exists=true' >> $GITHUB_OUTPUT
128131 else
129132 echo 'exists=false' >> $GITHUB_OUTPUT
@@ -148,9 +151,15 @@ jobs:
148151 sudo systemctl restart docker
149152 fi
150153
154+
155+ - name : Set up QEMU
156+ uses : docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
157+
158+ - name : Set up Docker Buildx
159+ uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
151160 - name : Build and push service image
152161 if : steps.hub_image_exists.outputs.exists == 'false'
153- uses : docker/build-push-action@v5
162+ uses : docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
154163 with :
155164 context : .
156165 file : Dockerfile
@@ -167,10 +176,11 @@ jobs:
167176 com.docker.image.source.entrypoint=Dockerfile
168177 provenance : mode=max
169178 sbom : true
179+ platforms : linux/amd64,linux/arm64
170180
171181 - name : Configure AWS Credentials
172182 if : inputs.mirror_ecr == 'true'
173- uses : aws-actions/configure-aws-credentials@v4
183+ uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
174184 with :
175185 role-session-name : gha-release-service-go-workflow
176186 role-to-assume : ${{ inputs.aws_role_to_assume_arn }}
@@ -179,35 +189,12 @@ jobs:
179189 - name : Log in to Amazon ECR
180190 if : inputs.mirror_ecr == 'true'
181191 id : login_ecr
182- uses : aws-actions/amazon-ecr-login@v2
192+ uses : aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2
183193
184- # # Note: We're disabling this for now so branch images can be overriden
185- # # on-demand. This is pending revisiting branch-based deployments.
186- # - name: Check image exists in AWS ECR
187- # if: inputs.mirror_ecr == 'true'
188- # id: ecr_image_exists
189- # shell: bash
190- # run: |
191- # if docker manifest inspect ${{ steps.login_ecr.outputs.registry }}/${{ inputs.service_name }}:${{ steps.image_tag.outputs.tag }}; then
192- # echo 'exists=true' >> $GITHUB_OUTPUT
193- # else
194- # echo 'exists=false' >> $GITHUB_OUTPUT
195- # fi
196-
197- - name : Vendor modules
198- # Basically, if the Hub image exists, then we need to make sure to vendor
199- # for building the ECR image.
200- if : steps.hub_image_exists.outputs.exists == 'true'
201- working-directory : ${{ inputs.service_directory }}
202- shell : bash
203- run : |
204- if [[ -f "go.mod" ]]; then
205- go mod vendor
206- fi
207194
208195 - name : Build and push Docker image to ECR
209196 if : inputs.mirror_ecr == 'true'
210- uses : docker/build-push-action@v5
197+ uses : docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
211198 with :
212199 context : .
213200 file : Dockerfile
@@ -229,23 +216,3 @@ jobs:
229216 if : inputs.mirror_ecr == true
230217 shell : bash
231218 run : docker logout ${{ steps.login_ecr.outputs.registry }}
232-
233-
234- - name : Restore repository to initial HEAD
235- shell : bash
236- run : git checkout "${{steps.base_branch.outputs.git_ref}}"
237-
238- - name : Delete git tag created by this workflow
239- if : failure() && steps.release_version.outputs.tag != ''
240- shell : bash
241- run : |
242- git push --delete origin ${{ steps.release_version.outputs.tag }}
243- # TODO: Some other things to do on cleanup:
244- #
245- # 1. revert deploy commit in cloud-manifests.
246- #
247- # 2. delete image from Hub. Doesn't create friction often; but might cause
248- # confusion.
249- #
250- # 3. delete image from ECR. Doesn't create friction often; but might cause
251- # confusion.
0 commit comments