Skip to content

Commit d23fe26

Browse files
feat: ghcr impl to create images here.
1 parent 6cac84d commit d23fe26

5 files changed

Lines changed: 295 additions & 81 deletions

File tree

.github/workflows/ci.yml

Lines changed: 113 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22

33
on:
44
push:
5-
branches: [main, staging, dev]
5+
branches: ['**']
66
pull_request:
77
branches: [main, staging, dev]
88

@@ -16,15 +16,42 @@ permissions:
1616
jobs:
1717
test-build:
1818
name: Test and Build
19-
if: github.ref != 'refs/heads/dev' || github.event_name == 'pull_request'
19+
if: >-
20+
github.event_name == 'pull_request' ||
21+
github.ref == 'refs/heads/main' ||
22+
github.ref == 'refs/heads/staging'
2023
uses: ./.github/workflows/test-build.yml
2124
secrets: inherit
2225

26+
# Resolve auto-incrementing GHCR tag for non-main branches (<branch>-0.0.N)
27+
resolve-ghcr-tag:
28+
name: Resolve GHCR Tag
29+
runs-on: ubuntu-latest
30+
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
31+
permissions:
32+
contents: read
33+
packages: read
34+
outputs:
35+
image_tag: ${{ steps.tag.outputs.image_tag }}
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v6
39+
40+
- name: Compute next GHCR tag
41+
id: tag
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
45+
run: |
46+
TAG="$(bash scripts/ci/ghcr-next-branch-tag.sh "${{ github.ref_name }}")"
47+
echo "image_tag=${TAG}" >> "$GITHUB_OUTPUT"
48+
echo "Computed GHCR tag: ${TAG}"
49+
2350
# Detect if this is a version release commit (e.g., "v0.5.24: ...")
2451
detect-version:
2552
name: Detect Version
26-
runs-on: blacksmith-4vcpu-ubuntu-2404
27-
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/dev')
53+
runs-on: ubuntu-latest
54+
if: github.event_name == 'push'
2855
outputs:
2956
version: ${{ steps.extract.outputs.version }}
3057
is_release: ${{ steps.extract.outputs.is_release }}
@@ -46,14 +73,66 @@ jobs:
4673
echo "ℹ️ Not a release commit"
4774
fi
4875
49-
# Dev: build all 3 images for ECR only (no GHCR, no ARM64)
76+
# Non-main branches: build all 3 images for GHCR with auto-increment tag
77+
build-ghcr-branch:
78+
name: Build GHCR Branch Images
79+
needs: [resolve-ghcr-tag]
80+
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: read
84+
packages: write
85+
strategy:
86+
fail-fast: false
87+
matrix:
88+
include:
89+
- dockerfile: ./docker/app.Dockerfile
90+
ghcr_image: ghcr.io/${{ github.repository_owner }}/p2-sim-simstudio
91+
- dockerfile: ./docker/db.Dockerfile
92+
ghcr_image: ghcr.io/${{ github.repository_owner }}/p2-sim-migrations
93+
- dockerfile: ./docker/realtime.Dockerfile
94+
ghcr_image: ghcr.io/${{ github.repository_owner }}/p2-sim-realtime
95+
steps:
96+
- name: Checkout code
97+
uses: actions/checkout@v6
98+
99+
- name: Login to GHCR
100+
uses: docker/login-action@v3
101+
with:
102+
registry: ghcr.io
103+
username: ${{ github.repository_owner }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Set up Docker Buildx
107+
uses: docker/setup-buildx-action@v3
108+
109+
- name: Generate tags
110+
id: meta
111+
run: |
112+
IMAGE_TAG="${{ needs.resolve-ghcr-tag.outputs.image_tag }}"
113+
GHCR_IMAGE="${{ matrix.ghcr_image }}"
114+
echo "tags=${GHCR_IMAGE}:${IMAGE_TAG},${GHCR_IMAGE}:${IMAGE_TAG}-${{ github.sha }}" >> "$GITHUB_OUTPUT"
115+
116+
- name: Build and push
117+
uses: docker/build-push-action@v6
118+
with:
119+
context: .
120+
file: ${{ matrix.dockerfile }}
121+
platforms: linux/amd64
122+
push: true
123+
tags: ${{ steps.meta.outputs.tags }}
124+
provenance: false
125+
sbom: false
126+
127+
# Dev: build all 3 images for ECR only (no ARM64)
50128
build-dev:
51129
name: Build Dev ECR
52130
needs: [detect-version]
53131
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
54-
runs-on: blacksmith-8vcpu-ubuntu-2404
132+
runs-on: ubuntu-latest
55133
permissions:
56134
contents: read
135+
packages: write
57136
id-token: write
58137
strategy:
59138
fail-fast: false
@@ -67,7 +146,7 @@ jobs:
67146
ecr_repo_secret: ECR_REALTIME
68147
steps:
69148
- name: Checkout code
70-
uses: actions/checkout@v4
149+
uses: actions/checkout@v6
71150

72151
- name: Configure AWS credentials
73152
uses: aws-actions/configure-aws-credentials@v4
@@ -86,22 +165,28 @@ jobs:
86165
password: ${{ secrets.DOCKERHUB_TOKEN }}
87166

88167
- name: Set up Docker Buildx
89-
uses: useblacksmith/setup-docker-builder@v1
168+
uses: docker/setup-buildx-action@v3
90169

91170
- name: Resolve ECR repo name
92171
id: ecr-repo
93172
run: echo "name=$ECR_REPO" >> $GITHUB_OUTPUT
94173
env:
95174
ECR_REPO: ${{ matrix.ecr_repo_secret == 'ECR_APP' && secrets.ECR_APP || matrix.ecr_repo_secret == 'ECR_MIGRATIONS' && secrets.ECR_MIGRATIONS || matrix.ecr_repo_secret == 'ECR_REALTIME' && secrets.ECR_REALTIME || '' }}
96175

176+
- name: Generate tags
177+
id: meta
178+
run: |
179+
ECR_IMAGE="${{ steps.login-ecr.outputs.registry }}/${{ steps.ecr-repo.outputs.name }}:dev"
180+
echo "tags=${ECR_IMAGE}" >> "$GITHUB_OUTPUT"
181+
97182
- name: Build and push
98-
uses: useblacksmith/build-push-action@v2
183+
uses: docker/build-push-action@v6
99184
with:
100185
context: .
101186
file: ${{ matrix.dockerfile }}
102187
platforms: linux/amd64
103188
push: true
104-
tags: ${{ steps.login-ecr.outputs.registry }}/${{ steps.ecr-repo.outputs.name }}:dev
189+
tags: ${{ steps.meta.outputs.tags }}
105190
provenance: false
106191
sbom: false
107192

@@ -112,7 +197,7 @@ jobs:
112197
if: >-
113198
github.event_name == 'push' &&
114199
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging')
115-
runs-on: blacksmith-8vcpu-ubuntu-2404
200+
runs-on: ubuntu-latest
116201
permissions:
117202
contents: read
118203
packages: write
@@ -122,13 +207,13 @@ jobs:
122207
matrix:
123208
include:
124209
- dockerfile: ./docker/app.Dockerfile
125-
ghcr_image: ghcr.io/simstudioai/simstudio
210+
ghcr_image: ghcr.io/${{ github.repository_owner }}/p2-sim-simstudio
126211
ecr_repo_secret: ECR_APP
127212
- dockerfile: ./docker/db.Dockerfile
128-
ghcr_image: ghcr.io/simstudioai/migrations
213+
ghcr_image: ghcr.io/${{ github.repository_owner }}/p2-sim-migrations
129214
ecr_repo_secret: ECR_MIGRATIONS
130215
- dockerfile: ./docker/realtime.Dockerfile
131-
ghcr_image: ghcr.io/simstudioai/realtime
216+
ghcr_image: ghcr.io/${{ github.repository_owner }}/p2-sim-realtime
132217
ecr_repo_secret: ECR_REALTIME
133218
steps:
134219
- name: Checkout code
@@ -151,15 +236,14 @@ jobs:
151236
password: ${{ secrets.DOCKERHUB_TOKEN }}
152237

153238
- name: Login to GHCR
154-
if: github.ref == 'refs/heads/main'
155239
uses: docker/login-action@v3
156240
with:
157241
registry: ghcr.io
158242
username: ${{ github.repository_owner }}
159243
password: ${{ secrets.GITHUB_TOKEN }}
160244

161245
- name: Set up Docker Buildx
162-
uses: useblacksmith/setup-docker-builder@v1
246+
uses: docker/setup-buildx-action@v3
163247

164248
- name: Resolve ECR repo name
165249
id: ecr-repo
@@ -199,7 +283,7 @@ jobs:
199283
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
200284
201285
- name: Build and push images
202-
uses: useblacksmith/build-push-action@v2
286+
uses: docker/build-push-action@v6
203287
with:
204288
context: .
205289
file: ${{ matrix.dockerfile }}
@@ -213,7 +297,7 @@ jobs:
213297
build-ghcr-arm64:
214298
name: Build ARM64 (GHCR Only)
215299
needs: [detect-version]
216-
runs-on: blacksmith-8vcpu-ubuntu-2404-arm
300+
runs-on: ubuntu-24.04-arm
217301
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
218302
permissions:
219303
contents: read
@@ -223,11 +307,11 @@ jobs:
223307
matrix:
224308
include:
225309
- dockerfile: ./docker/app.Dockerfile
226-
image: ghcr.io/simstudioai/simstudio
310+
image: ghcr.io/${{ github.repository_owner }}/p2-sim-simstudio
227311
- dockerfile: ./docker/db.Dockerfile
228-
image: ghcr.io/simstudioai/migrations
312+
image: ghcr.io/${{ github.repository_owner }}/p2-sim-migrations
229313
- dockerfile: ./docker/realtime.Dockerfile
230-
image: ghcr.io/simstudioai/realtime
314+
image: ghcr.io/${{ github.repository_owner }}/p2-sim-realtime
231315

232316
steps:
233317
- name: Checkout code
@@ -241,7 +325,7 @@ jobs:
241325
password: ${{ secrets.GITHUB_TOKEN }}
242326

243327
- name: Set up Docker Buildx
244-
uses: useblacksmith/setup-docker-builder@v1
328+
uses: docker/setup-buildx-action@v3
245329

246330
- name: Generate ARM64 tags
247331
id: meta
@@ -259,7 +343,7 @@ jobs:
259343
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
260344
261345
- name: Build and push ARM64 to GHCR
262-
uses: useblacksmith/build-push-action@v2
346+
uses: docker/build-push-action@v6
263347
with:
264348
context: .
265349
file: ${{ matrix.dockerfile }}
@@ -272,17 +356,17 @@ jobs:
272356
# Create GHCR multi-arch manifests (only for main, after both builds)
273357
create-ghcr-manifests:
274358
name: Create GHCR Manifests
275-
runs-on: blacksmith-2vcpu-ubuntu-2404
359+
runs-on: ubuntu-latest
276360
needs: [build-amd64, build-ghcr-arm64, detect-version]
277361
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
278362
permissions:
279363
packages: write
280364
strategy:
281365
matrix:
282366
include:
283-
- image: ghcr.io/simstudioai/simstudio
284-
- image: ghcr.io/simstudioai/migrations
285-
- image: ghcr.io/simstudioai/realtime
367+
- image: ghcr.io/${{ github.repository_owner }}/p2-sim-simstudio
368+
- image: ghcr.io/${{ github.repository_owner }}/p2-sim-migrations
369+
- image: ghcr.io/${{ github.repository_owner }}/p2-sim-realtime
286370

287371
steps:
288372
- name: Login to GHCR
@@ -329,7 +413,7 @@ jobs:
329413
# Check if docs changed
330414
check-docs-changes:
331415
name: Check Docs Changes
332-
runs-on: blacksmith-4vcpu-ubuntu-2404
416+
runs-on: ubuntu-latest
333417
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
334418
outputs:
335419
docs_changed: ${{ steps.filter.outputs.docs }}
@@ -357,7 +441,7 @@ jobs:
357441
# Create GitHub Release (only for version commits on main, after all builds complete)
358442
create-release:
359443
name: Create GitHub Release
360-
runs-on: blacksmith-4vcpu-ubuntu-2404
444+
runs-on: ubuntu-latest
361445
needs: [create-ghcr-manifests, detect-version]
362446
if: needs.detect-version.outputs.is_release == 'true'
363447
permissions:

0 commit comments

Comments
 (0)