mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-27 17:25:08 +00:00
Add build-assets script for simpler frontend build
This commit is contained in:
parent
eba7e7ab46
commit
051b196885
2 changed files with 51 additions and 52 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:14-bullseye-slim as base
|
FROM node:14-bullseye-slim as assets_builder
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
||||||
|
|
@ -8,85 +8,55 @@ RUN apt-get update \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /root/frappe-bench
|
WORKDIR /frappe-bench
|
||||||
RUN mkdir -p sites/assets
|
|
||||||
|
RUN mkdir -p sites/assets /out/assets \
|
||||||
|
&& echo frappe >sites/apps.txt
|
||||||
|
|
||||||
ARG FRAPPE_VERSION
|
ARG FRAPPE_VERSION
|
||||||
RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe
|
RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM base as frappe_prod_node_modules
|
|
||||||
|
|
||||||
# Install production node modules
|
|
||||||
RUN yarn --cwd apps/frappe --prod
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM frappe_prod_node_modules as assets_builder
|
|
||||||
|
|
||||||
# Install development node modules
|
# Install development node modules
|
||||||
RUN yarn --cwd apps/frappe
|
RUN yarn --cwd apps/frappe \
|
||||||
|
# TODO: Currently `yarn run production` doesn't create .build on develop branch: https://github.com/frappe/frappe/issues/15396
|
||||||
|
&& if [ ! -f sites/.build ]; then touch sites/.build; fi \
|
||||||
|
&& cp sites/.build /out
|
||||||
|
|
||||||
|
COPY build-assets.sh /usr/local/bin/build-assets
|
||||||
|
|
||||||
|
|
||||||
FROM assets_builder as frappe_assets
|
FROM assets_builder as frappe_assets
|
||||||
|
|
||||||
# Build assets they're stored in frappe-bench/sites/assets
|
RUN build-assets frappe
|
||||||
RUN echo "frappe" >sites/apps.txt \
|
|
||||||
&& yarn --cwd apps/frappe run production \
|
|
||||||
&& rm sites/apps.txt \
|
|
||||||
# TODO: Currently `yarn run production` doesn't create .build on develop branch: https://github.com/frappe/frappe/issues/15396
|
|
||||||
&& if [ ! -f sites/.build ]; then touch sites/.build; fi
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM assets_builder as erpnext_assets
|
||||||
FROM base as erpnext_prod_node_modules
|
|
||||||
|
|
||||||
ARG ERPNEXT_VERSION
|
ARG ERPNEXT_VERSION
|
||||||
RUN git clone --depth 1 -b ${ERPNEXT_VERSION} https://github.com/frappe/erpnext apps/erpnext
|
RUN build-assets erpnext ${ERPNEXT_VERSION} https://github.com/frappe/erpnext
|
||||||
|
|
||||||
RUN yarn --cwd apps/erpnext --prod
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine/git as bench
|
||||||
|
|
||||||
FROM erpnext_prod_node_modules as erpnext_assets
|
# Error pages
|
||||||
|
RUN git clone --depth 1 https://github.com/frappe/bench /tmp/bench \
|
||||||
RUN yarn --cwd apps/erpnext
|
&& mkdir /out \
|
||||||
|
&& mv /tmp/bench/bench/config/templates/502.html /out/
|
||||||
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 echo "frappe\nerpnext" >sites/apps.txt \
|
|
||||||
&& yarn --cwd apps/frappe run production --app erpnext \
|
|
||||||
&& rm sites/apps.txt
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM base as error_pages
|
|
||||||
|
|
||||||
RUN git clone --depth 1 https://github.com/frappe/bench /root/bench
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM nginxinc/nginx-unprivileged:1.21.6-alpine as frappe
|
FROM nginxinc/nginx-unprivileged:1.21.6-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
|
|
||||||
|
|
||||||
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/20-envsubst-on-templates.sh
|
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/20-envsubst-on-templates.sh
|
||||||
COPY nginx-template.conf /etc/nginx/templates/default.conf.template
|
COPY nginx-template.conf /etc/nginx/templates/default.conf.template
|
||||||
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/docker-entrypoint.sh
|
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/docker-entrypoint.sh
|
||||||
COPY entrypoint.sh /docker-entrypoint.d/frappe-entrypoint.sh
|
COPY entrypoint.sh /docker-entrypoint.d/frappe-entrypoint.sh
|
||||||
|
|
||||||
USER 1000
|
COPY --from=bench /out /usr/share/nginx/html/
|
||||||
|
COPY --from=frappe_assets /out /usr/share/nginx/html
|
||||||
|
|
||||||
|
USER 1000
|
||||||
|
|
||||||
|
|
||||||
FROM frappe as erpnext
|
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_assets /out /usr/share/nginx/html
|
||||||
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
|
|
||||||
|
|
|
||||||
29
images/nginx/build-assets.sh
Executable file
29
images/nginx/build-assets.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
|
||||||
|
APP=$1 BRANCH=$2 GIT_URL=$3
|
||||||
|
|
||||||
|
cd /frappe-bench
|
||||||
|
|
||||||
|
if test "$BRANCH" && test "$GIT_URL"; then
|
||||||
|
# Clone in case not copied manually
|
||||||
|
git clone --depth 1 -b "$BRANCH" "$GIT_URL" "apps/$APP"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add all not built assets
|
||||||
|
cp -r "apps/$APP/$APP/public" "/out/assets/$APP"
|
||||||
|
|
||||||
|
# Add production node modules
|
||||||
|
yarn --cwd "apps/$APP" --prod
|
||||||
|
cp -r "apps/$APP/node_modules" "/out/assets/$APP/node_modules"
|
||||||
|
|
||||||
|
# Add built assets
|
||||||
|
yarn --cwd "apps/$APP"
|
||||||
|
echo "$APP" >>sites/apps.txt
|
||||||
|
yarn --cwd apps/frappe run production --app "$APP"
|
||||||
|
cp -r sites/assets /out
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -rf "apps/$APP"
|
||||||
|
rm -rf sites/assets
|
||||||
Loading…
Reference in a new issue