Skip to content

Commit a27ecf5

Browse files
committed
ci: Add reusable image build workflow
1 parent 0e278c5 commit a27ecf5

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
product-name:
5+
required: true
6+
type: string
7+
sdp-version:
8+
required: true
9+
type: string
10+
secrets:
11+
harbor-robot-secret:
12+
description: The secret for the Harbor robot user used to push images and manifest
13+
required: true
14+
slack-token:
15+
description: The Slack token used to post failure notifications
16+
required: true
17+
18+
jobs:
19+
generate_matrix:
20+
name: Generate Version List
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
24+
with:
25+
persist-credentials: false
26+
- id: shard
27+
uses: stackabletech/actions/shard@320eae677555385b3d40e1c3a81d9263b72742e4 # 0.6.0
28+
with:
29+
product-name: ${{ inputs.product-name }}
30+
outputs:
31+
versions: ${{ steps.shard.outputs.versions }}
32+
33+
build:
34+
name: Build/Publish ${{ matrix.versions }}-${{ matrix.runner.arch }} Image
35+
needs: [generate_matrix]
36+
permissions:
37+
id-token: write
38+
runs-on: ${{ matrix.runner.name }}
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
runner:
43+
- {name: "ubuntu-latest", arch: "amd64"}
44+
- {name: "ubicloud-standard-8-arm", arch: "arm64"}
45+
versions: ${{ fromJson(needs.generate_matrix.outputs.versions) }}
46+
steps:
47+
- name: Checkout Repository
48+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
49+
with:
50+
persist-credentials: false
51+
52+
- name: Free Disk Space
53+
uses: stackabletech/actions/free-disk-space@320eae677555385b3d40e1c3a81d9263b72742e4 # 0.6.0
54+
55+
- name: Build Product Image
56+
id: build
57+
uses: stackabletech/actions/build-product-image@320eae677555385b3d40e1c3a81d9263b72742e4 # 0.6.0
58+
with:
59+
product-name: ${{ inputs.product-name }}
60+
product-version: ${{ matrix.versions }}
61+
sdp-version: ${{ inputs.sdp-version }}
62+
63+
- name: Publish Container Image on oci.stackable.tech
64+
uses: stackabletech/actions/publish-image@320eae677555385b3d40e1c3a81d9263b72742e4 # 0.6.0
65+
with:
66+
image-registry-uri: oci.stackable.tech
67+
image-registry-username: robot$sdp+github-action-build
68+
image-registry-password: ${{ secrets.harbor-robot-secret }}
69+
image-repository: sdp/${{ inputs.product-name }}
70+
image-manifest-tag: ${{ steps.build.outputs.image-manifest-tag }}
71+
source-image-uri: localhost/${{ inputs.product-name }}:${{ steps.build.outputs.image-manifest-tag }}
72+
73+
publish_manifests:
74+
name: Build/Publish ${{ matrix.versions }} Manifests
75+
needs: [generate_matrix, build]
76+
permissions:
77+
id-token: write
78+
runs-on: ubuntu-latest
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
versions: ${{ fromJson(needs.generate_matrix.outputs.versions) }}
83+
steps:
84+
- name: Checkout Repository
85+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
86+
with:
87+
persist-credentials: false
88+
89+
- name: Publish and Sign Image Index Manifest to oci.stackable.tech
90+
uses: stackabletech/actions/publish-index-manifest@320eae677555385b3d40e1c3a81d9263b72742e4 # 0.6.0
91+
with:
92+
image-registry-uri: oci.stackable.tech
93+
image-registry-username: robot$sdp+github-action-build
94+
image-registry-password: ${{ secrets.harbor-robot-secret }}
95+
image-repository: sdp/${{ inputs.product-name }}
96+
image-index-manifest-tag: ${{ matrix.versions }}-stackable${{ inputs.sdp-version }}
97+
98+
notify:
99+
name: Failure Notification
100+
needs: [generate_matrix, build, publish_manifests]
101+
runs-on: ubuntu-latest
102+
if: failure()
103+
steps:
104+
- uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0
105+
with:
106+
channel-id: "C07UG6JH44F" # notifications-container-images
107+
payload: |
108+
{
109+
"text": "*${{ github.workflow }}* failed (attempt ${{ github.run_attempt }})",
110+
"attachments": [
111+
{
112+
"pretext": "See the details below for a summary of which job(s) failed.",
113+
"color": "#aa0000",
114+
"fields": [
115+
{
116+
"title": "Generate Version List",
117+
"short": true,
118+
"value": "${{ needs.generate_matrix.result }}"
119+
},
120+
{
121+
"title": "Build/Publish Image",
122+
"short": true,
123+
"value": "${{ needs.build.result }}"
124+
},
125+
{
126+
"title": "Build/Publish Manifests",
127+
"short": true,
128+
"value": "${{ needs.publish_manifests.result }}"
129+
}
130+
],
131+
"actions": [
132+
{
133+
"type": "button",
134+
"text": "Go to workflow run",
135+
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}"
136+
}
137+
]
138+
}
139+
]
140+
}
141+
env:
142+
SLACK_BOT_TOKEN: ${{ secrets.slack-token }}

0 commit comments

Comments
 (0)