forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
160 lines (141 loc) · 4.77 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
FROM python:3.12-alpine3.17 AS base
# Creation of www-data group was removed as it is created by default in alpine 3.14 and higher
# Alpine does not create a www-data user, so we still need to create that. 82 is the standard
# uid/guid for www-data in Alpine.
RUN set -x \
&& adduser -h /var/www -u 82 -D -S -G www-data www-data
RUN apk add --no-cache --virtual .run-deps \
gcc \
g++ \
nodejs \
npm \
yarn \
libxslt-dev \
su-exec \
bash \
git \
libxml2 \
libxslt \
libpq-dev \
libffi \
libffi-dev \
libev \
libevent \
&& yarn global add bower \
&& mkdir -p /var/www \
&& chown www-data:www-data /var/www
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY=1 \
POETRY_VIRTUALENVS_CREATE=0
FROM base AS build
ENV POETRY_VIRTUALENVS_IN_PROJECT=1 \
YARN_CACHE_FOLDER=/tmp/yarn-cache \
POETRY_CACHE_DIR=/tmp/poetry-cache \
POETRY_HOME=/tmp/poetry
RUN python3 -m venv $POETRY_HOME
RUN $POETRY_HOME/bin/pip install poetry==1.8.3
RUN set -ex \
&& apk add --no-cache --virtual .build-deps \
build-base \
linux-headers \
musl-dev \
libxml2-dev \
libxslt-dev \
# cryptography
libffi-dev
WORKDIR /code
COPY pyproject.toml .
COPY poetry.lock .
# Fix: https://github.com/CenterForOpenScience/osf.io/pull/6783
RUN $POETRY_HOME/bin/poetry install --without=dev --no-root --compile
# Settings
COPY ./tasks/ ./tasks/
COPY ./website/settings/ ./website/settings/
COPY ./api/base/settings/ ./api/base/settings/
COPY ./website/__init__.py ./website/__init__.py
COPY ./addons.json ./addons.json
RUN mv ./website/settings/local-dist.py ./website/settings/local.py \
&& mv ./api/base/settings/local-dist.py ./api/base/settings/local.py \
&& sed 's/DEBUG_MODE = True/DEBUG_MODE = False/' -i ./website/settings/local.py
# Bower Assets
COPY ./.bowerrc ./bower.json ./
COPY ./admin/.bowerrc ./admin/bower.json ./admin/
RUN \
# OSF
bower install --production --allow-root \
&& bower cache clean --allow-root \
# Admin
&& cd ./admin \
&& bower install --production --allow-root \
&& bower cache clean --allow-root
# Webpack Assets
#
## OSF
COPY ./package.json ./.yarnrc ./yarn.lock ./
COPY ./webpack* ./
COPY ./website/static/ ./website/static/
## Admin
COPY ./admin/package.json ./admin/yarn.lock ./admin/
COPY ./admin/webpack* ./admin/
COPY ./admin/static/ ./admin/static/
## Addons
COPY ./addons/bitbucket/static/ ./addons/bitbucket/static/
COPY ./addons/boa/static/ ./addons/boa/static/
COPY ./addons/box/static/ ./addons/box/static/
COPY ./addons/citations/static/ ./addons/citations/static/
COPY ./addons/dataverse/static/ ./addons/dataverse/static/
COPY ./addons/dropbox/static/ ./addons/dropbox/static/
COPY ./addons/figshare/static/ ./addons/figshare/static/
COPY ./addons/forward/static/ ./addons/forward/static/
COPY ./addons/github/static/ ./addons/github/static/
COPY ./addons/gitlab/static/ ./addons/gitlab/static/
COPY ./addons/googledrive/static/ ./addons/googledrive/static/
COPY ./addons/mendeley/static/ ./addons/mendeley/static/
COPY ./addons/onedrive/static/ /code/addons/onedrive/static/
COPY ./addons/osfstorage/static/ ./addons/osfstorage/static/
COPY ./addons/owncloud/static/ ./addons/owncloud/static/
COPY ./addons/s3/static/ ./addons/s3/static/
COPY ./addons/twofactor/static/ ./addons/twofactor/static/
COPY ./addons/wiki/static/ ./addons/wiki/static/
COPY ./addons/zotero/static/ ./addons/zotero/static/
RUN \
# OSF
yarn install --frozen-lockfile \
&& mkdir -p ./website/static/built/ \
&& python3 -m invoke build-js-config-files \
&& yarn run webpack-prod \
# Admin
&& cd ./admin \
&& yarn install --frozen-lockfile \
&& yarn run webpack-prod \
&& cd ../ \
# Cleanup
&& yarn cache clean \
&& npm cache clean --force
# Copy the rest of the code over
COPY ./ ./
ARG GIT_COMMIT=
ENV GIT_COMMIT=${GIT_COMMIT}
# TODO: Admin/API should fully specify their bower static deps, and not
# include ./website/static in their defaults.py.
# (this adds an additional 300+mb to the build image)
RUN for module in \
api.base.settings \
admin.base.settings \
; do \
export DJANGO_SETTINGS_MODULE=$module \
&& python3 manage.py collectstatic --noinput --no-init-app \
; done \
&& for file in \
./website/templates/_log_templates.mako \
./website/static/built/nodeCategories.json \
; do \
touch $file && chmod o+w $file \
; done \
&& rm ./website/settings/local.py ./api/base/settings/local.py
FROM base AS runtime
WORKDIR /code
COPY --from=build /usr/local/lib/python3.12 /usr/local/lib/python3.12
COPY --from=build /usr/local/bin /usr/local/bin
COPY --from=build /code /code
CMD ["su-exec", "nobody", "python", "-m", "invoke", "--list"]