Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 076cef0

Browse files
authored
Merge pull request #168 from stacklok/issue-62-v3
feat: enable image builds for ci
2 parents aad0638 + 07e2bfb commit 076cef0

File tree

9 files changed

+606
-1131
lines changed

9 files changed

+606
-1131
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git
2+
__pycache__
3+
*.pyc
4+
*.pyo
5+
tests/
6+
docs/

.github/workflows/image-build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Attempt to build (but not push) the Docker image on Pull Requests
2+
name: Image build
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- "**.md"
9+
- "docs/**"
10+
- "static/**"
11+
- "LICENSE"
12+
permissions:
13+
contents: read
14+
jobs:
15+
docker-image:
16+
name: Check docker image build
17+
runs-on: codegate-pipeline
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3
23+
- name: Test build on x86
24+
id: docker_build
25+
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v5
26+
with:
27+
context: .
28+
file: ./Dockerfile
29+
platforms: linux/amd64
30+
push: false # Only attempt to build, to verify the Dockerfile is working
31+
load: true
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Post-submit and daily build and publish of the Helm chart and Docker container
2+
# This is a separate workflow than image-build.yml because image-build.yml is
3+
# run in the PR context, and those runs aren't allowed package:write permissions if
4+
# the source is a fork (GitHub errors and invalidates the entire workflow if you try).
5+
6+
name: Publish Docker Image
7+
on:
8+
push:
9+
branches:
10+
- main
11+
schedule:
12+
# Once weekly on fridays at noon
13+
- cron: '00 12 * * 5'
14+
# Allow for manually triggering the workflow
15+
workflow_dispatch:
16+
jobs:
17+
build-image:
18+
name: Build Docker image
19+
runs-on: codegate-pipeline
20+
permissions:
21+
contents: read
22+
packages: write
23+
env:
24+
BASE_REPO: "ghcr.io/stacklok"
25+
CODEGATE_SERVER_IMAGE: "ghcr.io/stacklok/codegate"
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
29+
- name: Set up QEMU for cross-platform builds
30+
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3
33+
- name: Compute version number
34+
id: version-string
35+
run: |
36+
DATE="$(date +%Y%m%d)"
37+
COMMIT="$(git rev-parse --short HEAD)"
38+
echo "tag=0.$DATE.$GITHUB_RUN_NUMBER+ref.$COMMIT" >> "$GITHUB_OUTPUT"
39+
- name: Login to GHCR
40+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
- name: Set container metadata
46+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5
47+
id: docker-metadata
48+
with:
49+
images: ${{ env.CODEGATE_SERVER_IMAGE }}
50+
labels: |
51+
org.opencontainers.image.source=${{ github.repositoryUrl }}
52+
org.opencontainers.image.description="This is a container for the Stacklok Codegate server"
53+
org.opencontainers.image.title="Stacklok Codegate Server"
54+
org.opencontainers.image.vendor="Stacklok Inc."
55+
org.opencontainers.image.version=${{ github.sha }}
56+
flavor: |
57+
latest=true
58+
# Even if tags are floating, it's handy and user-friendly to have a
59+
# matching tag for each build. This way, we can search for the digest
60+
# and verify that it's the same as the digest in the Helm chart.
61+
tags: |
62+
type=raw,value=${{ steps.version-string.outputs.tag }}
63+
- name: Build image
64+
id: image-build
65+
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v5
66+
with:
67+
context: .
68+
platforms: linux/amd64,linux/arm64
69+
push: true
70+
file: ./Dockerfile
71+
tags: ${{ steps.docker-metadata.outputs.tags }}
72+
labels: ${{ steps.docker-metadata.outputs.labels }}
73+
cache-from: type=gha
74+
cache-to: type=gha,mode=max
75+

Dockerfile

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
# Builder stage: Install dependencies and build the application
2-
FROM python:3.13-slim AS builder
2+
FROM python:3.12-slim AS builder
33

44
# Install system dependencies
55
RUN apt-get update && apt-get install -y --no-install-recommends \
66
gcc \
77
g++ \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
# Set environment variable to ensure Python modules are installed in the correct location
11-
ENV PYTHONPATH=/app
12-
1310
# Install Poetry
14-
RUN pip install poetry==1.8.4
15-
16-
# Create a non-root user and switch to it
17-
RUN adduser --system --no-create-home codegate --uid 1000
11+
RUN pip install poetry==1.8.4 && rm -rf /root/.cache/pip
1812

1913
# Set the working directory
2014
WORKDIR /app
21-
22-
# Copy only the files needed for installing dependencies
2315
COPY pyproject.toml poetry.lock* /app/
2416

2517
# Configure Poetry and install dependencies
@@ -30,7 +22,7 @@ RUN poetry config virtualenvs.create false && \
3022
COPY . /app
3123

3224
# Runtime stage: Create the final lightweight image
33-
FROM python:3.13-slim AS runtime
25+
FROM python:3.12-slim AS runtime
3426

3527
# Install runtime system dependencies
3628
RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -40,14 +32,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
4032
# Create a non-root user and switch to it
4133
RUN adduser --system --no-create-home codegate --uid 1000
4234
USER codegate
35+
WORKDIR /app
4336

4437
# Copy necessary artifacts from the builder stage
4538
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
4639
COPY --from=builder /app /app
4740

48-
# Set the working directory
49-
WORKDIR /app
50-
5141
# Set the PYTHONPATH environment variable
5242
ENV PYTHONPATH=/app/src
5343

@@ -56,5 +46,4 @@ VOLUME ["/app/weaviate_data"]
5646

5747
# Set the container's default entrypoint
5848
EXPOSE 8989
59-
#ENTRYPOINT ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"]
60-
CMD ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"]
49+
ENTRYPOINT ["python", "-m", "src.codegate.cli", "serve", "--port", "8989", "--host", "0.0.0.0"]

0 commit comments

Comments
 (0)