Skip to content

Commit aed7709

Browse files
committed
first pass on Dockerfile updates to uv
1 parent 274b775 commit aed7709

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

.github/Dockerfile.ci

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Dockerfile for CI/CD with Poetry and Python pre-installed
2-
FROM python:3.12-slim
1+
# Dockerfile for CI/CD with uv and Python pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.12-trixie
33

44
LABEL org.opencontainers.image.source="https://github.com/OpenSecFlow/netdriver"
5-
LABEL org.opencontainers.image.description="CI/CD image with Python 3.12 and Poetry"
5+
LABEL org.opencontainers.image.description="CI/CD image with Python 3.12 and uv"
66
LABEL org.opencontainers.image.licenses="Apache-2.0"
77

88
# Install system dependencies
@@ -11,22 +11,10 @@ RUN apt-get update && apt-get install -y \
1111
curl \
1212
&& rm -rf /var/lib/apt/lists/*
1313

14-
# Install Poetry
15-
ENV POETRY_VERSION=1.8.3
16-
ENV POETRY_HOME=/opt/poetry
17-
ENV POETRY_NO_INTERACTION=1
18-
ENV POETRY_VIRTUALENVS_IN_PROJECT=false
19-
ENV POETRY_VIRTUALENVS_CREATE=true
20-
21-
RUN curl -sSL https://install.python-poetry.org | python3 - \
22-
&& ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry
23-
24-
# Install Poetry plugins
25-
RUN poetry self add poetry-multiproject-plugin \
26-
&& poetry self add poetry-polylith-plugin
27-
28-
# Verify installation
29-
RUN poetry --version && poetry self show plugins
14+
# Set uv environment variables
15+
ENV UV_PYTHON=python3.12
16+
ENV UV_COMPILE_BYTECODE=1
17+
ENV UV_LINK_MODE=copy
3018

3119
WORKDIR /workspace
3220

projects/agent/Dockerfile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
11
# Multi-stage build for netdriver-agent
2-
FROM ghcr.io/opensecflow/netdriver/python-poetry AS builder
2+
FROM ghcr.io/opensecflow/netdriver/python-uv AS builder
33

44
LABEL org.opencontainers.image.source="https://github.com/OpenSecFlow/netdriver"
55
LABEL org.opencontainers.image.description="NetDriver Agent - Network Device Automation REST API"
66
LABEL org.opencontainers.image.licenses="Apache-2.0"
77

8-
# Poetry is already installed with plugins in the base image
9-
ENV POETRY_NO_INTERACTION=1
10-
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
11-
ENV POETRY_VIRTUALENVS_CREATE=true
8+
# uv is already installed in the base image
9+
ENV UV_NO_PROGRESS=1
10+
ENV UV_PYTHON=python3.12
11+
ENV UV_COMPILE_BYTECODE=1
12+
ENV UV_LINK_MODE=copy
1213

1314
WORKDIR /build
1415

1516
# Copy project files
1617
COPY . .
1718

18-
# Install dependencies and build
19-
RUN poetry install --only main --no-interaction --no-ansi \
20-
&& poetry build-project -C projects/agent
19+
# Build the wheel using uv
20+
RUN uv build --directory projects/agent --wheel
2121

2222
# Final stage
23-
FROM python:3.12-slim
23+
FROM ghcr.io/astral-sh/uv:python3.12-trixie
2424

2525
LABEL org.opencontainers.image.source="https://github.com/OpenSecFlow/netdriver"
2626
LABEL org.opencontainers.image.description="NetDriver Agent - Network Device Automation REST API"
2727
LABEL org.opencontainers.image.licenses="Apache-2.0"
2828

29+
# Set uv environment variables for production
30+
ENV UV_COMPILE_BYTECODE=1
31+
ENV UV_LINK_MODE=copy
32+
ENV UV_PYTHON=python3.12
33+
2934
# Create non-root user
3035
RUN useradd -m -u 1000 netdriver
3136

3237
WORKDIR /app
3338

34-
# Copy built wheel and install it
39+
# Copy built wheel and install it using uv
3540
COPY --from=builder /build/projects/agent/dist/*.whl /tmp/
36-
RUN pip install --no-cache-dir /tmp/*.whl \
41+
RUN uv pip install --system --no-cache /tmp/*.whl \
3742
&& rm -rf /tmp/*.whl
3843

3944
# Copy configuration files

projects/simunet/Dockerfile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
11
# Multi-stage build for netdriver-simunet
2-
FROM ghcr.io/opensecflow/netdriver/python-poetry AS builder
2+
FROM ghcr.io/opensecflow/netdriver/python-uv AS builder
33

44
LABEL org.opencontainers.image.source="https://github.com/OpenSecFlow/netdriver"
55
LABEL org.opencontainers.image.description="NetDriver Simunet - Simulated SSH Server for Network Devices"
66
LABEL org.opencontainers.image.licenses="Apache-2.0"
77

8-
# Poetry is already installed with plugins in the base image
9-
ENV POETRY_NO_INTERACTION=1
10-
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
11-
ENV POETRY_VIRTUALENVS_CREATE=true
8+
# uv is already installed in the base image
9+
ENV UV_NO_PROGRESS=1
10+
ENV UV_PYTHON=python3.12
11+
ENV UV_COMPILE_BYTECODE=1
12+
ENV UV_LINK_MODE=copy
1213

1314
WORKDIR /build
1415

1516
# Copy project files
1617
COPY . .
1718

18-
# Install dependencies and build
19-
RUN poetry install --only main --no-interaction --no-ansi \
20-
&& poetry build-project -C projects/simunet
19+
# Build the wheel using uv
20+
RUN uv build --directory projects/simunet --wheel
2121

2222
# Final stage
23-
FROM python:3.12-slim
23+
FROM ghcr.io/astral-sh/uv:python3.12-trixie
2424

2525
LABEL org.opencontainers.image.source="https://github.com/OpenSecFlow/netdriver"
2626
LABEL org.opencontainers.image.description="NetDriver Simunet - Simulated SSH Server for Network Devices"
2727
LABEL org.opencontainers.image.licenses="Apache-2.0"
2828

29+
# Set uv environment variables for production
30+
ENV UV_COMPILE_BYTECODE=1
31+
ENV UV_LINK_MODE=copy
32+
ENV UV_PYTHON=python3.12
33+
2934
# Create non-root user
3035
RUN useradd -m -u 1000 netdriver
3136

3237
WORKDIR /app
3338

34-
# Copy built wheel and install it
39+
# Copy built wheel and install it using uv
3540
COPY --from=builder /build/projects/simunet/dist/*.whl /tmp/
36-
RUN pip install --no-cache-dir /tmp/*.whl \
41+
RUN uv pip install --system --no-cache /tmp/*.whl \
3742
&& rm -rf /tmp/*.whl
3843

3944
# Copy configuration files

0 commit comments

Comments
 (0)