victorisgeek commited on
Commit
75359fe
·
verified ·
1 Parent(s): c53194e

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +59 -0
Dockerfile ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Build stage
2
+ FROM python:3.11-slim-buster AS Build
3
+
4
+ # Set environment variables for Python and Poetry
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PIP_NO_CACHE_DIR=1 \
7
+ POETRY_NO_INTERACTION=1 \
8
+ POETRY_VIRTUALENVS_CREATE=false \
9
+ POETRY_VERSION=1.7.1
10
+
11
+ # Set the working directory in the container
12
+ WORKDIR /app
13
+
14
+ # Copy the dependencies file to the working directory
15
+ COPY ./pyproject.toml /app/
16
+
17
+ # Update, install dependencies, and prepare the Python environment
18
+ RUN apt-get update && \
19
+ apt-get install -y gcc g++ unixodbc-dev && \
20
+ pip install "poetry==$POETRY_VERSION" && \
21
+ poetry export --without-hashes --format requirements.txt --output requirements.txt && \
22
+ python3 -m pip wheel --no-cache-dir --no-deps -w /app/wheels -r requirements.txt
23
+
24
+ # Runtime stage
25
+ FROM python:3.11-slim-buster AS Run
26
+
27
+ # Set environment variables for Python and Poetry
28
+ ENV HOME=/home/user \
29
+ PATH=/home/user/.local/bin:$PATH
30
+
31
+ # Create a non-root user
32
+ RUN useradd -m -u 1000 user
33
+
34
+ # Switch to the non-root user
35
+ USER user
36
+
37
+ # Copy wheel files from the build stage
38
+ COPY --from=build /app/wheels $HOME/app/wheels
39
+
40
+ # Set the working directory to where the wheels are
41
+ WORKDIR $HOME/app/wheels
42
+
43
+ # Install the wheel files
44
+ RUN pip3 --no-cache-dir install *.whl
45
+
46
+ # Change app name here to copy the application files to the working directory
47
+ COPY --chown=user ./your-app-name $HOME/app
48
+
49
+ # Set the working directory to the application files
50
+ WORKDIR $HOME/app
51
+
52
+ # Specify the command to run the application
53
+ ENTRYPOINT [ "writer", "run" ]
54
+
55
+ # Expose the port the app runs on
56
+ EXPOSE 8080
57
+
58
+ # Set the default command to run the app
59
+ CMD [ ".", "--port", "8080", "--host", "0.0.0.0" ]