Skip to content

Commit 0af476e

Browse files
authored
fix: minor Docker Build / Docker Push tweaks (#49)
- in `docker-push`, make the name of the GAR service account configurable, though provide a default of artifact-writer - in `docker-build`, build the image name and tag list so that there aren't blank lines when `GHCR` and `latest` images are tagged
1 parent 5974f43 commit 0af476e

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

docker-build/action.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ runs:
4545
env:
4646
REF_TYPE: ${{ github.ref_type }}
4747
REF_NAME: ${{ github.ref_name }}
48-
IMAGE_TAG_METADATA: ${{ input.image_tag_metadata }}
48+
IMAGE_TAG_METADATA: ${{ inputs.image_tag_metadata }}
4949
run: |
5050
if [[ "${REF_TYPE}" == "tag" ]]; then
5151
tag="${REF_NAME}"
@@ -57,17 +57,45 @@ runs:
5757
tag="${tag}--${IMAGE_TAG_METADATA}"
5858
fi
5959
echo "Setting IMAGE_TAG=${tag} as output"
60-
echo "IMAGE_TAG=${tag}" >> "$GITHUB_OUTPUT"
60+
echo "image_tag=${tag}" >> "$GITHUB_OUTPUT"
61+
62+
- name: Set image list
63+
shell: bash
64+
id: set-images
65+
env:
66+
GAR_LOCATION: ${{ inputs.gar_location }}
67+
PROJECT_ID: ${{ inputs.project_id }}
68+
GAR_NAME: ${{ inputs.gar_name }}
69+
IMAGE_NAME: ${{ inputs.image_name }}
70+
SHOULD_TAG_GHCR: ${{ inputs.should_tag_ghcr }}
71+
run: |
72+
images="${GAR_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${GAR_NAME}/${IMAGE_NAME}"
73+
if [[ "${SHOULD_TAG_GHCR}" == "true" ]]; then
74+
images="${images}"$'\n'"ghcr.io/${{ github.repository }}/${IMAGE_NAME}"
75+
fi
76+
echo -e "Generated Images:\n${images}"
77+
echo -e "IMAGES=<<EOF\n${images}\nEOF" >> "$GITHUB_OUTPUT"
78+
79+
- name: Set tag list
80+
shell: bash
81+
id: set-tags
82+
env:
83+
SHOULD_TAG_LATEST: ${{ inputs.should_tag_latest }}
84+
IMAGE_TAG: ${{ steps.mozcloud-tag.outputs.image_tag }}
85+
run: |
86+
tags="type=raw,value=${IMAGE_TAG}"
87+
if [[ "${SHOULD_TAG_LATEST}" == "true" ]]; then
88+
tags="${tags}"$'\n'"type=raw,value=latest"
89+
fi
90+
echo -e "Generated Tags:\n${tags}"
91+
echo -e "TAGS=<<EOF\n${tags}\nEOF" >> "$GITHUB_OUTPUT"
92+
6193
- name: Docker meta
6294
id: meta
6395
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 #v5.7.0
6496
with:
65-
images: |
66-
${{ inputs.gar_location }}-docker.pkg.dev/${{ inputs.project_id }}/${{ inputs.gar_name }}/${{ inputs.image_name }}
67-
${{ (inputs.should_tag_ghcr == 'true' && format('ghcr.io/{0}/{1}', github.repository, inputs.image_name)) || '' }}
68-
tags: |
69-
type=raw,value=${{ steps.mozcloud-tag.outputs.IMAGE_TAG }}
70-
type=raw,value=${{ (inputs.should_tag_latest == 'true' && latest) || ''}}
97+
images: ${{ steps.set-images.outputs.images }}
98+
tags: ${{ steps.set-tags.outputs.tags }}
7199
- name: Build image
72100
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
73101
env:

docker-push/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This GitHub Action is designed to push Docker images to Google Artifact Registry
1111
| `image_tags` | Yes | Newline-delimited list of images to be pushed.<br> Typically generated by `mozilla/deploy-actions/build-image` or `docker/metadata-action`. |
1212
| `workload_identity_pool_project_number` | Yes | Project number of the workload identity pool used for OIDC authentication |
1313
| `project_id` | Yes | GCP `project_id` used to construct the service account |
14+
| `service_account_name` | No | Service account used to authenticate to GAR. (default: `artifact-writer`) |
1415

1516
## Example Usage
1617

docker-push/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ inputs:
1919
project_id:
2020
description: GCP project_id used to construct the service account.
2121
required: true
22+
service_account_name:
23+
description: Service account used to authenticate to GAR
24+
default: artifact-writer
2225

2326

2427
runs:
@@ -29,7 +32,7 @@ runs:
2932
uses: google-github-actions/auth@3a3c4c57d294ef65efaaee4ff17b22fa88dd3c69 #v1
3033
with:
3134
workload_identity_provider: "projects/${{ inputs.workload_identity_pool_project_number }}/locations/global/workloadIdentityPools/github-actions/providers/github-actions"
32-
service_account: "artifact-writer@${{ inputs.project_id }}.iam.gserviceaccount.com"
35+
service_account: "${{ inputs.service_account_name }}@${{ inputs.project_id }}.iam.gserviceaccount.com"
3336
token_format: access_token
3437
create_credentials_file: false
3538
- name: Log in to GAR

0 commit comments

Comments
 (0)