Skip to content

Commit 3993c9f

Browse files
authored
Feat(ci): Gateway build on tag or new commit on main (#183)
* add gateway build * resolve conflicts * udpate to match change from main * remove redundant ifs
1 parent b76d16d commit 3993c9f

File tree

1 file changed

+160
-49
lines changed

1 file changed

+160
-49
lines changed

.github/workflows/build_and_push.yml

Lines changed: 160 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,138 +5,249 @@ on:
55
branches:
66
- main
77
tags:
8-
- 'v[0-9]+.[0-9]+.[0-9]+'
8+
- 'v*'
99

1010
env:
11-
REGISTRY_IMAGE: ghcr.io/lay3rlabs/layer-sdk
11+
REGISTRY_IMAGE_SLAY3R: ghcr.io/lay3rlabs/layer-sdk
12+
REGISTRY_IMAGE_GATEWAY: ghcr.io/lay3rlabs/gateway
1213

1314
jobs:
14-
build_amd64:
15-
name: Build and Push AMD64 Image
15+
build_slay3r_amd64:
16+
name: Build and Push layer-sdk AMD64 Image
1617
runs-on: linux-8-core
17-
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
1818
permissions:
1919
contents: read
2020
packages: write
2121
id-token: write
2222
steps:
23-
- name: Checkout the repo
24-
uses: actions/checkout@v4
23+
- uses: actions/checkout@v4
2524

2625
- name: Set IMAGE_TAG
2726
shell: bash
2827
run: |
29-
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
30-
TAG="${GITHUB_REF_NAME#v}"
31-
IMAGE_TAG="${TAG//[^a-zA-Z0-9_.-]/-}"
32-
elif [[ "${GITHUB_REF_NAME}" == "main" ]]; then
28+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
3329
IMAGE_TAG="latest"
30+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
31+
IMAGE_TAG="${GITHUB_REF_NAME#v}"
32+
IMAGE_TAG="${IMAGE_TAG//[^a-zA-Z0-9_.-]/-}"
3433
else
35-
echo "Not on main branch or tag, skipping build."
34+
echo "Not on main branch or a version tag, skipping build."
3635
exit 1
3736
fi
3837
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
3938
40-
- name: Log in to the Container registry
41-
uses: docker/login-action@v3
39+
- uses: docker/login-action@v3
4240
with:
4341
registry: ghcr.io
4442
username: ${{ github.actor }}
4543
password: ${{ secrets.GITHUB_TOKEN }}
4644

47-
- name: Build and push AMD64 image
45+
- name: Build and push layer-sdk AMD64 image
4846
uses: docker/build-push-action@v5
4947
with:
5048
context: .
5149
file: ./docker/Dockerfile.slay3rd
5250
push: true
53-
tags: ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }}-amd64
51+
tags: ${{ env.REGISTRY_IMAGE_SLAY3R }}:${{ env.IMAGE_TAG }}-amd64
5452
platforms: linux/amd64
5553
provenance: false
5654

57-
build_arm64:
58-
name: Build and Push ARM64 Image
55+
build_slay3r_arm64:
56+
name: Build and Push layer-sdk ARM64 Image
5957
runs-on: arm64-builder
60-
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
6158
permissions:
6259
contents: read
6360
packages: write
6461
id-token: write
6562
steps:
66-
- name: Checkout the repo
67-
uses: actions/checkout@v4
63+
- uses: actions/checkout@v4
6864

6965
- name: Set IMAGE_TAG
7066
shell: bash
7167
run: |
72-
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
73-
TAG="${GITHUB_REF_NAME#v}"
74-
IMAGE_TAG="${TAG//[^a-zA-Z0-9_.-]/-}"
75-
elif [[ "${GITHUB_REF_NAME}" == "main" ]]; then
68+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
7669
IMAGE_TAG="latest"
70+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
71+
IMAGE_TAG="${GITHUB_REF_NAME#v}"
72+
IMAGE_TAG="${IMAGE_TAG//[^a-zA-Z0-9_.-]/-}"
7773
else
78-
echo "Not on main branch or tag, skipping build."
74+
echo "Not on main branch or a version tag, skipping build."
7975
exit 1
8076
fi
8177
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
8278
83-
- name: Log in to the Container registry
84-
uses: docker/login-action@v3
79+
- uses: docker/login-action@v3
8580
with:
8681
registry: ghcr.io
8782
username: ${{ github.actor }}
8883
password: ${{ secrets.GITHUB_TOKEN }}
8984

90-
- name: Build and push ARM64 image
85+
- name: Build and push layer-sdk ARM64 image
9186
uses: docker/build-push-action@v5
9287
with:
9388
context: .
9489
file: ./docker/Dockerfile.slay3rd
9590
push: true
96-
tags: ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }}-arm64
91+
tags: ${{ env.REGISTRY_IMAGE_SLAY3R }}:${{ env.IMAGE_TAG }}-arm64
9792
platforms: linux/arm64
9893
provenance: false
9994

100-
create_manifest:
101-
name: Create and Push Multi-Arch Manifest
95+
build_gateway_amd64:
96+
name: Build and Push Gateway AMD64 Image
97+
runs-on: linux-8-core
98+
permissions:
99+
contents: read
100+
packages: write
101+
id-token: write
102+
steps:
103+
- uses: actions/checkout@v4
104+
105+
- name: Set IMAGE_TAG
106+
shell: bash
107+
run: |
108+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
109+
IMAGE_TAG="latest"
110+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
111+
IMAGE_TAG="${GITHUB_REF_NAME#v}"
112+
IMAGE_TAG="${IMAGE_TAG//[^a-zA-Z0-9_.-]/-}"
113+
else
114+
echo "Not on main branch or a version tag, skipping build."
115+
exit 1
116+
fi
117+
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
118+
119+
- uses: docker/login-action@v3
120+
with:
121+
registry: ghcr.io
122+
username: ${{ github.actor }}
123+
password: ${{ secrets.GITHUB_TOKEN }}
124+
125+
- name: Build and push Gateway AMD64 image
126+
uses: docker/build-push-action@v5
127+
with:
128+
context: .
129+
file: ./docker/Dockerfile.gateway
130+
push: true
131+
tags: ${{ env.REGISTRY_IMAGE_GATEWAY }}:${{ env.IMAGE_TAG }}-amd64
132+
platforms: linux/amd64
133+
provenance: false
134+
135+
build_gateway_arm64:
136+
name: Build and Push Gateway ARM64 Image
137+
runs-on: arm64-builder
138+
permissions:
139+
contents: read
140+
packages: write
141+
id-token: write
142+
steps:
143+
- uses: actions/checkout@v4
144+
145+
- name: Set IMAGE_TAG
146+
shell: bash
147+
run: |
148+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
149+
IMAGE_TAG="latest"
150+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
151+
IMAGE_TAG="${GITHUB_REF_NAME#v}"
152+
IMAGE_TAG="${IMAGE_TAG//[^a-zA-Z0-9_.-]/-}"
153+
else
154+
echo "Not on main branch or a version tag, skipping build."
155+
exit 1
156+
fi
157+
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
158+
159+
- uses: docker/login-action@v3
160+
with:
161+
registry: ghcr.io
162+
username: ${{ github.actor }}
163+
password: ${{ secrets.GITHUB_TOKEN }}
164+
165+
- name: Build and push Gateway ARM64 image
166+
uses: docker/build-push-action@v5
167+
with:
168+
context: .
169+
file: ./docker/Dockerfile.gateway
170+
push: true
171+
tags: ${{ env.REGISTRY_IMAGE_GATEWAY }}:${{ env.IMAGE_TAG }}-arm64
172+
platforms: linux/arm64
173+
provenance: false
174+
175+
create_manifest_slay3r:
176+
name: Create and Push layer-sdk Multi-Arch Manifest
177+
runs-on: ubuntu-latest
178+
needs: [build_slay3r_amd64, build_slay3r_arm64]
179+
permissions:
180+
contents: read
181+
packages: write
182+
id-token: write
183+
steps:
184+
- uses: actions/checkout@v4
185+
186+
- name: Set IMAGE_TAG
187+
shell: bash
188+
run: |
189+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
190+
IMAGE_TAG="latest"
191+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
192+
IMAGE_TAG="${GITHUB_REF_NAME#v}"
193+
IMAGE_TAG="${IMAGE_TAG//[^a-zA-Z0-9_.-]/-}"
194+
else
195+
echo "Not on main branch or a version tag, skipping manifest creation."
196+
exit 1
197+
fi
198+
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
199+
200+
- uses: docker/setup-buildx-action@v3
201+
202+
- uses: docker/login-action@v3
203+
with:
204+
registry: ghcr.io
205+
username: ${{ github.actor }}
206+
password: ${{ secrets.GITHUB_TOKEN }}
207+
208+
- name: Create and push SLAY3R multi-arch manifest
209+
run: |
210+
docker buildx imagetools create \
211+
--tag ${{ env.REGISTRY_IMAGE_SLAY3R }}:${{ env.IMAGE_TAG }} \
212+
${{ env.REGISTRY_IMAGE_SLAY3R }}:${{ env.IMAGE_TAG }}-amd64 \
213+
${{ env.REGISTRY_IMAGE_SLAY3R }}:${{ env.IMAGE_TAG }}-arm64
214+
215+
create_manifest_gateway:
216+
name: Create and Push Gateway Multi-Arch Manifest
102217
runs-on: ubuntu-latest
103-
needs: [build_amd64, build_arm64]
104-
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
218+
needs: [build_gateway_amd64, build_gateway_arm64]
105219
permissions:
106220
contents: read
107221
packages: write
108222
id-token: write
109223
steps:
110-
- name: Checkout the repo
111-
uses: actions/checkout@v4
224+
- uses: actions/checkout@v4
112225

113226
- name: Set IMAGE_TAG
114227
shell: bash
115228
run: |
116-
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
117-
TAG="${GITHUB_REF_NAME#v}"
118-
IMAGE_TAG="${TAG//[^a-zA-Z0-9_.-]/-}"
119-
elif [[ "${GITHUB_REF_NAME}" == "main" ]]; then
229+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
120230
IMAGE_TAG="latest"
231+
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
232+
IMAGE_TAG="${GITHUB_REF_NAME#v}"
233+
IMAGE_TAG="${IMAGE_TAG//[^a-zA-Z0-9_.-]/-}"
121234
else
122-
echo "Not on main branch or tag, skipping manifest creation."
235+
echo "Not on main branch or a version tag, skipping manifest creation."
123236
exit 1
124237
fi
125238
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
126239
127-
- name: Set up Docker Buildx
128-
uses: docker/setup-buildx-action@v3
240+
- uses: docker/setup-buildx-action@v3
129241

130-
- name: Log in to the Container registry
131-
uses: docker/login-action@v3
242+
- uses: docker/login-action@v3
132243
with:
133244
registry: ghcr.io
134245
username: ${{ github.actor }}
135246
password: ${{ secrets.GITHUB_TOKEN }}
136247

137-
- name: Create and push multi-arch manifest
248+
- name: Create and push Gateway multi-arch manifest
138249
run: |
139250
docker buildx imagetools create \
140-
--tag ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }} \
141-
${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }}-amd64 \
142-
${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }}-arm64
251+
--tag ${{ env.REGISTRY_IMAGE_GATEWAY }}:${{ env.IMAGE_TAG }} \
252+
${{ env.REGISTRY_IMAGE_GATEWAY }}:${{ env.IMAGE_TAG }}-amd64 \
253+
${{ env.REGISTRY_IMAGE_GATEWAY }}:${{ env.IMAGE_TAG }}-arm64

0 commit comments

Comments
 (0)