Skip to content

Commit 94a9d39

Browse files
authored
chore: optimize Docker CI for faster builds and multi-architecture support (#349)
* chore: optimize Docker CI workflow for faster builds and multi-architecture support Signed-off-by: liuhy <[email protected]> * chore: optimize Docker CI workflow for faster builds and multi-architecture support Signed-off-by: liuhy <[email protected]> * chore: streamline Docker publishing workflow for scheduled runs Signed-off-by: liuhy <[email protected]> * chore: streamline Docker publishing workflow for scheduled runs Signed-off-by: liuhy <[email protected]> * chore: simplify Rust build cache logic in Docker publish workflow Signed-off-by: liuhy <[email protected]> * chore: simplify Rust build cache logic in Docker publish workflow Signed-off-by: liuhy <[email protected]> * chore: simplify Rust build cache logic in Docker publish workflow Signed-off-by: liuhy <[email protected]> --------- Signed-off-by: liuhy <[email protected]>
1 parent 9866881 commit 94a9d39

File tree

1 file changed

+118
-84
lines changed

1 file changed

+118
-84
lines changed

.github/workflows/docker-publish.yml

Lines changed: 118 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,97 +14,131 @@ on:
1414
required: false
1515
type: boolean
1616
default: false
17+
skip_multiarch:
18+
description: "Skip multi-architecture build for faster CI"
19+
required: false
20+
type: boolean
21+
default: false
1722
push:
1823
branches: [ "main" ]
1924

2025
jobs:
21-
build_and_push_extproc:
26+
# Parallel job for building both images
27+
build_and_push:
2228
runs-on: ubuntu-latest
2329
permissions:
2430
contents: read
2531
packages: write
32+
strategy:
33+
matrix:
34+
image: [extproc, llm-katan]
35+
fail-fast: false # Continue building other images if one fails
2636

2737
steps:
28-
- name: Check out the repo
29-
uses: actions/checkout@v4
30-
31-
- name: Set up Docker Buildx
32-
uses: docker/setup-buildx-action@v3
33-
34-
- name: Set up QEMU
35-
uses: docker/setup-qemu-action@v3
36-
37-
- name: Log in to GitHub Container Registry
38-
uses: docker/login-action@v3
39-
with:
40-
registry: ghcr.io
41-
username: ${{ github.actor }}
42-
password: ${{ secrets.GITHUB_TOKEN }}
43-
44-
- name: Generate date tag for nightly builds
45-
id: date
46-
if: inputs.is_nightly == true
47-
run: echo "date_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
48-
49-
- name: Set lowercase repository owner
50-
run: echo "REPOSITORY_OWNER_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
51-
52-
- name: Build and push extproc Docker image
53-
uses: docker/build-push-action@v5
54-
with:
55-
context: .
56-
file: ./Dockerfile.extproc
57-
platforms: linux/amd64,linux/arm64
58-
push: ${{ github.event_name != 'pull_request' }} # Only push on merge to main, not on PRs
59-
tags: |
60-
${{ inputs.is_nightly == true && format('ghcr.io/{0}/semantic-router/extproc:nightly-{1}', env.REPOSITORY_OWNER_LOWER, steps.date.outputs.date_tag) || format('ghcr.io/{0}/semantic-router/extproc:{1}', env.REPOSITORY_OWNER_LOWER, github.sha) }}
61-
${{ inputs.is_nightly != true && format('ghcr.io/{0}/semantic-router/extproc:latest', env.REPOSITORY_OWNER_LOWER) || '' }}
62-
63-
build_and_push_llm_katan:
64-
runs-on: ubuntu-latest
65-
permissions:
66-
contents: read
67-
packages: write
68-
69-
steps:
70-
- name: Check out the repo
71-
uses: actions/checkout@v4
72-
73-
- name: Set up Docker Buildx
74-
uses: docker/setup-buildx-action@v3
75-
76-
- name: Set up QEMU
77-
uses: docker/setup-qemu-action@v3
78-
79-
- name: Log in to GitHub Container Registry
80-
uses: docker/login-action@v3
81-
with:
82-
registry: ghcr.io
83-
username: ${{ github.actor }}
84-
password: ${{ secrets.GITHUB_TOKEN }}
85-
86-
- name: Generate date tag for nightly builds
87-
id: date
88-
if: inputs.is_nightly == true
89-
run: echo "date_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
90-
91-
- name: Set lowercase repository owner
92-
run: echo "REPOSITORY_OWNER_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
93-
94-
- name: Extract version from pyproject.toml
95-
id: version
96-
run: |
97-
VERSION=$(grep '^version = ' e2e-tests/llm-katan/pyproject.toml | sed 's/version = "\(.*\)"/\1/')
98-
echo "version=$VERSION" >> $GITHUB_OUTPUT
99-
100-
- name: Build and push llm-katan Docker image
101-
uses: docker/build-push-action@v5
102-
with:
103-
context: ./e2e-tests/llm-katan
104-
file: ./e2e-tests/llm-katan/Dockerfile
105-
platforms: linux/amd64,linux/arm64
106-
push: ${{ github.event_name != 'pull_request' }} # Only push on merge to main, not on PRs
107-
tags: |
108-
${{ inputs.is_nightly == true && format('ghcr.io/{0}/semantic-router/llm-katan:nightly-{1}', env.REPOSITORY_OWNER_LOWER, steps.date.outputs.date_tag) || format('ghcr.io/{0}/semantic-router/llm-katan:{1}', env.REPOSITORY_OWNER_LOWER, github.sha) }}
109-
${{ inputs.is_nightly != true && format('ghcr.io/{0}/semantic-router/llm-katan:latest', env.REPOSITORY_OWNER_LOWER) || '' }}
110-
${{ inputs.is_nightly != true && format('ghcr.io/{0}/semantic-router/llm-katan:v{1}', env.REPOSITORY_OWNER_LOWER, steps.version.outputs.version) || '' }}
38+
- name: Check out the repo
39+
uses: actions/checkout@v4
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Set up QEMU (only for multi-arch builds)
45+
if: inputs.skip_multiarch != true
46+
uses: docker/setup-qemu-action@v3
47+
with:
48+
platforms: arm64
49+
50+
- name: Log in to GitHub Container Registry
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.actor }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Generate date tag for nightly builds
58+
id: date
59+
if: inputs.is_nightly == true
60+
run: echo "date_tag=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
61+
62+
- name: Set lowercase repository owner
63+
run: echo "REPOSITORY_OWNER_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
64+
65+
# Rust build cache for extproc - only use GitHub Actions cache for non-PR builds
66+
- name: Cache Rust dependencies (extproc only)
67+
if: matrix.image == 'extproc' && github.event_name != 'pull_request'
68+
uses: actions/cache@v4
69+
with:
70+
path: |
71+
~/.cargo/bin/
72+
~/.cargo/registry/index/
73+
~/.cargo/registry/cache/
74+
~/.cargo/git/db/
75+
candle-binding/target/
76+
key: ${{ runner.os }}-cargo-extproc-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
77+
restore-keys: |
78+
${{ runner.os }}-cargo-extproc-
79+
80+
# Set build context and dockerfile based on matrix
81+
- name: Set build parameters
82+
id: build-params
83+
run: |
84+
if [ "${{ matrix.image }}" = "extproc" ]; then
85+
echo "context=." >> $GITHUB_OUTPUT
86+
echo "dockerfile=./Dockerfile.extproc" >> $GITHUB_OUTPUT
87+
echo "platforms=${{ inputs.skip_multiarch == true && 'linux/amd64' || 'linux/amd64,linux/arm64' }}" >> $GITHUB_OUTPUT
88+
elif [ "${{ matrix.image }}" = "llm-katan" ]; then
89+
echo "context=./e2e-tests/llm-katan" >> $GITHUB_OUTPUT
90+
echo "dockerfile=./e2e-tests/llm-katan/Dockerfile" >> $GITHUB_OUTPUT
91+
echo "platforms=${{ inputs.skip_multiarch == true && 'linux/amd64' || 'linux/amd64,linux/arm64' }}" >> $GITHUB_OUTPUT
92+
fi
93+
94+
# Extract version for llm-katan
95+
- name: Extract version from pyproject.toml
96+
id: version
97+
if: matrix.image == 'llm-katan'
98+
run: |
99+
VERSION=$(grep '^version = ' e2e-tests/llm-katan/pyproject.toml | sed 's/version = "\(.*\)"/\1/')
100+
echo "version=$VERSION" >> $GITHUB_OUTPUT
101+
102+
# Generate tags for extproc
103+
- name: Generate extproc tags
104+
id: extproc-tags
105+
if: matrix.image == 'extproc'
106+
run: |
107+
REPO_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')
108+
if [ "${{ inputs.is_nightly }}" = "true" ]; then
109+
echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/extproc:nightly-${{ steps.date.outputs.date_tag }}" >> $GITHUB_OUTPUT
110+
else
111+
if [ "${{ github.event_name }}" != "pull_request" ]; then
112+
echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/extproc:${{ github.sha }},ghcr.io/${REPO_LOWER}/semantic-router/extproc:latest" >> $GITHUB_OUTPUT
113+
else
114+
echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/extproc:${{ github.sha }}" >> $GITHUB_OUTPUT
115+
fi
116+
fi
117+
118+
# Generate tags for llm-katan
119+
- name: Generate llm-katan tags
120+
id: llm-katan-tags
121+
if: matrix.image == 'llm-katan'
122+
run: |
123+
REPO_LOWER=$(echo $GITHUB_REPOSITORY_OWNER | tr '[:upper:]' '[:lower:]')
124+
if [ "${{ inputs.is_nightly }}" = "true" ]; then
125+
echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:nightly-${{ steps.date.outputs.date_tag }}" >> $GITHUB_OUTPUT
126+
else
127+
if [ "${{ github.event_name }}" != "pull_request" ]; then
128+
echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:${{ github.sha }},ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:latest,ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:v${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT
129+
else
130+
echo "tags=ghcr.io/${REPO_LOWER}/semantic-router/llm-katan:${{ github.sha }}" >> $GITHUB_OUTPUT
131+
fi
132+
fi
133+
134+
- name: Build and push ${{ matrix.image }} Docker image
135+
uses: docker/build-push-action@v5
136+
with:
137+
context: ${{ steps.build-params.outputs.context }}
138+
file: ${{ steps.build-params.outputs.dockerfile }}
139+
platforms: ${{ steps.build-params.outputs.platforms }}
140+
push: ${{ github.event_name != 'pull_request' }}
141+
load: ${{ github.event_name == 'pull_request' }}
142+
tags: ${{ matrix.image == 'extproc' && steps.extproc-tags.outputs.tags || steps.llm-katan-tags.outputs.tags }}
143+
build-args: |
144+
BUILDKIT_INLINE_CACHE=1

0 commit comments

Comments
 (0)