-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
58 lines (42 loc) · 1.48 KB
/
Dockerfile
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
# Stage 1 - Build Stage
FROM python:3.11-slim AS builder
# Install system dependencies and create a non-root user
RUN groupadd --gid 1000 appuser \
&& useradd --uid 1000 --gid 1000 -ms /bin/bash appuser
# Install pip and virtualenv
RUN pip install --no-cache-dir --upgrade pip virtualenv
# Install build essentials and other necessary tools
RUN apt-get update && apt-get install -y build-essential software-properties-common git
# Switch to the non-root user
USER appuser
# Set the working directory
WORKDIR /home/appuser
# Copy the source code into the container
COPY . /home/appuser/
# Set environment variables
ENV VIRTUAL_ENV="/home/appuser/venv"
ENV LC_ALL=es_AR.utf8
ENV LANG=es_AR.utf8
ENV LANGUAGE=es_AR.utf8
ENV TZ=America/Argentina/Buenos_Aires
# Create and activate the virtual environment, and install dependencies
RUN python -m venv ${VIRTUAL_ENV}
RUN . ${VIRTUAL_ENV}/bin/activate && pip install -r requirements.txt
# Stage 2 - Production Image
FROM python:3.11-slim AS production
# Create a non-root user to run the application
RUN groupadd --system appuser \
&& useradd --system --gid appuser appuser
# Switch to the non-root user
USER appuser
# Set the working directory
WORKDIR /home/appuser
# Copy from the first stage
COPY --from=builder /home/appuser /home/appuser
# Set environment variables
ENV TZ=America/Argentina/Buenos_Aires
# Expose the port
EXPOSE 8501
# Copy the run script to the image and set as entrypoint
COPY run.sh /home/appuser
ENTRYPOINT ["./run.sh"]