From ca9761585ae6d54771459cc0b68e9e0f250d3abf Mon Sep 17 00:00:00 2001 From: Lev Date: Wed, 30 Mar 2022 12:09:09 +0300 Subject: [PATCH] Remove git reference from install-app (#742) * Remove git reference from install-app Also fixed issue with missing sites/assets folder * Update custom app guide according to changes * Ignore apps that have no frontend code instead of failing --- custom_app/README.md | 4 +++- custom_app/backend.Dockerfile | 6 ------ custom_app/frontend.Dockerfile | 6 ------ images/nginx/Dockerfile | 8 ++++---- images/nginx/install-app.sh | 17 ++++++++++------- images/worker/Dockerfile | 6 ++++-- images/worker/install-app.sh | 8 ++------ 7 files changed, 23 insertions(+), 32 deletions(-) diff --git a/custom_app/README.md b/custom_app/README.md index 820ae7bc..d11b55bf 100644 --- a/custom_app/README.md +++ b/custom_app/README.md @@ -41,4 +41,6 @@ Cool! You just containerized your app! ## Installing multiple apps -Both backend and frontend builds contain `install-app` script that places app where it should be. Each call to script installs given app. Usage: `install-app [APP_NAME] [BRANCH?] [GIT_URL?]`. +Both backend and frontend builds contain `install-app` script that places app where it should be. Each call to script installs given app. Usage: `install-app [APP_NAME]`. + +If you want to install an app from git, clone it locally, COPY in Dockerfile. diff --git a/custom_app/backend.Dockerfile b/custom_app/backend.Dockerfile index cc779b1c..3bd32834 100644 --- a/custom_app/backend.Dockerfile +++ b/custom_app/backend.Dockerfile @@ -11,10 +11,4 @@ COPY . ../apps/${APP_NAME} RUN --mount=type=cache,target=/root/.cache/pip \ install-app ${APP_NAME} -# or with git: -# ARG APP_NAME -# ARG BRANCH -# ARG GIT_URL -# RUN install-assets ${APP_NAME} ${BRANCH} ${GIT_URL} - USER frappe diff --git a/custom_app/frontend.Dockerfile b/custom_app/frontend.Dockerfile index 09424c17..205934c7 100644 --- a/custom_app/frontend.Dockerfile +++ b/custom_app/frontend.Dockerfile @@ -7,12 +7,6 @@ ARG APP_NAME COPY . apps/${APP_NAME} RUN install-app ${APP_NAME} -# or with git: -# ARG APP_NAME -# ARG BRANCH -# ARG GIT_URL -# RUN install-app ${APP_NAME} ${BRANCH} ${GIT_URL} - FROM frappe/erpnext-nginx:${ERPNEXT_VERSION} diff --git a/images/nginx/Dockerfile b/images/nginx/Dockerfile index 184dad1d..d5949dd7 100644 --- a/images/nginx/Dockerfile +++ b/images/nginx/Dockerfile @@ -14,10 +14,9 @@ RUN mkdir -p sites/assets /out/assets \ && echo frappe >sites/apps.txt ARG FRAPPE_VERSION -RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe - # Install development node modules -RUN yarn --cwd apps/frappe \ +RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe \ + && 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 @@ -33,7 +32,8 @@ RUN install-app frappe FROM assets_builder as erpnext_assets ARG ERPNEXT_VERSION -RUN install-app erpnext ${ERPNEXT_VERSION} https://github.com/frappe/erpnext +RUN git clone --depth 1 -b ${ERPNEXT_VERSION} https://github.com/frappe/erpnext apps/erpnext \ + && install-app erpnext FROM alpine/git as bench diff --git a/images/nginx/install-app.sh b/images/nginx/install-app.sh index c30a63f3..4d634cf6 100755 --- a/images/nginx/install-app.sh +++ b/images/nginx/install-app.sh @@ -2,13 +2,18 @@ set -e set -x -APP=$1 BRANCH=$2 GIT_URL=$3 +APP=$1 + +cleanup() { + rm -rf "apps/$APP" + rm -rf sites/assets/* +} 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" +if ! test -d "apps/$APP/$APP/public"; then + cleanup + exit 0 fi # Add all not built assets @@ -24,6 +29,4 @@ 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 +cleanup diff --git a/images/worker/Dockerfile b/images/worker/Dockerfile index 00013df9..6f8951cb 100644 --- a/images/worker/Dockerfile +++ b/images/worker/Dockerfile @@ -43,7 +43,8 @@ FROM build_deps as frappe_builder ARG FRAPPE_VERSION RUN --mount=type=cache,target=/root/.cache/pip \ - install-app frappe ${FRAPPE_VERSION} https://github.com/frappe/frappe \ + git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe \ + && install-app frappe \ && env/bin/pip install -U gevent \ # Link Frappe's node_modules/ to make Website Theme work && mkdir -p /home/frappe/frappe-bench/sites/assets/frappe/node_modules \ @@ -54,7 +55,8 @@ FROM frappe_builder as erpnext_builder ARG ERPNEXT_VERSION RUN --mount=type=cache,target=/root/.cache/pip \ - install-app erpnext ${ERPNEXT_VERSION} https://github.com/frappe/erpnext + git clone --depth 1 -b ${ERPNEXT_VERSION} https://github.com/frappe/erpnext apps/erpnext \ + && install-app erpnext FROM base as configured_base diff --git a/images/worker/install-app.sh b/images/worker/install-app.sh index f6fed4e7..93f7b9fc 100755 --- a/images/worker/install-app.sh +++ b/images/worker/install-app.sh @@ -2,15 +2,11 @@ set -e set -x -APP=$1 BRANCH=$2 GIT_URL=$3 +APP=$1 cd /home/frappe/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" - rm -r "apps/$APP/.git" -fi +rm -rf "apps/$APP/.git" env/bin/pip install -e "apps/$APP"