From 38266a1971c0e434b798f4d8c00cd1a303a53f25 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Fri, 25 Oct 2024 13:53:28 +0530 Subject: [PATCH] feat: allow layered custom image build speed up build time pull builder image pack built assets into base image --- docker-bake.hcl | 16 +++++++++++ images/layered/Containerfile | 47 +++++++++++++++++++++++++++++++++ images/production/Containerfile | 4 ++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 images/layered/Containerfile diff --git a/docker-bake.hcl b/docker-bake.hcl index f2a9fc70b9..db6d9ac080 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -91,3 +91,19 @@ target "erpnext" { target = "erpnext" tags = tag("erpnext", "${ERPNEXT_VERSION}") } + +target "base" { + inherits = ["default-args"] + context = "." + dockerfile = "images/production/Containerfile" + target = "base" + tags = tag("base", "${FRAPPE_VERSION}") +} + +target "build" { + inherits = ["default-args"] + context = "." + dockerfile = "images/production/Containerfile" + target = "build" + tags = tag("build", "${FRAPPE_VERSION}") +} diff --git a/images/layered/Containerfile b/images/layered/Containerfile new file mode 100644 index 0000000000..c2656ade3b --- /dev/null +++ b/images/layered/Containerfile @@ -0,0 +1,47 @@ +ARG FRAPPE_BRANCH=version-15 +ARG FRAPPE_PATH=https://github.com/frappe/frappe + +FROM frappe/build:${FRAPPE_BRANCH} AS builder + +RUN export APP_INSTALL_ARGS="" && \ + if [ -n "${APPS_JSON_BASE64}" ]; then \ + export APP_INSTALL_ARGS="--apps_path=/opt/frappe/apps.json"; \ + fi && \ + bench init ${APP_INSTALL_ARGS}\ + --frappe-branch=${FRAPPE_BRANCH} \ + --frappe-path=${FRAPPE_PATH} \ + --no-procfile \ + --no-backups \ + --skip-redis-config-generation \ + --verbose \ + /home/frappe/frappe-bench && \ + cd /home/frappe/frappe-bench && \ + echo "{}" > sites/common_site_config.json && \ + find apps -mindepth 1 -path "*/.git" | xargs rm -fr + +FROM frappe/base:${FRAPPE_BRANCH} AS backend + +USER frappe + +COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe/frappe-bench + +WORKDIR /home/frappe/frappe-bench + +VOLUME [ \ + "/home/frappe/frappe-bench/sites", \ + "/home/frappe/frappe-bench/sites/assets", \ + "/home/frappe/frappe-bench/logs" \ +] + +CMD [ \ + "/home/frappe/frappe-bench/env/bin/gunicorn", \ + "--chdir=/home/frappe/frappe-bench/sites", \ + "--bind=0.0.0.0:8000", \ + "--threads=4", \ + "--workers=2", \ + "--worker-class=gthread", \ + "--worker-tmp-dir=/dev/shm", \ + "--timeout=120", \ + "--preload", \ + "frappe.app:application" \ +] diff --git a/images/production/Containerfile b/images/production/Containerfile index fddfdeaf30..78c80f73ae 100644 --- a/images/production/Containerfile +++ b/images/production/Containerfile @@ -70,7 +70,7 @@ RUN useradd -ms /bin/bash frappe \ COPY resources/nginx-template.conf /templates/nginx/frappe.conf.template COPY resources/nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh -FROM base AS builder +FROM base AS build RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ @@ -98,6 +98,8 @@ RUN apt-get update \ USER frappe +FROM build AS builder + ARG FRAPPE_BRANCH=version-15 ARG FRAPPE_PATH=https://github.com/frappe/frappe ARG ERPNEXT_REPO=https://github.com/frappe/erpnext