@@ -11,25 +11,25 @@ ARG STAGE=production
1111COPY ./requirements /requirements
1212# install build dependencies
1313RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
14- apk update \
15- && apk add --no-cache build-base \
16- # psycopg2 dependencies
17- && apk add --no-cache --virtual build-deps gcc python3-dev musl-dev \
18- && apk add --no-cache postgresql-dev \
19- # Pillow dependencies
20- && apk add --no-cache jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
21- # CFFI dependencies
22- && apk add --no-cache libffi-dev py-cffi \
23- # XLSX dependencies
24- && apk add --no-cache libxml2-dev libxslt-dev \
25- # Rust and Cargo required by the ``cryptography`` Python package - only required during build
26- && apk add --no-cache rust \
27- && apk add --no-cache cargo \
28- # && pip install -r /requirements/${STAGE}.txt \
29- # build wheels
30- && pip install wheel && pip wheel --wheel-dir=/tmp/wheels -r /requirements/${STAGE}.txt \
31- # remove the virtual package group 'build-deps'
32- && apk del build-deps
14+ apk update \
15+ && apk add --no-cache build-base \
16+ # psycopg2 dependencies
17+ && apk add --no-cache --virtual build-deps gcc python3-dev musl-dev \
18+ && apk add --no-cache postgresql-dev \
19+ # Pillow dependencies
20+ && apk add --no-cache jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
21+ # CFFI dependencies
22+ && apk add --no-cache libffi-dev py-cffi \
23+ # XLSX dependencies
24+ && apk add --no-cache libxml2-dev libxslt-dev \
25+ # Rust and Cargo required by the ``cryptography`` Python package - only required during build
26+ && apk add --no-cache rust \
27+ && apk add --no-cache cargo \
28+ # && pip install -r /requirements/${STAGE}.txt \
29+ # build wheels
30+ && pip install wheel && pip wheel --wheel-dir=/tmp/wheels -r /requirements/${STAGE}.txt \
31+ # remove the virtual package group 'build-deps'
32+ && apk del build-deps
3333# ---------------------------------------------
3434# END build image stage
3535# ---------------------------------------------
@@ -48,38 +48,38 @@ ENV PYTHONPATH="$PYTHONPATH:/app/config"
4848ARG USER_UID=1000
4949ARG USER_GID=$USER_UID
5050RUN if [ -n "$(getent group ${USER_GID})" ]; \
51- then \
52- apk --no-cache add shadow; \
53- groupmod -n "django" "${USER_GID}" ; \
54- else \
55- addgroup --gid "${USER_GID}" "django" ; \
56- fi && \
57- if [ -n "$(getent passwd ${USER_UID})" ]; \
58- then \
59- apk --no-cache add shadow; \
60- usermod -l "django" -g "${USER_GID}" -d "/app" ; \
61- else \
62- adduser \
63- --home "/app" \
64- --gecos "MAIL_DIR=/dev/null" \
65- --shell /bin/ash \
66- --ingroup "django" \
67- --system \
68- --disabled-password \
69- --no-create-home \
70- --uid "${USER_UID}" \
71- "django" ; \
72- fi
51+ then \
52+ apk --no-cache add shadow; \
53+ groupmod -n "django" "${USER_GID}" ; \
54+ else \
55+ addgroup --gid "${USER_GID}" "django" ; \
56+ fi && \
57+ if [ -n "$(getent passwd ${USER_UID})" ]; \
58+ then \
59+ apk --no-cache add shadow; \
60+ usermod -l "django" -g "${USER_GID}" -d "/app" ; \
61+ else \
62+ adduser \
63+ --home "/app" \
64+ --gecos "MAIL_DIR=/dev/null" \
65+ --shell /bin/ash \
66+ --ingroup "django" \
67+ --system \
68+ --disabled-password \
69+ --no-create-home \
70+ --uid "${USER_UID}" \
71+ "django" ; \
72+ fi
7373
7474# install runtime dependencies. `add --no-cache` performs an apk update, adds packages and excludes caching
7575# in order to not require deletion of apk cache.
7676RUN apk add --no-cache postgresql-dev \
77- # Pillow dependencies
78- jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
79- # CFFI dependencies
80- libffi-dev py-cffi \
81- # XLSX dependencies
82- libxml2-dev libxslt-dev
77+ # Pillow dependencies
78+ jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
79+ # CFFI dependencies
80+ libffi-dev py-cffi \
81+ # XLSX dependencies
82+ libxml2-dev libxslt-dev
8383
8484# ensure that we are using the same requirements from the build stage
8585COPY --from=build /requirements /tmp/requirements
@@ -88,11 +88,11 @@ COPY --from=build /requirements /tmp/requirements
8888
8989# combine build and ${STAGE}.txt - remove --no-binary to installing our own wheels
9090RUN --mount=type=bind,target=/tmp/wheels,source=/tmp/wheels,from=build \
91- --mount=type=cache,mode=0755,target=/root/.cache/pip \
92- du -shc /tmp/wheels \
93- && ( cat /tmp/requirements/base.txt; sed -e 's/--no-binary.*//' -e 's/^-r .*//' /tmp/requirements/${STAGE}.txt ) | tee /tmp/requirements.txt >/dev/null \
94- && pip install --find-links=/tmp/wheels -r /tmp/requirements.txt \
95- && rm -rf /tmp/requirements /tmp/requirements.txt
91+ --mount=type=cache,mode=0755,target=/root/.cache/pip \
92+ du -shc /tmp/wheels \
93+ && ( cat /tmp/requirements/base.txt; sed -e 's/--no-binary.*//' -e 's/^-r .*//' /tmp/requirements/${STAGE}.txt ) | tee /tmp/requirements.txt >/dev/null \
94+ && pip install --find-links=/tmp/wheels -r /tmp/requirements.txt \
95+ && rm -rf /tmp/requirements /tmp/requirements.txt
9696# ---------------------------------------------
9797# END django image stage
9898# ---------------------------------------------
@@ -106,18 +106,17 @@ FROM django as django-production
106106COPY --chown=django . /app
107107
108108# copy the entrypoint and run scripts
109- RUN cp -ap /app/compose/django/entrypoint /entrypoint \
110- && cp -vap /app/compose/django/start /start \
111- && cp -vap /app/compose/django/queue/start /start-queue \
112- && cp -vap /app/compose/django/seed_data /seed_data \
113- && chmod -v 0755 /entrypoint /start /start-queue /seed_data \
114- # remove all carriage returns in the case that a user checks out the files on a windows system
115- # and has their git core.eol set to native or crlf
116- && sed -i 's/\r $//g' /entrypoint /start /start-queue /seed_data \
117- # due to volumes mounted to these locations we must created and set the ownership of the underlying directory
118- # so that it is correctly propagated to the named volume
119- && mkdir -p "/app/ghostwriter/media" "/app/staticfiles" \
120- && chown -R "django" : "/app/ghostwriter/media" "/app/staticfiles"
109+ RUN for target in /app/compose/django/*; \
110+ do ln "$target" /"$(basename " $target")" \
111+ && chmod +X /"$(basename " $target")" \
112+ # remove all carriage returns in the case that a user checks out the files on a windows system
113+ # and has their git core.eol set to native or crlf
114+ && sed -i 's/\r $//g' /entrypoint /start /seed_data; \
115+ done \
116+ # due to volumes mounted to these locations we must created and set the ownership of the underlying directory
117+ # so that it is correctly propagated to the named volume
118+ && mkdir -p "/app/ghostwriter/media" "/app/staticfiles" \
119+ && chown -R "django" : "/app/ghostwriter/media" "/app/staticfiles"
121120# ---------------------------------------------
122121# END production stage
123122# ---------------------------------------------
@@ -128,21 +127,17 @@ RUN cp -ap /app/compose/django/entrypoint /entrypoint \
128127FROM django as django-local
129128
130129# add our application
131- COPY --chown=django ./compose/django/entrypoint /entrypoint
132- COPY --chown=django ./compose/django/start-dev /start
133- COPY --chown=django ./compose/django/queue/start /start-queue
134- COPY --chown=django ./compose/django/seed_data /seed_data
135-
130+ COPY --chown=django ./compose/django/ /
136131
137132# copy the entrypoint and run scripts
138- RUN chmod -v 0755 /entrypoint /start /start-queue / seed_data \
139- # remove all carriage returns in the case that a user checks out the files on a windows system
140- # and has their git core.eol set to native or crlf
141- && sed -i 's/\r $//g' /entrypoint /start /start-queue /seed_data \
142- # due to volumes mounted to these locations we must created and set the ownership of the underlying directory
143- # so that it is correctly propagated to the named volume
144- && mkdir -p "/app/ghostwriter/media" "/app/staticfiles" \
145- && chown -R "django" : "/app/ghostwriter/media" "/app/staticfiles"
133+ RUN chmod -v 0755 /entrypoint /start /seed_data \
134+ # remove all carriage returns in the case that a user checks out the files on a windows system
135+ # and has their git core.eol set to native or crlf
136+ && sed -i 's/\r $//g' /entrypoint /start /seed_data \
137+ # due to volumes mounted to these locations we must created and set the ownership of the underlying directory
138+ # so that it is correctly propagated to the named volume
139+ && mkdir -p "/app/ghostwriter/media" "/app/staticfiles" \
140+ && chown -R "django" : "/app/ghostwriter/media" "/app/staticfiles"
146141# ---------------------------------------------
147142# END local stage
148143# ---------------------------------------------
0 commit comments