-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (56 loc) · 2.29 KB
/
Dockerfile
File metadata and controls
72 lines (56 loc) · 2.29 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.11
# First stage: build environment
FROM python:${PYTHON_VERSION}-slim-buster AS builder
# Install system dependencies
RUN apt-get update && \
apt-get install -y build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install poetry
# Set up the working directory
WORKDIR /srv/flowctl
ADD flowctl ./flowctl
# Copy the project files and install dependencies
COPY pyproject.toml poetry.lock README.md ./
# Create a virtual env
RUN python -m venv /opt/venv
# Install the project and dependencies
RUN . /opt/venv/bin/activate && \
poetry config installer.max-workers 4 && \
poetry install --without dev --all-extras
# Second stage: production environment
FROM python:${PYTHON_VERSION}-slim-buster AS production
# Install system dependencies
RUN apt-get update && \
apt-get install -y build-essential && \
apt-get install -y python3-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create a non-root user and give necessary permissions
# We use the UID 1000 since it is the default UID for the first user on most systems
RUN useradd -u 1000 -G sudo -U -m -s /bin/bash flowdapt \
&& echo "flowdapt ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers
# Set up the working directory
WORKDIR /srv/flowctl
# Copy the virtual environment and code from the builder stage
COPY --from=builder --chown=flowdapt:flowdapt /srv/flowctl /srv/flowctl
COPY --from=builder --chown=flowdapt:flowdapt /opt/venv /opt/venv
# Add the virtual environment to the system PATH (same as activating it)
ENV PATH="/opt/venv/bin:$PATH"
# Set the environment variable in the shell's profile to support login shells
# having the virtual environment activated by default
RUN echo 'export PATH=/opt/venv/bin:$PATH' >> /home/flowdapt/.profile
# Default the data directory to /data while running in a container
ENV FLOWCTL__APP_DIR="/data"
# Deactivate config file persistence and reading by default
# This will just cause the server to use default values
# but can still be overridden by setting this variable
ENV FLOWCTL__CONFIG_FILE="-"
# Create the data directory and give necessary permissions
RUN mkdir -p /data && chown -R flowdapt:flowdapt /data
WORKDIR /data
# Switch to the non-root user
USER flowdapt
ENTRYPOINT ["flowctl"]