Skip to content

Commit 9a319bd

Browse files
committed
in progress docker changes
1 parent 9967321 commit 9a319bd

File tree

6 files changed

+318
-0
lines changed

6 files changed

+318
-0
lines changed

docker/Backend.Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# from code mod
2+
FROM python:3.11-slim
3+
4+
# This is required by the executable called by the Syntax Checker agent
5+
RUN apt-get update && \
6+
apt-get install -y libicu-dev
7+
8+
WORKDIR /app
9+
10+
# Copy only requirements first to leverage Docker cache
11+
COPY ../src/backend/requirements.txt .
12+
13+
# Install dependencies
14+
RUN pip install --no-cache-dir -r requirements.txt
15+
16+
# Copy backend code
17+
COPY ../src/backend/ .
18+
19+
EXPOSE 8000
20+
21+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
22+
23+
24+
# From Multi Agent
25+
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye AS base
26+
WORKDIR /app
27+
28+
FROM base AS builder
29+
COPY --from=ghcr.io/astral-sh/uv:0.6.3 /uv /uvx /bin/
30+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
31+
32+
WORKDIR /app
33+
COPY uv.lock pyproject.toml /app/
34+
35+
# Install the project's dependencies using the lockfile and settings
36+
RUN --mount=type=cache,target=/root/.cache/uv \
37+
--mount=type=bind,source=uv.lock,target=uv.lock \
38+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
39+
uv sync --frozen --no-install-project --no-dev
40+
41+
# Backend app setup
42+
COPY . /app
43+
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
44+
45+
FROM base
46+
47+
COPY --from=builder /app /app
48+
COPY --from=builder /bin/uv /bin/uv
49+
50+
ENV PATH="/app/.venv/bin:$PATH"
51+
# Install dependencies
52+
53+
EXPOSE 8000
54+
CMD ["uv", "run", "uvicorn", "app_kernel:app", "--host", "0.0.0.0", "--port", "8000"]

docker/Backend_s.Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Base Python image
2+
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye AS base
3+
WORKDIR /app
4+
5+
FROM base AS builder
6+
COPY --from=ghcr.io/astral-sh/uv:0.6.3 /uv /uvx /bin/
7+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
8+
9+
WORKDIR /app
10+
# Copy project files from the correct relative path
11+
COPY ../src/backend/uv.lock ../src/backend/pyproject.toml /app/
12+
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev
18+
19+
# Backend app setup - copy from the correct relative path
20+
COPY ../src/backend/ /app/
21+
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
22+
23+
FROM base
24+
25+
COPY --from=builder /app /app
26+
COPY --from=builder /bin/uv /bin/uv
27+
28+
ENV PATH="/app/.venv/bin:$PATH"
29+
30+
EXPOSE 8000
31+
CMD ["uv", "run", "uvicorn", "app_kernel:app", "--host", "0.0.0.0", "--port", "8000"]

docker/Frontend copy.Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Build stage
2+
FROM node:18 AS build
3+
4+
WORKDIR /app
5+
6+
# Copy package files
7+
COPY src/frontend/package*.json ./
8+
9+
# Install dependencies
10+
RUN npm install
11+
12+
# Copy frontend source
13+
COPY src/frontend/ .
14+
15+
# Build the app
16+
RUN npm run build
17+
18+
# Runtime stage
19+
FROM python:3.11-slim
20+
21+
WORKDIR /app
22+
23+
# Copy Python requirements and install
24+
COPY src/frontend/requirements.txt .
25+
RUN pip install --no-cache-dir -r requirements.txt
26+
27+
# Copy built assets from build stage
28+
COPY --from=build /app/dist ./dist
29+
COPY src/frontend/frontend_server.py .
30+
31+
EXPOSE 3000
32+
33+
CMD ["uvicorn", "frontend_server:app", "--host", "0.0.0.0", "--port", "3000"]
34+
35+
# OTHER DOCKERFILE
36+
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye AS base
37+
WORKDIR /app
38+
39+
FROM base AS builder
40+
COPY --from=ghcr.io/astral-sh/uv:0.6.3 /uv /uvx /bin/
41+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
42+
43+
WORKDIR /app
44+
COPY uv.lock pyproject.toml /app/
45+
46+
# Install the project's dependencies using the lockfile and settings
47+
RUN --mount=type=cache,target=/root/.cache/uv \
48+
--mount=type=bind,source=uv.lock,target=uv.lock \
49+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
50+
uv sync --frozen --no-install-project --no-dev
51+
52+
# Backend app setup
53+
COPY . /app
54+
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
55+
56+
FROM base
57+
58+
COPY --from=builder /app /app
59+
COPY --from=builder /bin/uv /bin/uv
60+
61+
ENV PATH="/app/.venv/bin:$PATH"
62+
63+
EXPOSE 3000
64+
CMD ["uv","run","uvicorn", "frontend_server:app", "--host", "0.0.0.0", "--port", "3000"]

docker/Frontend.Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Build stage node
2+
FROM node:18 AS build
3+
4+
WORKDIR /app
5+
6+
# Copy package files
7+
COPY src/frontend/package*.json ./
8+
9+
# Install dependencies
10+
RUN npm install
11+
12+
# Copy frontend source
13+
COPY src/frontend/ .
14+
15+
# Build the app
16+
RUN npm run build
17+
18+
# Runtime stage
19+
FROM python:3.11-slim
20+
21+
WORKDIR /app
22+
23+
# Copy Python requirements and install
24+
COPY src/frontend/requirements.txt .
25+
RUN pip install --no-cache-dir -r requirements.txt
26+
27+
# Copy built assets from build stage
28+
COPY --from=build /app/dist ./dist
29+
COPY src/frontend/frontend_server.py .
30+
31+
EXPOSE 3000
32+
33+
CMD ["uvicorn", "frontend_server:app", "--host", "0.0.0.0", "--port", "3000"]
34+
35+
# OTHER DOCKERFILE
36+
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye AS base
37+
WORKDIR /app
38+
39+
FROM base AS builder
40+
COPY --from=ghcr.io/astral-sh/uv:0.6.3 /uv /uvx /bin/
41+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
42+
43+
WORKDIR /app
44+
COPY uv.lock pyproject.toml /app/
45+
46+
# Install the project's dependencies using the lockfile and settings
47+
RUN --mount=type=cache,target=/root/.cache/uv \
48+
--mount=type=bind,source=uv.lock,target=uv.lock \
49+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
50+
uv sync --frozen --no-install-project --no-dev
51+
52+
# Backend app setup
53+
COPY . /app
54+
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
55+
56+
FROM base
57+
58+
COPY --from=builder /app /app
59+
COPY --from=builder /bin/uv /bin/uv
60+
61+
ENV PATH="/app/.venv/bin:$PATH"
62+
63+
EXPOSE 3000
64+
CMD ["uv","run","uvicorn", "frontend_server:app", "--host", "0.0.0.0", "--port", "3000"]

docker/Frontend_s.Dockerfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Multi-stage Dockerfile for React frontend with Python backend support using UV
2+
3+
# Stage 1: Node build environment for React
4+
FROM node:18-alpine AS frontend-builder
5+
6+
WORKDIR /app/frontend
7+
8+
# Copy package files first for better caching
9+
COPY src/frontend_react/package*.json ./
10+
11+
# Install dependencies
12+
RUN npm ci --silent
13+
14+
# Copy source files
15+
COPY src/frontend_react/ ./
16+
17+
# Build the React app
18+
RUN npm run build
19+
20+
# Stage 2: Python build environment with UV
21+
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye AS python-builder
22+
23+
# Copy UV from official image
24+
COPY --from=ghcr.io/astral-sh/uv:0.6.3 /uv /uvx /bin/
25+
26+
# Setup UV environment variables
27+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
28+
29+
WORKDIR /app
30+
31+
# Copy Python project definition files
32+
COPY src/frontend_react/pyproject.toml src/frontend_react/uv.lock* ./
33+
34+
# Install Python dependencies using UV
35+
RUN --mount=type=cache,target=/root/.cache/uv \
36+
uv pip install --system -r <(uv pip freeze --requirement pyproject.toml)
37+
38+
# Stage 3: Final production image
39+
FROM python:3.11-slim-bullseye
40+
41+
# Set production environment
42+
ENV NODE_ENV=production \
43+
PYTHONDONTWRITEBYTECODE=1 \
44+
PYTHONUNBUFFERED=1 \
45+
PATH="/app/venv/bin:$PATH"
46+
47+
WORKDIR /app
48+
49+
# Create a non-root user for security
50+
RUN adduser --disabled-password --gecos "" appuser && \
51+
mkdir -p /app/static && \
52+
chown -R appuser:appuser /app
53+
54+
# Copy Python dependencies from builder
55+
COPY --from=python-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
56+
COPY --from=python-builder /usr/local/bin /usr/local/bin
57+
58+
# Copy React build artifacts
59+
COPY --from=frontend-builder --chown=appuser:appuser /app/frontend/build /app/static
60+
61+
# Copy Python application code
62+
COPY --chown=appuser:appuser src/frontend_react/*.py /app/
63+
64+
# Create log directory with correct permissions
65+
RUN mkdir -p /app/logs && chown -R appuser:appuser /app/logs
66+
67+
# Use non-root user for security
68+
USER appuser
69+
70+
# Expose port
71+
EXPOSE 3000
72+
73+
# Health check
74+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
75+
CMD curl -f http://localhost:3000/health || exit 1
76+
77+
# Run the application with uvicorn
78+
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "3000", "--log-config", "log_config.json"]

docker/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3.8'
2+
3+
services:
4+
backend:
5+
build:
6+
context: ..
7+
dockerfile: docker/Backend.Dockerfile
8+
ports:
9+
- "8000:8000"
10+
environment:
11+
- AZURE_STORAGE_CONNECTION_STRING=${AZURE_STORAGE_CONNECTION_STRING}
12+
- AZURE_COSMOS_CONNECTION_STRING=${AZURE_COSMOS_CONNECTION_STRING}
13+
volumes:
14+
- ../src/backend/logs:/app/logs
15+
16+
frontend:
17+
build:
18+
context: ..
19+
dockerfile: docker/Frontend.Dockerfile
20+
ports:
21+
- "3000:3000"
22+
depends_on:
23+
- backend
24+
25+
networks:
26+
default:
27+
name: codegen-network

0 commit comments

Comments
 (0)