@@ -3,10 +3,16 @@ name: Create Release and Publish Docker Images
33on :
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
1117jobs :
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
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."
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
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 }}
0 commit comments