Skip to content

Commit 6bbe302

Browse files
authored
Use user over root for the BE Ddocker image (#4247)
1 parent 7211cfa commit 6bbe302

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

backend/Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,22 @@ ARG FUNCTION_DIR
140140

141141
WORKDIR ${FUNCTION_DIR}
142142

143-
COPY --from=js-stage ${FUNCTION_DIR}/dist/*.html ${FUNCTION_DIR}/custom_admin/templates/astro/
144-
COPY --from=js-stage ${FUNCTION_DIR}/dist/_astro ${FUNCTION_DIR}/custom_admin/static/_astro/
143+
RUN groupadd -r app && useradd -r -g app app && mkdir -p ${FUNCTION_DIR} && chown -R app:app ${FUNCTION_DIR}
145144

146-
COPY --from=build-stage ${FUNCTION_DIR}/.venv ${FUNCTION_DIR}/.venv
145+
COPY --chown=app:app --from=js-stage ${FUNCTION_DIR}/dist/*.html ${FUNCTION_DIR}/custom_admin/templates/astro/
146+
COPY --chown=app:app --from=js-stage ${FUNCTION_DIR}/dist/_astro ${FUNCTION_DIR}/custom_admin/static/_astro/
147+
148+
COPY --chown=app:app --from=build-stage ${FUNCTION_DIR}/.venv ${FUNCTION_DIR}/.venv
147149
COPY --from=build-stage /usr/local/lib/*.so* /usr/local/lib/
148150
COPY --from=build-stage /libs.tar.gz /libs.tar.gz
149151

150152
RUN tar -xvf /libs.tar.gz -C / && rm /libs.tar.gz && ldconfig
151153

152-
RUN mkdir -p ${FUNCTION_DIR}/assets
154+
COPY --chown=app:app . ${FUNCTION_DIR}
153155

154-
COPY . ${FUNCTION_DIR}
156+
USER app
157+
158+
RUN mkdir -p ${FUNCTION_DIR}/assets
155159

156160
ENV DJANGO_SETTINGS_MODULE=pycon.settings.prod
157161

0 commit comments

Comments
 (0)