-
Notifications
You must be signed in to change notification settings - Fork 36
/
Dockerfile
177 lines (128 loc) · 5.53 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
FROM ubuntu:18.04 AS common
LABEL maintainer="Specify Collections Consortium <github.com/specify>"
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
gettext \
python3.8 \
libldap-2.4-2 \
libmariadbclient18 \
rsync \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd -g 999 specify \
&& useradd -r -u 999 -g specify specify
RUN mkdir -p /home/specify \
&& chown specify.specify /home/specify
RUN mkdir -p /opt/specify7 \
&& chown specify.specify /opt/specify7
#####################################################################
FROM node:20-alpine AS build-frontend
LABEL maintainer="Specify Collections Consortium <github.com/specify>"
USER node
WORKDIR /home/node
COPY --chown=node:node specifyweb/frontend/js_src/package*.json ./
RUN npm ci
RUN mkdir dist && chown node:node dist
COPY --chown=node:node specifyweb/frontend/js_src .
RUN npx webpack --mode production
#####################################################################
FROM common AS build-backend
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
build-essential \
ca-certificates \
curl \
git \
libldap2-dev \
libmariadbclient-dev \
libsasl2-dev \
python3.8-venv \
python3.8-distutils \
python3.8-dev
USER specify
COPY --chown=specify:specify requirements.txt /home/specify/
WORKDIR /opt/specify7
RUN python3.8 -m venv ve \
&& ve/bin/pip install --no-cache-dir -r /home/specify/requirements.txt
RUN ve/bin/pip install --no-cache-dir gunicorn
COPY --from=build-frontend /home/node/dist specifyweb/frontend/static/js
COPY --chown=specify:specify specifyweb /opt/specify7/specifyweb
COPY --chown=specify:specify manage.py /opt/specify7/
COPY --chown=specify:specify docker-entrypoint.sh /opt/specify7/
COPY --chown=specify:specify Makefile /opt/specify7/
COPY --chown=specify:specify specifyweb.wsgi /opt/specify7/
COPY --chown=specify:specify config /opt/specify7/config
ARG BUILD_VERSION
ARG GIT_SHA
ENV BUILD_VERSION=$BUILD_VERSION
RUN make specifyweb/settings/build_version.py
RUN echo $BUILD_VERSION > specifyweb/frontend/static/build_version.txt
RUN echo $GIT_SHA > specifyweb/frontend/static/git_sha.txt
RUN date > specifyweb/frontend/static/build_date.txt
# The following is needed to run manage.py compilemessages:
# The secret key file needs to exist so it can be imported.
# The INSTALLED_APPS needs to be cleared out so Django doesn't
# try to import the Specify datamodel which isn't defined yet.
RUN echo "SECRET_KEY = 'bogus'" > specifyweb/settings/secret_key.py
RUN echo "INSTALLED_APPS = ['specifyweb.frontend']" >> specifyweb/settings/__init__.py
RUN (cd specifyweb && ../ve/bin/python ../manage.py compilemessages)
# Now put things back the way they were.
RUN rm specifyweb/settings/secret_key.py
COPY --chown=specify:specify specifyweb/settings/__init__.py /opt/specify7/specifyweb/settings/__init__.py
######################################################################
FROM common AS run-common
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
rsync \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir -p /volumes/static-files/depository \
&& chown -R specify.specify /volumes/static-files
USER specify
COPY --from=build-backend /opt/specify7 /opt/specify7
WORKDIR /opt/specify7
RUN cp -r specifyweb/settings .
RUN echo \
"import os" \
"\nDATABASE_NAME = os.environ['DATABASE_NAME']" \
"\nDATABASE_HOST = os.environ['DATABASE_HOST']" \
"\nDATABASE_PORT = os.environ.get('DATABASE_PORT', '')" \
"\nMASTER_NAME = os.environ['MASTER_NAME']" \
"\nMASTER_PASSWORD = os.environ['MASTER_PASSWORD']" \
"\nDEPOSITORY_DIR = '/volumes/static-files/depository'" \
"\nREPORT_RUNNER_HOST = os.getenv('REPORT_RUNNER_HOST', '')" \
"\nREPORT_RUNNER_PORT = os.getenv('REPORT_RUNNER_PORT', '')" \
"\nWEB_ATTACHMENT_URL = os.getenv('ASSET_SERVER_URL', None)" \
"\nWEB_ATTACHMENT_KEY = os.getenv('ASSET_SERVER_KEY', None)" \
"\nWEB_ATTACHMENT_COLLECTION = os.getenv('ASSET_SERVER_COLLECTION', None)" \
"\nSEPARATE_WEB_ATTACHMENT_FOLDERS = os.getenv('SEPARATE_WEB_ATTACHMENT_FOLDERS', None)" \
"\nCELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', None)" \
"\nCELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', None)" \
"\nCELERY_TASK_DEFAULT_QUEUE = os.getenv('CELERY_TASK_QUEUE', DATABASE_NAME)" \
"\nANONYMOUS_USER = os.getenv('ANONYMOUS_USER', None)" \
> settings/local_specify_settings.py
RUN echo "import os \nDEBUG = os.getenv('SP7_DEBUG', '').lower() == 'true'\n" \
> settings/debug.py
RUN echo "import os \nSECRET_KEY = os.environ['SECRET_KEY']\n" \
> settings/secret_key.py
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV DJANGO_SETTINGS_MODULE='settings'
ENTRYPOINT ["/opt/specify7/docker-entrypoint.sh"]
EXPOSE 8000
######################################################################
FROM run-common AS run-development
USER root
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
python3.8-distutils \
ca-certificates \
make
USER specify
COPY requirements-testing.txt /home/specify/
#RUN ve/bin/pip install --no-cache-dir -r /home/specify/requirements-testing.txt
COPY mypy.ini ./
######################################################################
FROM run-common AS run
RUN mv specifyweb.wsgi specifyweb_wsgi.py
CMD ["ve/bin/gunicorn", "-w", "3", "-b", "0.0.0.0:8000", "-t", "300", "specifyweb_wsgi"]