Skip to content

Commit ff1cdf8

Browse files
committed
Add reusable push-to-gar-docker-multiarch workflow
1 parent 98f4728 commit ff1cdf8

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Multi-platform Docker image push to Google Artifact Registry
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
platforms:
7+
default: "['amd64']"
8+
type: string
9+
image_name:
10+
required: true
11+
type: string
12+
registry:
13+
description: |
14+
Google Artifact Registry to store docker images in.
15+
default: "us-docker.pkg.dev"
16+
type: string
17+
tags:
18+
type: string
19+
description: |
20+
List of Docker images to be pushed.
21+
required: true
22+
context:
23+
description: |
24+
Path to the Docker build context.
25+
default: "."
26+
type: string
27+
environment:
28+
description: |
29+
Environment for pushing artifacts (can be either dev or prod).
30+
default: dev
31+
type: string
32+
build-args:
33+
type: string
34+
description: |
35+
List of arguments necessary for the Docker image to be built.
36+
default: ""
37+
file:
38+
type: string
39+
description: |
40+
The dockerfile to use.
41+
required: false
42+
cache-from:
43+
type: string
44+
description: |
45+
Where cache should be fetched from
46+
required: false
47+
default: "type=gha"
48+
cache-to:
49+
type: string
50+
description: |
51+
Where cache should be stored to
52+
required: false
53+
default: "type=gha,mode=max"
54+
ssh:
55+
type: string
56+
description: |
57+
List of SSH agent socket or keys to expose to the build
58+
59+
permissions:
60+
contents: read
61+
id-token: write
62+
63+
env:
64+
platform_env: ${{ inputs.platforms }}
65+
66+
jobs:
67+
build-multi-arch:
68+
outputs:
69+
full_image_name: ${{ steps.build-multiarch.outputs.full_image_name }}
70+
strategy:
71+
matrix:
72+
os: ${{ fromJson(inputs.platforms ) }}
73+
tag: ${{ fromJson(inputs.tags ) }}
74+
runs-on: ubuntu-${{ matrix.os }}-large
75+
name: build-${{ matrix.os }}-image-for-tag-${{ matrix.tags }}
76+
steps:
77+
- name: Checkout
78+
env:
79+
action_repo: ${{ github.action_repository }}
80+
action_ref: ${{ github.action_ref }}
81+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
82+
with:
83+
repository: ${{ env.action_repo }}
84+
ref: ${{ env.action_ref }}
85+
- name: Checkout
86+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
87+
with:
88+
repository: grafana/shared-workflows
89+
ref: multiarch-docker-builds-using-sh-runners
90+
path: shared-workflows
91+
- name: Build multi-arch
92+
id: build-multiarch
93+
uses: ./shared-workflows/actions/build-and-push-image-digest
94+
with:
95+
platform: "linux/${{ matrix.os }}"
96+
image_name: ${{ inputs.image_name }}
97+
tags: ${{ matrix.tag }}
98+
context: ${{ inputs.context }}
99+
build-args: ${{ inputs.build-args }}
100+
cache-from: ${{ inputs.cache-from }}
101+
cache-to: ${{ inputs.cache-to }}
102+
file: ${{ inputs.file }}
103+
ssh: ${{ inputs.ssh }}
104+
push-manifest:
105+
strategy:
106+
matrix:
107+
tag: ${{ fromJson(inputs.tags ) }}
108+
needs: [build-multi-arch]
109+
name: push-manifest
110+
runs-on: ubuntu-x64-small
111+
steps:
112+
- name: Checkout
113+
env:
114+
action_repo: ${{ github.action_repository }}
115+
action_ref: ${{ github.action_ref }}
116+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
117+
with:
118+
repository: ${{ env.action_repo }}
119+
ref: ${{ env.action_ref }}
120+
- name: Checkout
121+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
122+
with:
123+
repository: grafana/shared-workflows
124+
ref: multiarch-docker-builds-using-sh-runners
125+
path: shared-workflows
126+
- name: Create and push image manifests
127+
uses: ./shared-workflows/actions/create-and-push-image-manifests
128+
with:
129+
full-image-name: ${{ needs.build-multi-arch.outputs.full_image_name }}
130+
tag: ${{ matrix.tag }}
131+
environment: ${{ inputs.environment }}

0 commit comments

Comments
 (0)