fix(custom): pass base64 encoded apps json

This commit is contained in:
Revant Nandgaonkar 2023-01-01 13:59:51 +05:30
parent 4e96a16ee2
commit b82b5bf583
2 changed files with 23 additions and 14 deletions

View file

@ -24,6 +24,7 @@ export APPS_JSON='[
"branch": "main" "branch": "main"
} }
]' ]'
export APPS_JSON_BASE64=$(echo ${APPS_JSON} | base64 --wrap=0)
``` ```
Note: Note:
@ -38,7 +39,7 @@ buildah build \
--build-arg=FRAPPE_BRANCH=version-14 \ --build-arg=FRAPPE_BRANCH=version-14 \
--build-arg=PYTHON_VERSION=3.10.5 \ --build-arg=PYTHON_VERSION=3.10.5 \
--build-arg=NODE_VERSION=16.18.0 \ --build-arg=NODE_VERSION=16.18.0 \
--build-arg=APPS_JSON=$APPS_JSON \ --build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
--tag=ghcr.io/user/repo/custom:1.0.0 \ --tag=ghcr.io/user/repo/custom:1.0.0 \
--file=images/custom/Containerfile . --file=images/custom/Containerfile .
``` ```
@ -46,9 +47,11 @@ buildah build \
Note: Note:
- Use `docker` instead of `buildah` as per your setup. - Use `docker` instead of `buildah` as per your setup.
- Make sure `APPS_JSON` variable has correct JSON. - `FRAPPE_PATH` and `FRAPPE_BRANCH` build args are optional and can be overridden in case of fork/branch.
- Make sure `APPS_JSON_BASE64` variable has correct base64 encoded JSON string. It is consumed as build arg, base64 encoding ensures it to be friendly with environment variables
- Make sure the `--tag` is valid image name that will be pushed to registry. - Make sure the `--tag` is valid image name that will be pushed to registry.
- Change `--build-arg` as per version of Python, NodeJS, Frappe Framework repo and branch - Change `--build-arg` as per version of Python, NodeJS, Frappe Framework repo and branch
- The final image will have no traces of `.git` directory for any apps including frappe framework.
### Push image to use in yaml files ### Push image to use in yaml files

View file

@ -73,23 +73,29 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# apps.json includes # apps.json includes
ARG APPS_JSON=[] ARG APPS_JSON_BASE64
RUN mkdir /opt/frappe && echo "${APPS_JSON}" | jq . > /opt/frappe/apps.json RUN if [ -n "${APPS_JSON_BASE64}" ]; then \
mkdir /opt/frappe && echo "${APPS_JSON_BASE64}" | base64 -d > /opt/frappe/apps.json; \
fi
USER frappe USER frappe
ARG FRAPPE_BRANCH=version-14 ARG FRAPPE_BRANCH=version-14
ARG FRAPPE_PATH=https://github.com/frappe/frappe ARG FRAPPE_PATH=https://github.com/frappe/frappe
RUN bench init \ RUN export APP_INSTALL_ARGS="" && \
--frappe-branch=${FRAPPE_BRANCH} \ if [ -n "${APPS_JSON_BASE64}" ]; then \
--frappe-path=${FRAPPE_PATH} \ export APP_INSTALL_ARGS="--apps_path=/opt/frappe/apps.json"; \
--no-procfile \ fi && \
--no-backups \ bench init ${APP_INSTALL_ARGS}\
--skip-redis-config-generation \ --frappe-branch=${FRAPPE_BRANCH} \
--verbose \ --frappe-path=${FRAPPE_PATH} \
--skip-assets \ --no-procfile \
--apps_path=/opt/frappe/apps.json \ --no-backups \
/home/frappe/frappe-bench && \ --skip-redis-config-generation \
--verbose \
--skip-assets \
--apps_path=/opt/frappe/apps.json \
/home/frappe/frappe-bench && \
cd /home/frappe/frappe-bench && \ cd /home/frappe/frappe-bench && \
bench setup requirements && \ bench setup requirements && \
find /home/frappe/frappe-bench/apps -mindepth 1 -path "*/.git" | xargs rm -fr find /home/frappe/frappe-bench/apps -mindepth 1 -path "*/.git" | xargs rm -fr