-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerfile
47 lines (45 loc) · 1.6 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
#Get the base images
FROM python:3.9.0 AS develop-stage
#Set the working directory
WORKDIR /app
#Set some python env vars
ENV PATH="/venv/bin:$PATH"
ENV PYTHONPATH=/app
#Create the virtual env for python to isntall modules
RUN python -m venv /venv
#Copy over the requirements txt for pip
COPY SnipeITToTTM/requirements.txt requirements.txt
#install python dependencies
RUN pip install --no-cache-dir -r requirements.txt
#Copy over the application source to the /app folder in the container
COPY SnipeITToTTM/. .
#Entry command for this stage
CMD ["python", "main.py"]
#Pull from the previous state
FROM develop-stage as build-stage
#Make a tmp dir this is needed for pyinstaller to use
RUN mkdir tmp
#Make a storage dir this is for logs etc
RUN mkdir /app/storage
#Install and update dependancy for staticx
RUN apt update && apt install patchelf
#Copy python dependencies from previous venv
COPY --from=develop-stage /venv /venv
#run pyinstaller to make a one-file bundled executable of the app
RUN pyinstaller -F main.py
#run staticx to grab a linux dependencies and make a package of it
RUN staticx /app/dist/main /app/dist/main_tmp
#Entry command for this stage
CMD ["/app/dist/main"]
#New base image with nothing in it
FROM scratch
#Create a non admin user
USER 65535
#Copy tmp files and set user permissions
COPY --from=build-stage --chown=65535:65535 /app/tmp /tmp
#Copy the staticx application and set user permissions
COPY --from=build-stage --chown=65535:65535 /app/dist/main_tmp /app/main
#Copy the storage dir
COPY --from=build-stage --chown=65535:65535 /app/storage /app/storage
#Entry command for this stage
CMD ["/app/main"]