Skip to content

Commit 2f95b01

Browse files
committed
ci: Add workflow to build and push docker image
1 parent 6a04d89 commit 2f95b01

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

.github/workflows/docker.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Build and Push Appchain-Agent Docker Image
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- ".github/workflows/docker.yml"
12+
tags:
13+
- "v*"
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
jobs:
20+
build-push-docker-image:
21+
runs-on: ubuntu-latest
22+
23+
env:
24+
APPCHAIN_REF: main
25+
APPCHAIN_REPO: ${{ github.repository_owner }}/appchain
26+
IMAGE: ghcr.io/${{ github.repository_owner }}/appchain-agent
27+
IMAGE_TEST: zkn/appchain-agent
28+
29+
steps:
30+
- name: Checkout appchain-agent repository
31+
uses: actions/checkout@v4
32+
with:
33+
path: appchain-agent
34+
35+
- name: Checkout appchain repository
36+
uses: actions/checkout@v4
37+
with:
38+
path: appchain
39+
ref: ${{ env.APPCHAIN_REF }}
40+
repository: ${{ env.APPCHAIN_REPO }}
41+
ssh-key: ${{ secrets.APPCHAIN_DEPLOY_KEY }}
42+
43+
- name: Set up QEMU
44+
uses: docker/setup-qemu-action@v3
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Log in to GitHub Container Registry
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.repository_owner }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Docker meta
57+
id: meta
58+
uses: docker/metadata-action@v5
59+
with:
60+
images: |
61+
${{ env.IMAGE }}
62+
tags: |
63+
type=ref,event=branch
64+
type=ref,event=pr
65+
type=semver,pattern={{version}}
66+
type=semver,pattern={{major}}.{{minor}}
67+
type=raw,value=latest,enable={{is_default_branch}}
68+
type=sha
69+
70+
# https://docs.docker.com/build/ci/github-actions/reproducible-builds/
71+
- name: Set source build date from git commit timestamp
72+
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
73+
74+
- name: Build and export to Docker
75+
uses: docker/build-push-action@v6
76+
env:
77+
DOCKER_BUILD_SUMMARY: false
78+
with:
79+
build-contexts: |
80+
context-appchain=./appchain
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max
83+
context: ./appchain-agent
84+
tags: ${{ env.IMAGE_TEST }}:test
85+
load: true
86+
87+
- name: Test docker image
88+
run: docker run --rm ${{ env.IMAGE_TEST }}:test pnpm run agent --help
89+
90+
- name: Docker build and push
91+
uses: docker/build-push-action@v6
92+
with:
93+
build-contexts: |
94+
context-appchain=./appchain
95+
context: ./appchain-agent
96+
tags: ${{ steps.meta.outputs.tags }}
97+
labels: ${{ steps.meta.outputs.labels }}
98+
platforms: linux/amd64
99+
push: ${{ github.event_name != 'pull_request' }}
100+
101+
- name: List docker images
102+
run: docker images

0 commit comments

Comments
 (0)