Skip to content

Commit 6dca827

Browse files
feat(CI): Package docker containers to GHCR for PRs. (#8588)
1 parent d746eb7 commit 6dca827

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: 'Push to docker'
2+
description: 'Builds packages and pushes a docker image to GHCR'
3+
4+
inputs:
5+
github-actor:
6+
description: 'Github actor'
7+
required: true
8+
github-secret:
9+
description: 'Github secret'
10+
required: true
11+
ref-name:
12+
description: 'Github ref name'
13+
required: true
14+
github-sha:
15+
description: 'Github Commit SHA Hash'
16+
required: true
17+
18+
runs:
19+
using: 'composite'
20+
steps:
21+
- name: 'Checkout'
22+
uses: 'actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955' # ratchet:actions/checkout@v4
23+
with:
24+
ref: '${{ inputs.github-sha }}'
25+
fetch-depth: 0
26+
- name: 'Install Dependencies'
27+
shell: 'bash'
28+
run: 'npm install'
29+
- name: 'Set up Docker Buildx'
30+
uses: 'docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435' # ratchet:docker/setup-buildx-action@v3
31+
- name: 'build'
32+
shell: 'bash'
33+
run: 'npm run build'
34+
- name: 'pack @google/gemini-cli'
35+
shell: 'bash'
36+
run: 'npm pack -w @google/gemini-cli --pack-destination ./packages/cli/dist'
37+
- name: 'pack @google/gemini-cli-core'
38+
shell: 'bash'
39+
run: 'npm pack -w @google/gemini-cli-core --pack-destination ./packages/core/dist'
40+
- name: 'Log in to GitHub Container Registry'
41+
uses: 'docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1' # ratchet:docker/login-action@v3
42+
with:
43+
registry: 'ghcr.io'
44+
username: '${{ inputs.github-actor }}'
45+
password: '${{ inputs.github-secret }}'
46+
- name: 'Get branch name'
47+
id: 'branch_name'
48+
shell: 'bash'
49+
run: |
50+
REF_NAME="${{ inputs.ref-name }}"
51+
echo "name=${REF_NAME%/merge}" >> $GITHUB_OUTPUT
52+
- name: 'Build and Push the Docker Image'
53+
uses: 'docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83' # ratchet:docker/build-push-action@v6
54+
with:
55+
context: '.'
56+
file: './Dockerfile'
57+
push: true
58+
provenance: false # avoid pushing 3 images to Aritfact Registry
59+
tags: |
60+
ghcr.io/${{ github.repository }}/cli:${{ steps.branch_name.outputs.name }}
61+
ghcr.io/${{ github.repository }}/cli:${{ inputs.github-sha }}
62+
- name: 'Create issue on failure'
63+
if: |-
64+
${{ failure() }}
65+
shell: 'bash'
66+
env:
67+
GITHUB_TOKEN: '${{ inputs.github-secret }}'
68+
DETAILS_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
69+
run: |-
70+
gh issue create \
71+
--title "Docker build failed" \
72+
--body "The docker build failed. See the full run for details: ${DETAILS_URL}" \
73+
--label "kind/bug,release-failure"

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,25 @@ jobs:
395395
minimum-change-threshold: '1000'
396396
compression: 'none'
397397
clean-script: 'clean'
398+
package_docker:
399+
name: 'Package Docker'
400+
runs-on: 'self-hosted'
401+
402+
permissions:
403+
contents: 'read'
404+
packages: 'write'
405+
406+
if: |-
407+
${{ always() && (github.event.pull_request.head.repo.full_name == github.repository) }}
408+
steps:
409+
- name: 'Checkout'
410+
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5
411+
with:
412+
fetch-depth: 1
413+
- name: 'Push Docker to GHCR'
414+
uses: './.github/actions/push-docker'
415+
with:
416+
github-actor: '${{ github.actor }}'
417+
github-secret: '${{ secrets.GITHUB_TOKEN }}'
418+
ref-name: '${{ github.ref_name }}'
419+
github-sha: '${{ github.sha }}'

0 commit comments

Comments
 (0)