-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (48 loc) · 1.87 KB
/
Dockerfile
File metadata and controls
64 lines (48 loc) · 1.87 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
# syntax=docker/dockerfile:1
FROM python:3.11.0
# General environment settings
ENV PYTHONFAULTHANDLER=1 \
# print immediately in stdout
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.8.0
# Project settings
ENV user=alab \
project_folder=PyFlowintel
# Set the complete project home path
ENV PROJECT_HOME=/home/${user}/${project_folder}/
# Update dependencies in the Debian OS that comes with the base image
RUN apt update --fix-missing
RUN pip install --upgrade pip
# Create a non-root user with sudo capability
RUN useradd -ms /bin/bash ${user} && echo "${user} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# Switch to non-root user
USER ${user}
# Install pipx and add it to PATH
RUN python3 -m pip install pipx
ENV PATH="/home/${user}/.local/bin:${PATH}"
# Install Poetry
RUN pipx install "poetry==$POETRY_VERSION"
RUN poetry completions bash >> ~/.bash_completion
# Create and set the working directory in the container
WORKDIR ${PROJECT_HOME}
# Copy dependency files from the host to the container
COPY poetry.lock pyproject.toml ${PROJECT_HOME}
#COPY pyproject.toml ${PROJECT_HOME}
# copy the project files separately for build cache optimization
COPY . ${PROJECT_HOME}
# Install the project's dependencies using Poetry and create virtual environment
RUN poetry install
# Switch back to root for cleanup
USER root
# Clean up unnecessary packages to reduce image size
RUN apt-get autoremove -y && apt-get autoclean -y && apt-get clean -y
# Set the container's starting point running the project as the user
USER ${user}
WORKDIR ${PROJECT_HOME}
# Health check - verify Poetry and package can be imported
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD poetry run python -c "from pyflowintel import PyFlowintel; print('OK')" || exit 1
# Entry point: run bash within Poetry's virtual environment
ENTRYPOINT ["poetry", "run", "bash"]