-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.prod
130 lines (99 loc) · 3.86 KB
/
Dockerfile.prod
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
###########
# BUILDER #
###########
# pull official base image
FROM ubuntu:20.04 as builder
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
#Time to install Postgresql
ENV TZ=Europe/Kiev
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Setup Python
RUN apt update
RUN apt-get update && \
apt-get install --no-install-recommends -y \
python3.8 python3-pip python3.8-dev \
build-essential autoconf libtool pkg-config gcc libssl-dev netcat libxml2-dev libcurl4-openssl-dev
# Setup Postgres
RUN apt-get install --no-install-recommends -y postgresql postgresql-contrib
# install dependencies
COPY ./requirements.txt .
RUN pip3 wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
# copy project
COPY . .
#RUN flake8 --ignore=E501,F401 .
#RUN cd miopy && python3.8 setup.py install --user
###########
# FINAL #
###########
# pull official base image
FROM ubuntu:20.04
#Time to install Postgresql
ENV TZ=Europe/Kiev
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update
# Setup Python
RUN apt-get update && \
apt-get install --no-install-recommends -y \
python3.8 python3-pip python3.8-dev \
build-essential autoconf libtool pkg-config gcc libssl-dev netcat libxml2-dev libcurl4-openssl-dev
# Setup Postgres
RUN apt-get install --no-install-recommends -y postgresql postgresql-contrib
# create directory for the app user
RUN mkdir -p /home/app
RUN mkdir -p /home/app/.local/lib/python3.8/site-packages
# Install R
RUN apt-get update && apt-get -y install --no-install-recommends --no-install-suggests \
ca-certificates software-properties-common gnupg2 gnupg1 dirmngr apt-transport-https \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 \
&& add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' \
&& apt-get -y install r-base
#Install git
RUN apt-get -y install git git-lfs
RUN git lfs install
##R Library
COPY ./scripts/docker/r_dependence.r ${APP_HOME}
RUN Rscript ${APP_HOME}/r_dependence.r
# create the app user
#RUN addgroup 65534 && useradd -d /home/app/ -u 65534 -g 65534 nobody
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/Data
RUN mkdir $APP_HOME/staticfiles/account/
WORKDIR $APP_HOME
# Setup Python
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip3 install --no-cache /wheels/*
# copy entrypoint-prod.sh
COPY ./scripts/docker/entrypoint.sh $APP_HOME
# copy project
COPY . $APP_HOME
#RUN cd ${APP_HOME}/miotools && python3 setup.py install
# chown all the files to the app user
RUN chown -R nobody:nogroup $APP_HOME/
RUN chown -R nobody:nogroup $APP_HOME/*
RUN chown -R nobody:nogroup /home/app/.local/*
RUN touch /var/log/django.log && chown -R nobody:nogroup /var/log/django.log
RUN touch /home/app/web/gunicorn-access.log && chown nobody:nogroup /home/app/web/gunicorn-access.log
RUN mkdir -p '/home/app/web/staticfiles/account' & chown -R nobody:nogroup '/home/app/web/staticfiles/account'
RUN mkdir -p '/home/app/.local/bin/'
RUN mkdir -p '/home/app/web/Data/' && chown -R nobody:nogroup '/home/app/web/Data/' && chmod ugo+rw '/home/app/web/Data/'
#RUN git lfs clone https://github.com/icbi-lab/miopy.git
#COPY ./miopy $APP_HOME
RUN cd $APP_HOME/miopy/ && python3 ./setup.py install --user
RUN find /home/app/ -type f -print0 | xargs -0 chown nobody:nogroup
RUN find /home/app/ -type d -print0 | xargs -0 chown nobody:nogroup
<