From 36f58c593786e2642631cc05c80e7738361e7b39 Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Thu, 16 Dec 2021 21:41:31 +0300 Subject: [PATCH] Clean up nginx dockerfile --- build/nginx/Dockerfile | 61 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/build/nginx/Dockerfile b/build/nginx/Dockerfile index 43cf066a..ac236016 100644 --- a/build/nginx/Dockerfile +++ b/build/nginx/Dockerfile @@ -9,61 +9,57 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* WORKDIR /root/frappe-bench -RUN mkdir -p apps sites/assets/frappe +RUN mkdir -p sites/assets ARG FRAPPE_VERSION -RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe \ - && echo "frappe" >sites/apps.txt - -WORKDIR /root/frappe-bench/apps/frappe +RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe -FROM base as frappe_node_modules -RUN yarn --prod +FROM base as frappe_prod_node_modules + +# Install production node modules +RUN yarn --cwd apps/frappe --prod -FROM frappe_node_modules as frappe_assets -RUN if [ "$(uname -m)" = "aarch64" ]; then \ +FROM frappe_prod_node_modules as frappe_assets + +# Install development node modules +RUN cd apps/frappe && \ + if [ "$(uname -m)" = "aarch64" ]; then \ yarn remove svg-sprite || true \ && yarn add sass; \ fi \ && yarn -RUN yarn run production \ - && cp -R frappe/public/* ../../sites/assets/frappe \ - && rm ../../sites/apps.txt - -# Get rid of development node modules -COPY --from=frappe_node_modules /root/frappe-bench/apps/frappe/node_modules /root/frappe-bench/sites/assets/frappe/ +# Build assets stored in frappe-bench/sites/assets +RUN echo "frappe" >sites/apps.txt \ + && yarn --cwd apps/frappe run production \ + && rm sites/apps.txt -FROM base as erpnext_node_modules + +FROM base as erpnext_prod_node_modules ARG ERPNEXT_VERSION -RUN cd ../.. \ - && git clone --depth 1 -b ${ERPNEXT_VERSION} https://github.com/frappe/erpnext apps/erpnext \ - && echo "frappe\nerpnext" >sites/apps.txt +RUN git clone --depth 1 -b ${ERPNEXT_VERSION} https://github.com/frappe/erpnext apps/erpnext -RUN yarn --cwd ../erpnext --prod +RUN yarn --cwd apps/erpnext --prod -FROM erpnext_node_modules as erpnext_assets -RUN mkdir -p ../../sites/assets/erpnext -RUN yarn --cwd ../erpnext +FROM erpnext_prod_node_modules as erpnext_assets + +RUN yarn --cwd apps/erpnext -# Reuse development node_modules from frappe_assets COPY --from=frappe_assets /root/frappe-bench/apps/frappe/node_modules /root/frappe-bench/apps/frappe/node_modules COPY --from=frappe_assets /root/frappe-bench/apps/frappe/package.json /root/frappe-bench/apps/frappe/yarn.lock /root/frappe-bench/apps/frappe/ -RUN yarn run production --app erpnext \ - && cp -R ../erpnext/erpnext/public/* ../../sites/assets/erpnext \ - && rm ../../sites/apps.txt +RUN echo "frappe\nerpnext" >sites/apps.txt \ + && yarn --cwd apps/frappe run production --app erpnext \ + && rm sites/apps.txt -# Get rid of development node modules -COPY --from=erpnext_node_modules /root/frappe-bench/apps/erpnext/node_modules /root/frappe-bench/apps/erpnext/node_modules FROM base as error_pages @@ -71,15 +67,22 @@ FROM base as error_pages RUN git clone --depth 1 https://github.com/frappe/bench /root/bench + FROM nginx:1.21-alpine as frappe COPY --from=error_pages /root/bench/bench/config/templates/502.html /usr/share/nginx/html +COPY --from=base /root/frappe-bench/apps/frappe/frappe/public /usr/share/nginx/html/assets/frappe +COPY --from=frappe_prod_node_modules /root/frappe-bench/apps/frappe/node_modules /usr/share/nginx/html/assets/frappe/node_modules COPY --from=frappe_assets /root/frappe-bench/sites /usr/share/nginx/html + COPY nginx-template.conf / CMD [ "/bin/sh" , "-c" , "envsubst '${BACKEND} ${SOCKETIO} ${FRAPPE_SITE_NAME_HEADER}' /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" ] + FROM frappe as erpnext +COPY --from=erpnext_prod_node_modules /root/frappe-bench/apps/erpnext/erpnext/public /usr/share/nginx/html/assets/erpnext +COPY --from=erpnext_prod_node_modules /root/frappe-bench/apps/erpnext/node_modules /usr/share/nginx/html/assets/erpnext/node_modules COPY --from=erpnext_assets /root/frappe-bench/sites /usr/share/nginx/html