generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
84 lines (69 loc) · 2.34 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
FROM python:3.10 AS builder
# DECLARE SHELL
SHELL ["/bin/bash", "-c"]
## ARGS ##
ARG REQS=base
ARG DEVREQS=test
ARG VENV=/usr/local/gval_env
ARG PROJDIR=/home/user/gval
ARG PANDOC_PARENT=/usr/bin/local
ARG VERSION='0.0.1'
ARG MAINTANER='Fernando Aristizabal & Gregory Petrochenkov'
ARG RELEASE_DATE=''
## SETUP ENV VARS ##
ENV VENV=$VENV
ENV PROJDIR=$PROJDIR
## COPY IN REQUIREMENTS ##
COPY requirements/$REQS.txt /tmp
COPY requirements/$DEVREQS.txt /tmp
## INSTALL EXTERNAL DEPENDENCIES ##
# remove versions if errors occur
RUN wget -P $PANDOC_PARENT https://github.com/jgm/pandoc/releases/download/3.1/pandoc-3.1-linux-amd64.tar.gz && \
tar -xf $PANDOC_PARENT/pandoc-3.1-linux-amd64.tar.gz --directory $PANDOC_PARENT && \
python3 -m venv $VENV && \
$VENV/bin/pip install --upgrade build && \
$VENV/bin/pip install -r /tmp/$REQS.txt && \
$VENV/bin/pip install -r /tmp/$DEVREQS.txt
###############################################################################################
# development stage
###############################################################################################
FROM python:3.10 AS development
## ARGS ##
ARG REQS=base
ARG DEVREQS=test
ARG VENV=/usr/local/gval_env
ARG PANDOC=/usr/bin/local/pandoc-3.1/bin
ARG PROJDIR=/home/user/gval
ARG VERSION='0.0.1'
ARG MAINTANER='Fernando Aristizabal & Gregory Petrochenkov'
ARG RELEASE_DATE=''
# Label docker image
LABEL version=$VERSION \
maintaner=$MAINTANER \
release-date=$RELEASE_DATE
## SETTING ENV VARIABLES ##
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# ensures stdout stderr are sent straight to terminal
ENV PYTHONUNBUFFERED=TRUE
ENV VENV=$VENV
ENV PROJDIR=$PROJDIR
# add path to virtual env so that future python commands use it
ENV PATH="$VENV/bin:$PANDOC:$PATH"
## ADDING USER GROUP ##
ARG UID=1001
ARG UNAME=user
RUN useradd -Ums /bin/bash -u $UID $UNAME
USER $UNAME
WORKDIR /home/$UNAME
# RETRIEVE BUILT DEPENDENCIES
COPY --from=builder --chown=$UID $VENV $VENV
COPY --from=builder --chown=$UID $PANDOC $PANDOC
##############################################################################################
# runtime stage
##############################################################################################
FROM development AS runtime
COPY . $PROJDIR
WORKDIR $PROJDIR
RUN $VENV/bin/pip install $PROJDIR
CMD ["./.venv/bin/python", "-m", "$PROJDIR/main.py"]