Skip to content

Commit 6c9fefc

Browse files
committed
Merge Commit 'aba23fe': feat(CI): Add a github action to build the sandbox image and push to GHCR (google-gemini#8670)
2 parents bf1866d + aba23fe commit 6c9fefc

3 files changed

Lines changed: 125 additions & 13 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: 'Build and push sandbox docker'
2+
description: 'Pushes sandbox docker image to container registry'
3+
4+
inputs:
5+
github-actor:
6+
description: 'Github actor'
7+
required: true
8+
github-secret:
9+
description: 'Github secret'
10+
required: true
11+
github-sha:
12+
description: 'Github Commit SHA Hash'
13+
required: true
14+
github-ref-name:
15+
description: 'Github ref name'
16+
required: true
17+
dry-run:
18+
description: 'Whether this is a dry run.'
19+
required: true
20+
type: 'boolean'
21+
22+
runs:
23+
using: 'composite'
24+
steps:
25+
- name: 'Checkout'
26+
uses: 'actions/checkout@v4'
27+
with:
28+
ref: '${{ inputs.github-sha }}'
29+
fetch-depth: 0
30+
- name: 'Install Dependencies'
31+
shell: 'bash'
32+
run: 'npm install'
33+
- name: 'npm build'
34+
shell: 'bash'
35+
run: 'npm run build'
36+
- name: 'Set up Docker Buildx'
37+
uses: 'docker/setup-buildx-action@v3'
38+
- name: 'Log in to GitHub Container Registry'
39+
uses: 'docker/login-action@v3'
40+
with:
41+
registry: 'ghcr.io'
42+
username: '${{ inputs.github-actor }}'
43+
password: '${{ inputs.github-secret }}'
44+
- name: 'determine image tag'
45+
id: 'image_tag'
46+
shell: 'bash'
47+
run: |-
48+
SHELL_TAG_NAME="${{ inputs.github-ref-name }}"
49+
FINAL_TAG="${{ inputs.github-sha }}"
50+
if [[ "$SHELL_TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
51+
echo "Release detected."
52+
FINAL_TAG="${SHELL_TAG_NAME#v}"
53+
else
54+
echo "Development release detected. Using commit SHA as tag."
55+
fi
56+
echo "Determined image tag: $FINAL_TAG"
57+
echo "FINAL_TAG=$FINAL_TAG" >> $GITHUB_OUTPUT
58+
- name: 'build'
59+
id: 'docker_build'
60+
shell: 'bash'
61+
env:
62+
GEMINI_SANDBOX_IMAGE_TAG: '${{ steps.image_tag.outputs.FINAL_TAG }}'
63+
GEMINI_SANDBOX: 'docker'
64+
run: |-
65+
npm run build:sandbox -- \
66+
--image ghcr.io/${{ github.repository}}/sandbox:${{ steps.image_tag.outputs.FINAL_TAG }} \
67+
--output-file final_image_uri.txt
68+
echo "uri=$(cat final_image_uri.txt)" >> $GITHUB_OUTPUT
69+
- name: 'publish'
70+
shell: 'bash'
71+
if: "${{ inputs.dry-run == 'false' }}"
72+
run: |-
73+
docker push "${{ steps.docker_build.outputs.uri }}"
74+
- name: 'Create issue on failure'
75+
if: |-
76+
${{ failure() }}
77+
shell: 'bash'
78+
env:
79+
GITHUB_TOKEN: '${{ inputs.github-secret }}'
80+
DETAILS_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
81+
run: |-
82+
gh issue create \
83+
--title "Docker build failed" \
84+
--body "The docker build failed. See the full run for details: ${DETAILS_URL}" \
85+
--label "kind/bug,release-failure"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Release Sandbox'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: 'The branch, tag, or SHA to release from.'
8+
required: false
9+
type: 'string'
10+
default: 'main'
11+
dry-run:
12+
description: 'Whether this is a dry run.'
13+
required: false
14+
type: 'boolean'
15+
default: true
16+
17+
jobs:
18+
build:
19+
runs-on: 'ubuntu-latest'
20+
steps:
21+
- name: 'Checkout'
22+
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8'
23+
with:
24+
ref: '${{ github.event.inputs.ref || github.sha }}'
25+
fetch-depth: 0
26+
- name: 'Push'
27+
uses: './.github/actions/push-sandbox'
28+
with:
29+
github-actor: '${{ github.actor }}'
30+
github-secret: '${{ secrets.GITHUB_TOKEN }}'
31+
github-sha: '${{ github.event.inputs.ref || github.sha }}'
32+
github-ref-name: '${{github.event.inputs.ref}}'
33+
dry-run: '${{ github.event.inputs.dry-run }}'

scripts/build_sandbox.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ const argv = yargs(hideBin(process.argv))
4141
.option('f', {
4242
alias: 'dockerfile',
4343
type: 'string',
44+
default: 'Dockerfile',
4445
description: 'use <dockerfile> for custom image',
4546
})
4647
.option('i', {
4748
alias: 'image',
4849
type: 'string',
50+
default: cliPkgJson.config.sandboxImageUri,
4951
description: 'use <image> name for custom image',
5052
})
5153
.option('output-file', {
@@ -74,12 +76,10 @@ if (sandboxCommand === 'sandbox-exec') {
7476

7577
console.log(`using ${sandboxCommand} for sandboxing`);
7678

77-
const baseImage = cliPkgJson.config.sandboxImageUri;
78-
const customImage = argv.i;
79-
const baseDockerfile = 'Dockerfile';
80-
const customDockerfile = argv.f;
79+
const image = argv.i;
80+
const dockerFile = argv.f;
8181

82-
if (!baseImage?.length) {
82+
if (!image.length) {
8383
console.warn(
8484
'No default image tag specified in gemini-cli/packages/cli/package.json',
8585
);
@@ -160,7 +160,7 @@ function buildImage(imageName, dockerfile) {
160160
execSync(
161161
`${sandboxCommand} build ${buildCommandArgs} ${
162162
process.env.BUILD_SANDBOX_FLAGS || ''
163-
} --build-arg CLI_VERSION_ARG=${npmPackageVersion} -f "${dockerfile}" -t "${imageName}" .`,
163+
} --build-arg CLI_VERSION_ARG=${npmPackageVersion} -f "${dockerfile}" -t "${finalImageName}" .`,
164164
{ stdio: buildStdout, shell: shellToUse },
165165
);
166166
console.log(`built ${finalImageName}`);
@@ -187,12 +187,6 @@ function buildImage(imageName, dockerfile) {
187187
}
188188
}
189189

190-
if (baseImage && baseDockerfile) {
191-
buildImage(baseImage, baseDockerfile);
192-
}
193-
194-
if (customDockerfile && customImage) {
195-
buildImage(customImage, customDockerfile);
196-
}
190+
buildImage(image, dockerFile);
197191

198192
execSync(`${sandboxCommand} image prune -f`, { stdio: 'ignore' });

0 commit comments

Comments
 (0)