Skip to content

Commit f434160

Browse files
committed
Workflow to build docker images
1 parent 34e9c9c commit f434160

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Docker Images CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
ORG: trypromptly
10+
IMAGE_NAME_API: "llmstack-api"
11+
IMAGE_NAME_APP: "llmstack-app"
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
permissions:
18+
contents: read
19+
packages: write
20+
# This is used to complete the identity challenge
21+
# with sigstore/fulcio when running outside of PRs.
22+
id-token: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
28+
# Install the cosign tool except on PR
29+
# https://github.com/sigstore/cosign-installer
30+
- name: Install cosign
31+
if: github.event_name != 'pull_request'
32+
uses: sigstore/[email protected]
33+
with:
34+
cosign-release: "v2.1.1"
35+
36+
# Setup QEMU for cross compilation
37+
- name: Set up QEMU
38+
uses: docker/setup-qemu-action@v2
39+
40+
# Setup Docker Buildx
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v2
43+
44+
- name: Setup Node
45+
uses: actions/setup-node@v3
46+
with:
47+
node-version: 20
48+
cache: "npm"
49+
cache-dependency-path: "llmstack/llmstack/client/package-lock.json"
50+
51+
# Login against a Docker registry except on PR
52+
# https://github.com/docker/login-action
53+
- name: Log into registry ${{ env.REGISTRY }}
54+
if: github.event_name != 'pull_request'
55+
uses: docker/[email protected]
56+
with:
57+
registry: ${{ env.REGISTRY }}
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
# Extract metadata (tags, labels) for Docker
62+
# https://github.com/docker/metadata-action
63+
- name: Extract Docker metadata for API
64+
id: meta-api
65+
uses: docker/metadata-action@v4
66+
with:
67+
images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME_API }}
68+
69+
- name: Extract Docker metadata for app
70+
id: meta-app
71+
uses: docker/metadata-action@v4
72+
with:
73+
images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME_APP }}
74+
75+
# Build client
76+
- name: Build client
77+
run: |
78+
cd llmstack/client
79+
npm install
80+
npm run build
81+
82+
# Build and push Docker image with Buildx (don't push on PR)
83+
# https://github.com/docker/build-push-action
84+
- name: Build and push LLMStack API Docker image
85+
id: build-and-push-api
86+
uses: docker/build-push-action@v4
87+
with:
88+
context: .
89+
push: ${{ github.event_name != 'pull_request' }}
90+
tags: ${{ steps.meta-api.outputs.tags }}
91+
labels: ${{ steps.meta-api.outputs.labels }}
92+
cache-from: type=gha
93+
cache-to: type=gha,mode=max
94+
file: docker/api/Dockerfile
95+
platforms: linux/amd64,linux/arm64
96+
97+
- name: Build and push LLMStack app Docker image
98+
id: build-and-push-app
99+
uses: docker/build-push-action@v4
100+
with:
101+
context: app
102+
push: ${{ github.event_name != 'pull_request' }}
103+
tags: ${{ steps.meta-app.outputs.tags }}
104+
labels: ${{ steps.meta-app.outputs.labels }}
105+
cache-from: type=gha
106+
cache-to: type=gha,mode=max
107+
file: docker/app/Dockerfile
108+
platforms: linux/amd64,linux/arm64
109+
build-args: |
110+
REGISTRY=${{ env.REGISTRY }}/${{ env.ORG }}/
111+
TAG=main
112+
113+
- name: Sign the published LLMStack API Docker image
114+
if: ${{ github.event_name != 'pull_request' }}
115+
env:
116+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
117+
TAGS: ${{ steps.meta-api.outputs.tags }}
118+
DIGEST: ${{ steps.build-and-push-api.outputs.digest }}
119+
# This step uses the identity token to provision an ephemeral certificate
120+
# against the sigstore community Fulcio instance.
121+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
122+
123+
- name: Sign the published LLMStack app Docker image
124+
if: ${{ github.event_name != 'pull_request' }}
125+
env:
126+
TAGS: ${{ steps.meta-app.outputs.tags }}
127+
DIGEST: ${{ steps.build-and-push-app.outputs.digest }}
128+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)