diff --git a/images/custom/Containerfile b/images/custom/Containerfile index c99ff880..2ecb06d7 100644 --- a/images/custom/Containerfile +++ b/images/custom/Containerfile @@ -146,11 +146,23 @@ COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe WORKDIR /home/frappe/frappe-bench +# Move assets to image-layer storage +RUN cp -r /home/frappe/frappe-bench/sites/assets /home/frappe/frappe-bench/assets && \ + rm -rf /home/frappe/frappe-bench/sites/assets + VOLUME [ \ "/home/frappe/frappe-bench/sites", \ "/home/frappe/frappe-bench/logs" \ ] +USER root +# This entrypoint script link build assets of the image to the mounted sites volume at container initialization +COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +USER frappe +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + CMD [ \ "/home/frappe/frappe-bench/env/bin/gunicorn", \ "--chdir=/home/frappe/frappe-bench/sites", \ diff --git a/images/layered/Containerfile b/images/layered/Containerfile index 0048930f..7482280c 100644 --- a/images/layered/Containerfile +++ b/images/layered/Containerfile @@ -35,11 +35,23 @@ COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe WORKDIR /home/frappe/frappe-bench +# Move assets to image-layer storage +RUN cp -r /home/frappe/frappe-bench/sites/assets /home/frappe/frappe-bench/assets && \ + rm -rf /home/frappe/frappe-bench/sites/assets + VOLUME [ \ "/home/frappe/frappe-bench/sites", \ "/home/frappe/frappe-bench/logs" \ ] +USER root +# This entrypoint script link build assets of the image to the mounted sites volume at container initialization +COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +USER frappe +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + CMD [ \ "/home/frappe/frappe-bench/env/bin/gunicorn", \ "--chdir=/home/frappe/frappe-bench/sites", \ diff --git a/images/production/Containerfile b/images/production/Containerfile index 48df0d9d..f95a9703 100644 --- a/images/production/Containerfile +++ b/images/production/Containerfile @@ -136,11 +136,23 @@ COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe WORKDIR /home/frappe/frappe-bench +# Move assets to image-layer storage +RUN cp -r /home/frappe/frappe-bench/sites/assets /home/frappe/frappe-bench/assets && \ + rm -rf /home/frappe/frappe-bench/sites/assets + VOLUME [ \ "/home/frappe/frappe-bench/sites", \ "/home/frappe/frappe-bench/logs" \ ] +USER root +# This entrypoint script link build assets of the image to the mounted sites volume at container initialization +COPY resources/core/main-entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +USER frappe +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + CMD [ \ "/home/frappe/frappe-bench/env/bin/gunicorn", \ "--chdir=/home/frappe/frappe-bench/sites", \ diff --git a/resources/core/main-entrypoint.sh b/resources/core/main-entrypoint.sh new file mode 100755 index 00000000..d1e89601 --- /dev/null +++ b/resources/core/main-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +ASSETS_PATH="/home/frappe/frappe-bench/sites/assets" +BAKED_PATH="/home/frappe/frappe-bench/assets" + +echo "Linking fresh assets to volume..." +rm -rf "$ASSETS_PATH" +mkdir -p "$(dirname "$ASSETS_PATH")" +ln -s "$BAKED_PATH" "$ASSETS_PATH" + +exec "$@"