Skip to content

Commit b88d833

Browse files
authored
Merge pull request #429 from remsky/pr-420
Pr 420
2 parents 311ee64 + 0ae1c33 commit b88d833

2 files changed

Lines changed: 154 additions & 29 deletions

File tree

.github/workflows/release.yml

Lines changed: 101 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ name: Create Release and Publish Docker Images
33
on:
44
push:
55
branches:
6-
- release # Trigger when commits are pushed to the release branch (e.g., after merging master)
6+
- release # Auto-trigger only on release branch
77
paths-ignore:
88
- '**.md'
99
- 'docs/**'
10+
workflow_dispatch: # Manual trigger - explicitly specify branch
11+
inputs:
12+
branch_name:
13+
description: 'Branch to build from (required)'
14+
required: true
15+
type: string
1016

1117
jobs:
1218
prepare-release:
@@ -22,22 +28,49 @@ jobs:
2228
id: get-version
2329
run: |
2430
VERSION_PLAIN=$(cat VERSION)
25-
echo "version=${VERSION_PLAIN}" >> $GITHUB_OUTPUT
26-
echo "version_tag=v${VERSION_PLAIN}" >> $GITHUB_OUTPUT # Add 'v' prefix for tag
31+
32+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
33+
BRANCH_NAME="${{ inputs.branch_name }}"
34+
else
35+
BRANCH_NAME="${{ github.ref_name }}"
36+
fi
37+
38+
if [[ "$BRANCH_NAME" == "release" ]]; then
39+
echo "version=${VERSION_PLAIN}" >> $GITHUB_OUTPUT
40+
echo "version_tag=v${VERSION_PLAIN}" >> $GITHUB_OUTPUT
41+
else
42+
SAFE_BRANCH=$(echo "$BRANCH_NAME" | tr '/' '-' | tr '[:upper:]' '[:lower:]')
43+
echo "version=${VERSION_PLAIN}-${SAFE_BRANCH}" >> $GITHUB_OUTPUT
44+
echo "version_tag=v${VERSION_PLAIN}-${SAFE_BRANCH}" >> $GITHUB_OUTPUT
45+
fi
2746
2847
build-images:
2948
needs: prepare-release
30-
runs-on: ubuntu-latest
3149
permissions:
32-
packages: write # Needed to push images to GHCR
50+
packages: write
3351
env:
3452
DOCKER_BUILDKIT: 1
3553
BUILDKIT_STEP_LOG_MAX_SIZE: 10485760
36-
# These environment variables will override the defaults within docker-bake.hcl
37-
VERSION: ${{ needs.prepare-release.outputs.version_tag }} # Use tag version (vX.Y.Z) for bake
38-
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }} # Override with GitHub Action Environment Variable
54+
VERSION: ${{ needs.prepare-release.outputs.version_tag }}
55+
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }}
3956
OWNER: ${{ vars.OWNER || 'remsky' }}
4057
REPO: ${{ vars.REPO || 'kokoro-fastapi' }}
58+
strategy:
59+
matrix:
60+
include:
61+
- build_target: "cpu"
62+
platform: "linux/amd64"
63+
runs_on: "ubuntu-latest"
64+
- build_target: "gpu"
65+
platform: "linux/amd64"
66+
runs_on: "ubuntu-latest"
67+
- build_target: "cpu"
68+
platform: "linux/arm64"
69+
runs_on: "ubuntu-24.04-arm"
70+
- build_target: "gpu"
71+
platform: "linux/arm64"
72+
runs_on: "ubuntu-24.04-arm"
73+
runs-on: ${{ matrix.runs_on }}
4174
steps:
4275
- name: Checkout repository
4376
uses: actions/checkout@v4
@@ -48,7 +81,6 @@ jobs:
4881
run: |
4982
TAG_NAME="${{ needs.prepare-release.outputs.version_tag }}"
5083
echo "Checking for existing tag: $TAG_NAME"
51-
# Fetch tags explicitly just in case checkout didn't get them all
5284
git fetch --tags
5385
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
5486
echo "::error::Tag $TAG_NAME already exists. Please increment the version in the VERSION file."
@@ -57,7 +89,7 @@ jobs:
5789
echo "Tag $TAG_NAME does not exist. Proceeding with release."
5890
fi
5991
60-
- name: Free disk space # Optional: Keep as needed for large builds
92+
- name: Free disk space
6193
run: |
6294
echo "Listing current disk space"
6395
df -h
@@ -67,9 +99,6 @@ jobs:
6799
echo "Disk space after cleanup"
68100
df -h
69101
70-
- name: Set up QEMU
71-
uses: docker/setup-qemu-action@v3 # Use v3
72-
73102
- name: Set up Docker Buildx
74103
uses: docker/setup-buildx-action@v3 # Use v3
75104
with:
@@ -84,30 +113,77 @@ jobs:
84113
username: ${{ github.actor }}
85114
password: ${{ secrets.GITHUB_TOKEN }}
86115

87-
- name: Build and push images using Docker Bake
116+
- name: Build and push single-platform image
88117
run: |
89-
echo "Building and pushing images for version ${{ needs.prepare-release.outputs.version_tag }}"
90-
# The VERSION env var above sets the tag for the bake file targets
91-
docker buildx bake --push
118+
PLATFORM="${{ matrix.platform }}"
119+
BUILD_TARGET="${{ matrix.build_target }}"
120+
VERSION_TAG="${{ needs.prepare-release.outputs.version_tag }}"
121+
122+
echo "Building ${PLATFORM} image for ${BUILD_TARGET} version ${VERSION_TAG}"
123+
124+
TARGET="${BUILD_TARGET}-$(echo ${PLATFORM} | cut -d'/' -f2)"
125+
echo "Using bake target: $TARGET"
126+
127+
docker buildx bake $TARGET --push --progress=plain
92128
93-
create-release:
129+
create-manifests:
94130
needs: [prepare-release, build-images]
95131
runs-on: ubuntu-latest
96132
permissions:
97-
contents: write # Needed to create releases
133+
packages: write
134+
env:
135+
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }}
136+
OWNER: ${{ vars.OWNER || 'remsky' }}
137+
REPO: ${{ vars.REPO || 'kokoro-fastapi' }}
138+
strategy:
139+
matrix:
140+
build_target: ["cpu", "gpu"]
141+
steps:
142+
- name: Log in to GitHub Container Registry
143+
uses: docker/login-action@v3
144+
with:
145+
registry: ghcr.io
146+
username: ${{ github.actor }}
147+
password: ${{ secrets.GITHUB_TOKEN }}
148+
149+
- name: Create multi-platform manifest
150+
run: |
151+
VERSION_TAG="${{ needs.prepare-release.outputs.version_tag }}"
152+
TARGET="${{ matrix.build_target }}"
153+
REGISTRY="${{ env.REGISTRY }}"
154+
OWNER="${{ env.OWNER }}"
155+
REPO="${{ env.REPO }}"
156+
157+
docker buildx imagetools create -t \
158+
${REGISTRY}/${OWNER}/${REPO}-${TARGET}:${VERSION_TAG} \
159+
${REGISTRY}/${OWNER}/${REPO}-${TARGET}:${VERSION_TAG}-amd64 \
160+
${REGISTRY}/${OWNER}/${REPO}-${TARGET}:${VERSION_TAG}-arm64
161+
162+
if [[ "$VERSION_TAG" != *"-"* ]]; then
163+
docker buildx imagetools create -t \
164+
${REGISTRY}/${OWNER}/${REPO}-${TARGET}:latest \
165+
${REGISTRY}/${OWNER}/${REPO}-${TARGET}:${VERSION_TAG}-amd64 \
166+
${REGISTRY}/${OWNER}/${REPO}-${TARGET}:${VERSION_TAG}-arm64
167+
fi
168+
169+
create-release:
170+
needs: [prepare-release, create-manifests]
171+
runs-on: ubuntu-latest
172+
permissions:
173+
contents: write
98174
steps:
99175
- name: Checkout repository
100176
uses: actions/checkout@v4
101177
with:
102-
fetch-depth: 0 # Fetch all history for release notes generation
178+
fetch-depth: 0
103179

104180
- name: Create GitHub Release
105-
uses: softprops/action-gh-release@v2 # Use v2
181+
uses: softprops/action-gh-release@v2
106182
with:
107-
tag_name: ${{ needs.prepare-release.outputs.version_tag }} # Use vX.Y.Z tag
183+
tag_name: ${{ needs.prepare-release.outputs.version_tag }}
108184
name: Release ${{ needs.prepare-release.outputs.version_tag }}
109-
generate_release_notes: true # Auto-generate release notes
110-
draft: false # Publish immediately
111-
prerelease: false # Mark as a stable release
185+
generate_release_notes: true
186+
draft: false
187+
prerelease: false
112188
env:
113189
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker-bake.hcl

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,41 @@ target "gpu" {
6060
]
6161
}
6262

63-
# Default group to build both CPU and GPU versions
64-
group "default" {
65-
targets = ["cpu", "gpu"]
63+
# Individual platform targets for debugging/testing
64+
target "cpu-amd64" {
65+
inherits = ["_cpu_base"]
66+
platforms = ["linux/amd64"]
67+
tags = [
68+
"${REGISTRY}/${OWNER}/${REPO}-cpu:${VERSION}-amd64",
69+
"${REGISTRY}/${OWNER}/${REPO}-cpu:latest-amd64"
70+
]
71+
}
72+
73+
target "cpu-arm64" {
74+
inherits = ["_cpu_base"]
75+
platforms = ["linux/arm64"]
76+
tags = [
77+
"${REGISTRY}/${OWNER}/${REPO}-cpu:${VERSION}-arm64",
78+
"${REGISTRY}/${OWNER}/${REPO}-cpu:latest-arm64"
79+
]
80+
}
81+
82+
target "gpu-amd64" {
83+
inherits = ["_gpu_base"]
84+
platforms = ["linux/amd64"]
85+
tags = [
86+
"${REGISTRY}/${OWNER}/${REPO}-gpu:${VERSION}-amd64",
87+
"${REGISTRY}/${OWNER}/${REPO}-gpu:latest-amd64"
88+
]
89+
}
90+
91+
target "gpu-arm64" {
92+
inherits = ["_gpu_base"]
93+
platforms = ["linux/arm64"]
94+
tags = [
95+
"${REGISTRY}/${OWNER}/${REPO}-gpu:${VERSION}-arm64",
96+
"${REGISTRY}/${OWNER}/${REPO}-gpu:latest-arm64"
97+
]
6698
}
6799

68100
# Development targets for faster local builds
@@ -80,4 +112,21 @@ target "gpu-dev" {
80112

81113
group "dev" {
82114
targets = ["cpu-dev", "gpu-dev"]
83-
}
115+
}
116+
117+
# Build groups for different use cases
118+
group "cpu-all" {
119+
targets = ["cpu", "cpu-amd64", "cpu-arm64"]
120+
}
121+
122+
group "gpu-all" {
123+
targets = ["gpu", "gpu-amd64", "gpu-arm64"]
124+
}
125+
126+
group "all" {
127+
targets = ["cpu", "gpu"]
128+
}
129+
130+
group "individual-platforms" {
131+
targets = ["cpu-amd64", "cpu-arm64", "gpu-amd64", "gpu-arm64"]
132+
}

0 commit comments

Comments
 (0)