-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (39 loc) · 1.48 KB
/
Dockerfile
File metadata and controls
54 lines (39 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
ARG PYTHON_VERSION=3.14-slim
# ===== Stage 1: Builder =====
FROM python:${PYTHON_VERSION} AS builder
ARG POETRY_VERSION=2.1.2
ARG POETRY_PLUGIN_EXPORT_VERSION=1.9.0
ENV POETRY_HOME="/opt/poetry"
ENV PATH="${POETRY_HOME}/bin:${PATH}"
# Install dependencies for Poetry and build process
RUN apt-get update && apt-get install -y curl \
&& curl -sSL https://install.python-poetry.org | POETRY_VERSION=$POETRY_VERSION python3 - \
&& rm -rf /var/lib/apt/lists/*
RUN poetry self add poetry-plugin-export==${POETRY_PLUGIN_EXPORT_VERSION}
WORKDIR /app
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Export dependencies to requirements.txt (no dev deps)
RUN poetry export --without-hashes --only main -f requirements.txt > requirements.txt
# Create and install dependencies into a virtualenv
RUN python -m venv /venv \
&& /venv/bin/pip install --no-cache-dir --upgrade pip \
&& /venv/bin/pip install --no-cache-dir -r requirements.txt
# ===== Stage 2: Final image =====
FROM python:${PYTHON_VERSION}
ENV PATH="/venv/bin:${PATH}"
WORKDIR /app
# Install git for reviewing local changes
RUN apt-get update && apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy virtualenv and source code from builder
COPY --from=builder /venv /venv
COPY . .
# Install the CLI tool
RUN /venv/bin/pip install --no-cache-dir .
# Create a non-root user and group and use it
RUN groupadd -g 1001 lgtm && \
useradd -m -u 1001 -g lgtm -s /bin/bash lgtm
USER lgtm
ENTRYPOINT ["lgtm"]