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

Commit f005ecc

Browse files
authored
Merge pull request #113 from stacklok/issue-62
feat: create Dockerfile for shipping codegate as image
2 parents 1c73d91 + 60ab202 commit f005ecc

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Builder stage: Install dependencies and build the application
2+
FROM python:3.12-slim AS builder
3+
4+
# Install system dependencies
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
gcc \
7+
g++ \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Set environment variable to ensure Python modules are installed in the correct location
11+
ENV PYTHONPATH=/app
12+
13+
# 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
18+
19+
# Set the working directory
20+
WORKDIR /app
21+
22+
# Copy only the files needed for installing dependencies
23+
COPY pyproject.toml poetry.lock* /app/
24+
25+
# Configure Poetry and install dependencies
26+
RUN poetry config virtualenvs.create false && \
27+
poetry install --no-dev
28+
29+
# Copy the rest of the application
30+
COPY . /app
31+
32+
# Runtime stage: Create the final lightweight image
33+
FROM python:3.12-slim AS runtime
34+
35+
# Install runtime system dependencies
36+
RUN apt-get update && apt-get install -y --no-install-recommends \
37+
libgomp1 \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
# Create a non-root user and switch to it
41+
RUN adduser --system --no-create-home codegate --uid 1000
42+
USER codegate
43+
44+
# Copy necessary artifacts from the builder stage
45+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
46+
COPY --from=builder /app /app
47+
48+
# Set the working directory
49+
WORKDIR /app
50+
51+
# Set the PYTHONPATH environment variable
52+
ENV PYTHONPATH=/app/src
53+
54+
# Allow to expose weaviate_data volume
55+
VOLUME ["/app/weaviate_data"]
56+
57+
# Set the container's default entrypoint
58+
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"]

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.PHONY: clean install format lint test security build all
2+
CONTAINER_BUILD?=docker buildx build
3+
VER?=0.1.0
24

35
clean:
46
rm -rf build/
@@ -27,4 +29,8 @@ security:
2729
build: clean test
2830
poetry build
2931

32+
image-build:
33+
$(CONTAINER_BUILD) -f Dockerfile -t codegate . -t ghcr.io/stacklok/codegate:$(VER) --load
34+
35+
3036
all: clean install format lint test security build

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,19 @@ pip install -e ".[dev]"
108108
```bash
109109
pytest
110110
```
111+
112+
113+
### Running from image
114+
115+
A docker image can be built just with `make image-build`. That will start a codegate server ready to use.
116+
Then it can be started with:
117+
118+
```bash
119+
docker run -p 8989:8989 codegate:latest
120+
```
121+
122+
Additionally if you want to start with a pre-created database, a volume can be mounted:
123+
124+
```bash
125+
docker run -p 8989:8989 -v /path/to/volume:/app/weaviate_data codegate:latest
126+
```

0 commit comments

Comments
 (0)