From d23a90e765514d6d5fcec604e939877b4bb89286 Mon Sep 17 00:00:00 2001 From: Nj Subedi Date: Wed, 4 Jan 2023 21:53:30 +0545 Subject: [PATCH] run cloudron redis; run services as normal user; support updating apps --- CloudronManifest.json | 6 +- Dockerfile | 177 +++++++----------- README.md | 94 ++++++++-- dev-scripts/docker-run.sh | 8 +- nginx.conf | 47 +++++ start.sh | 138 ++++++-------- supervisor/app-nginx.conf | 8 + .../supervisord.conf | 3 +- 8 files changed, 266 insertions(+), 215 deletions(-) create mode 100644 nginx.conf create mode 100644 supervisor/app-nginx.conf rename supervisord.conf => supervisor/supervisord.conf (92%) diff --git a/CloudronManifest.json b/CloudronManifest.json index 283adc5..fe13a12 100644 --- a/CloudronManifest.json +++ b/CloudronManifest.json @@ -1,5 +1,6 @@ { "manifestVersion": 2, + "minBoxVersion": "7.3.3", "id": "com.erpnext.cloudronapp", "website": "https://www.erpnext.com", "contactEmail": "support@erpnext.com", @@ -12,12 +13,13 @@ "changelog": "file://manifest/CHANGELOG.md", "postInstallMessage": "file://manifest/POSTINSTALL.md", "healthCheckPath": "/", - "httpPort": 80, + "httpPort": 8888, "memoryLimit": 4294967296, + "multiDomain": true, "addons": { "localstorage": {}, "recvmail": {}, - "sendmail": {}, + "sendmail": { "supportsDisplayName": true }, "ldap": {}, "redis": { "noPassword": true diff --git a/Dockerfile b/Dockerfile index 8340f40..46f7526 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,148 +1,99 @@ -FROM cloudron/base:3.2.0@sha256:ba1d566164a67c266782545ea9809dc611c4152e27686fd14060332dd88263ea +FROM cloudron/base:4.0.0@sha256:31b195ed0662bdb06a6e8a5ddbedb6f191ce92e8bee04c03fb02dd4e9d0286df # Create all necessary directories -# Get rid of the `cmdtest` package that has a command called `yarn`. it conflicts with npm's `yarn` command -# Remove unnecessary database and php packages (takes some time) -# install mariadb-10.3, redis-server and required python3 packages -RUN mkdir -p /app/code /app/data/{frappe-bench,db} /run/{logs} \ - && apt-get remove -y --purge cmdtest mongodb-* postgresql-* *mysql* *mariadb* \ +RUN mkdir -p /app/code /app/data/{frappe-bench,mariadb} \ + && chown -R cloudron:cloudron /app/code /app/data + +WORKDIR /app/code/frappe-bench + +# Remove unnecessary database and php packages (takes some time) +# install mariadb (10.6 default), python (3.10 default) and required python3 packages +RUN apt-get remove -y --purge mongodb-* postgresql-* *mysql* *mariadb* \ && sudo rm -rf /etc/mysql /var/lib/mysql \ && apt-get -y autoremove \ && apt-get -y autoclean \ - && sed -i 's/archive.ubuntu.com/ubuntu.ntc.net.np/g' /etc/apt/sources.list \ - && add-apt-repository ppa:deadsnakes/ppa \ && apt-get -y update \ && apt-get install -y --reinstall --fix-missing \ - wkhtmltopdf \ - xvfb \ - libfontconfig\ - redis-server\ - python3-setuptools\ - python3.10\ - python3.10-dev\ - python3.10-venv\ - uwsgi-plugin-python3\ - python3-pip\ - python3-venv\ - python3.10-distutils\ + wkhtmltopdf xvfb libfontconfig fonts-cantarell xfonts-75dpi xfonts-base \ + python3-setuptools python3 python3-dev python3-pip python3-venv python3-distutils uwsgi-plugin-python3 \ libssl-dev\ - fonts-cantarell\ - xfonts-75dpi\ - xfonts-base - -RUN wget -O /tmp/mariadb_repo_setup https://downloads.mariadb.com/MariaDB/mariadb_repo_setup && \ - chmod +x /tmp/mariadb_repo_setup && \ - sudo /tmp/mariadb_repo_setup --mariadb-server-version="mariadb-10.6" && \ - sudo apt install -y mariadb-server mariadb-backup - -# If we don't install python 3.10, some python functions won't work. -# remove this block to see them. -RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 \ - && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2 \ - && update-alternatives --set python3 /usr/bin/python3.10 - -# Not sure if this is required -RUN chown -R 1000:1000 /app/code + mariadb-server mariadb-backup\ + && pip3 install frappe-bench -# Cannot install python packages as root user -USER cloudron +ARG FRAPPE_VERSION=v14.21.0 -# pip module throws error in source code without this thing! AGAIN! -RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 - -# RUN pip3 install won't work. python code throws errors -RUN python3.10 -m pip install --upgrade wheel \ - && python3.10 -m pip install --upgrade setuptools pip distlib - -# This is required because w'er going to install frappe-bench in the ~/.local/bin directory, and running it later -ENV PATH /home/cloudron/.local/bin:$PATH - -# frappe-bench will be installed in the ~/.local/.bin directory because of limited permission. -RUN chown -R cloudron:cloudron /app/code/ \ - && python3.10 -m pip install frappe-bench \ - && echo "export PATH=/home/cloudron/.local/bin:\$PATH" >>/home/cloudron/.bashrc \ - && echo "export BENCH_DEVELOPER=0" >>/home/cloudron/.bashrc +RUN chown -R 1000:1000 /app/code # Initialize frappe-bench, whatever it means. -RUN bench init --verbose --frappe-branch version-14 --ignore-exist --python /usr/bin/python3 /app/code/frappe-bench - -# If we run any command outside this directory, it simple FAILS. -WORKDIR /app/code/frappe-bench - -# We have to specify the specific version of erpnext. The payments and hrms don't have tagged versions. -RUN bench get-app --branch develop payments \ - && bench get-app --branch develop hrms \ - && bench get-app --branch version-14 erpnext - -# Required if we later switched to external database; for now we're settling with local mysqld.sock -# RUN jq '.db_host = "127.0.0.1"' /app/code/frappe-bench/sites/common_site_config.json > /tmp/jqtmp \ -# && mv /tmp/jqtmp /app/code/frappe-bench/sites/common_site_config.json - -# Need root access for installing mysql; there could be other ways but it works -USER root +RUN /usr/local/bin/gosu cloudron:cloudron bench init --verbose \ + --frappe-branch ${FRAPPE_VERSION} \ + --skip-redis-config-generation \ + --ignore-exist \ + --python /usr/bin/python3 \ + /app/code/frappe-bench + +# [1]This is a standard procedure for Cloudron to move existing "data" somewhere else, +# and put a symlink to /app/data from the original location; on first run, we copy +# files from -orig to /app/data/, which in turn points to the actual files. +# anyone who has packaged an app would know this practice. -COPY supervisord.conf /etc/supervisor/supervisord.conf +# Move the folders that frappe would pollute with writes at runtime. +RUN mkdir -p /app/data/frappe \ + && mv /app/code/frappe-bench/sites /app/code/frappe-bench/sites-orig \ + && ln -sf /app/data/frappe/sites /app/code/frappe-bench/sites \ + \ + && mv /app/code/frappe-bench/env /app/code/frappe-bench/env-orig \ + && ln -sf /app/data/frappe/env /app/code/frappe-bench/env \ + \ + && mv /app/code/frappe-bench/config /app/code/frappe-bench/config-orig \ + && ln -sf /app/data/frappe/config /app/code/frappe-bench/config \ + \ + && mv /app/code/frappe-bench/apps /app/code/frappe-bench/apps-orig \ + && ln -sf /app/data/frappe/apps /app/code/frappe-bench/apps \ + \ + && mv /app/code/frappe-bench/logs /app/code/frappe-bench/logs-orig \ + && ln -sf /run/frappe/logs /app/code/frappe-bench/logs \ + \ + && mv /app/code/frappe-bench/patches.txt /app/code/frappe-bench/patches-orig.txt \ + && ln -sf /app/data/frappe/patches.txt /app/code/frappe-bench/patches.txt -# Basically move config to proper location (see below for details[1]) -RUN mkdir -p /run/supervisor/{logs} \ - && sudo ln -s /run/supervisor/logs/supervisord.log /var/log/supervisor/supervisord.log \ - && sudo ln -s /app/data/frappe/config/supervisor.conf /etc/supervisor/conf.d/frappe-bench.conf \ - && sudo ln -s /app/data/frappe/config/supervisor-app-nginx.conf /etc/supervisor/conf.d/app-nginx.conf \ - && sudo ln -s /app/data/frappe/config/nginx.conf /etc/nginx/sites-enabled/cloudron-erpnext.conf -# Add our custom mysql/mariadb configuration +# Add our custom mysql/mariadb configuration and run commands Equivalent of mysql_sercure_installation ADD mysql_custom.cnf /etc/mysql/conf.d/ -# Equivalent of mysql_sercure_installation -# PS: Root password is essential for Frappe; won't take empty password # If there's a better way to kill the mysqld process, replace `mysqladmin -uroot -proot shutdown`. -RUN sudo sudo mysqld_safe & \ - sleep 5 \ +# Note: a single sign & below is to send mysqld_safe command to background. Do not change it to double &&. +RUN sudo mysqld_safe & \ + sleep 10 \ && mysql -uroot -v -e "DELETE FROM mysql.user WHERE user=''" \ && mysql -uroot -v -e "DELETE FROM mysql.user WHERE user='root' AND host NOT IN ('localhost', '127.0.0.1', '::1')" \ && mysql -uroot -v -e "DROP DATABASE IF EXISTS test" \ && mysql -uroot -v -e "DELETE FROM mysql.db WHERE db='test' OR db='test\\_%'" \ && mysql -uroot -v -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');" \ && mysql -uroot -v -e "FLUSH PRIVILEGES;" \ - && mysqladmin -uroot -proot shutdown - -# [1]This is a standard procedure for Cloudron to move existing "data" somewhere else, \ -# and put a symlink to /app/data from the original location; on first run, we copy -# files from -orig to /app/data/, which in turn points to the actual files. -# anyone who has packaged an app would know this practice. -RUN mkdir -p /app/data/mariadb \ + && mysqladmin -uroot -proot shutdown \ + && mkdir -p /app/data/mariadb \ && mkdir -p /run/mysqld/logs \ - && ls -la /var/log \ && mv /var/lib/mysql /var/lib/mysql-orig \ && mv /var/log/mysql /var/log/mysql-orig \ && ln -sf /app/data/mariadb /var/lib/mysql \ && ln -sf /run/mysqld/logs /var/log/mysql -RUN mkdir -p /app/data/redis /run/redis/logs \ - && mv /etc/redis /etc/redis-orig \ - && ln -sf /app/data/redis /etc/redis +COPY supervisor/ /etc/supervisor/ -RUN mkdir -p /run/nginx/ \ - && rm -r /var/lib/nginx && ln -sf /run/nginx /var/lib/nginx \ - && rm -r /var/log/nginx && ln -sf /run/nginx/logs /var/log/nginx \ - && rm -f /etc/nginx/sites-available/default && rm -f /etc/nginx/sites-enabled/default \ - && sed -i 's|pid /run/nginx.pid;|pid /run/nginx/nginx.pid;|g' /etc/nginx/nginx.conf +RUN mkdir -p /run/supervisor/{logs} \ + && sudo ln -s /run/supervisor/logs/supervisord.log /var/log/supervisor/supervisord.log \ + \ + && rm /etc/nginx/sites-enabled/* \ + && ln -sf /run/nginx/access.log /var/log/nginx/access.log \ + && ln -sf /run/nginx/error.log /var/log/nginx/error.log \ + && ln -s /app/data/frappe/config/nginx.conf /etc/nginx/sites-enabled/frappe -# Same thing, but for the folders that frappe would pollute with writes -RUN mkdir -p /app/data/frappe \ - && rm -rf /app/code/frappe-bench/apps/erpnext/.git \ - && rm -rf /app/code/frappe-bench/apps/payments/.git \ - && rm -rf /app/code/frappe-bench/apps/frappe/.git \ - && mv /app/code/frappe-bench/sites /app/code/frappe-bench/sites-orig \ - && mv /app/code/frappe-bench/config /app/code/frappe-bench/config-orig \ - && mv /app/code/frappe-bench/apps /app/code/frappe-bench/apps-orig \ - && mv /app/code/frappe-bench/logs /app/code/frappe-bench/logs-orig \ - && ln -sf /app/data/frappe/sites /app/code/frappe-bench/sites \ - && ln -sf /app/data/frappe/config /app/code/frappe-bench/config \ - && ln -sf /app/data/frappe/apps /app/code/frappe-bench/apps \ - && ln -sf /app/data/frappe/logs /app/code/frappe-bench/logs +RUN ln -sf /run/.yarnrc /home/cloudron/.yarnrc + +COPY nginx.conf setup-ldap.sh start.sh /app/pkg/ -ADD start.sh setup-ldap.sh /app/code/ +ENV ERPNEXT_VERSION=v14.11.1 -CMD [ "/app/code/start.sh" ] \ No newline at end of file +CMD [ "/app/pkg/start.sh" ] \ No newline at end of file diff --git a/README.md b/README.md index c71a56e..5069b17 100644 --- a/README.md +++ b/README.md @@ -24,44 +24,112 @@ Refer to the [Cloudron Docs](https://docs.cloudron.io/packaging/cli) for more in Please refer to `docker-run.sh` file for some commands handy for you to test this setup. +## Logging in +Look for credentials in the file `-credentials.txt` from the file manager.sd + ## LDAP Connection [WIP] -LDAP Auth is not already configured. When a user logs in for the first time, a new **System User** is created with **Guest** -role. An admin can then change the user's role. +LDAP Auth is not already configured. When a user logs in for the first time, a new **System User** is created with ** +Guest** role. An admin can then change the user's role. LDAP Group sync or custom group mapping could also be possible, but I haven't tried it yet. Send a PR if you want. -For now, use the script `/app/code/setup-ldap.sh` and make necessary changes, then modify the LDAP settings to -suit your needs using the REST API, even if you have already completed setup. It takes one of the three params: +For now, look at the `/app/pkg/setup-ldap.sh` and make necessary changes. Run the command to add LDAP settings. The +script is configured to use your cloudron's LDAP addon. + - add : adds LDAP settings to the site - disable: disables LDAP settings (required before deleting) - delete: deletes the LDAP settings for the site +## Installing Apps + +You can install new frappe apps. To install the apps, simply follow these steps, and restart the app. +Also refer to the [Official Documentation](https://frappeframework.com/docs/v14/user/en/bench/bench-commands#add-apps) + +```shell +# Make sure you are in the /app/code/frappe-bench directory. +cd /app/code/frappe-bench + +gosu cloudron bench get-app --branch +gosu cloudron bench install-app hrms + +# Example: install the hrms app for HR Management +gosu cloudron bench get-app --branch v1.0.0 hrms +gosu cloudron bench install-app hrms + +``` + +Note: Restart the app using the Restart button on top of the terminal, or simply run `supervisorctl restart all` to +ensure the apps are properly configured. + ## Updating ErpNext -This might not work yet because of the read-only -filesystem. [Official Documentation](https://frappeframework.com/docs/v14/user/en/production-setup#updating) +### Important Notes + +- **MAKE SURE TO BACKUP BEFORE TRYING TO UPDATE. IF THE UPDATE FAILS, THE APP MAY STOP RESPONDING, AND YOU MAY LOSE + DATA.** + +- **Run the `git` and `bench` commands with `gosu cloudron` as the user `cloudron` instead of the root user.**' + +- **Put the app in Recovery Mode from the dashboard before running updates and turn it off later.** + +```shell + # Put the app in maintenance mode + gosu cloudron bench set-maintenance-mode on + + + # Turn off maintenance mode + gosu cloudron bench set-maintenance-mode off +``` + +### 1. Update with Cloudron CLI + +You can update this package normally by pulling the latest version of this repository, then running `cloudron update` +and `cloudron update --app your-app-domain`. This is the safest way to update the app. + +**After updating, make sure to run `gosu cloudron bench migrate` from the terminal while the app is running.** + +### 2. Automatic updates with bench + +Set the application to Recovery Mode. Then update normally. Refer to +the [Official Documentation](https://frappeframework.com/docs/v14/user/en/production-setup#updating) ```shell - # update everything - bench update + # switch frappe and erpnext app version to version-14 + gosu cloudron bench switch-to-branch version-14 frappe erpnext + #if you have more apps, switch to the respective versions for those apps as well + # gosu cloudron bench switch-to-branch version-xxx app1 app2 app3 ... + + # update frappe and all apps, then run migration + gosu cloudron bench update + +``` + +You can also run each steps one at a time as needed. + +```shell # update apps - bench update --pull + gosu cloudron bench update --pull # run patches only - bench update --patch + gosu cloudron bench update --patch # build assets only - bench update --build + gosu cloudron bench update --build # update bench (the cli) - bench update --bench + gosu cloudron bench update --bench # update python packages and node_modules - bench update --requirements + gosu cloudron bench update --requirements ``` +## Disable public website (eg. Dashboard as homepage) + +From the sidebar, **Website** -> **Website Settings** -> **Landing Page (Home Page)** -> Set to **app** instead of ** +home**. + ## Third-party Intellectual Properties All third-party product names, company names, and their logos belong to their respective owners, and may be their diff --git a/dev-scripts/docker-run.sh b/dev-scripts/docker-run.sh index b2ede79..8ae163f 100755 --- a/dev-scripts/docker-run.sh +++ b/dev-scripts/docker-run.sh @@ -23,10 +23,12 @@ BUILDKIT_PROGRESS=plain docker build --platform linux/amd64 -t erpnext_custom . erpnext_custom BUILDKIT_PROGRESS=plain docker build --platform linux/arm64 -t erpnext14 . && - docker run --platform linux/arm64 --read-only \ + docker run --platform linux/arm64 \ -v "$(pwd)"/.docker14/app/data:/app/data:rw \ -v "$(pwd)"/.docker14/tmp:/tmp:rw \ -v "$(pwd)"/.docker14/run:/run:rw \ - -p 8000:80 \ - -p 9000:9000 \ + -p 8800:80 \ + -p 9900:9000 \ + --network localnet \ + -e CLOUDRON_REDIS_HOST=redis-stack \ erpnext14 \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..cc5f1ca --- /dev/null +++ b/nginx.conf @@ -0,0 +1,47 @@ +worker_processes auto; +user nginx; +pid /run/nginx/nginx.pid; +error_log /run/nginx/error.log warn; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + server_names_hash_bucket_size 64; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # nginx's default mime.types doesn't include a mapping for wasm + types { + application/wasm wasm; + } + + client_body_temp_path /run/nginx; + proxy_temp_path /run/nginx; + fastcgi_temp_path /run/nginx; + uwsgi_temp_path /run/nginx; + scgi_temp_path /run/nginx; + + access_log /run/nginx/access.log; + error_log /run/nginx/error.log info; + + add_header Strict-Transport-Security "max-age=63072000" always; + + gzip on; + gzip_types text/plain text/css application/javascript application/json image/x-icon application/octet-stream application/wasm; + gzip_vary on; + gzip_proxied no-cache no-store private expired auth; + gzip_min_length 512; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} \ No newline at end of file diff --git a/start.sh b/start.sh index bf9c66c..f29a93d 100755 --- a/start.sh +++ b/start.sh @@ -1,16 +1,28 @@ #!/bin/bash set -eu pipefail +echo ">>>> Creating directories" +mkdir -p /run/nginx /run/supervisor/logs /run/mariadb /run/frappe +chown -R cloudron:cloudron /run/nginx +chown -R cloudron:cloudron /run/supervisor/ + +if [[ ! -f /run/.yarnrc ]]; then + touch /run/.yarnrc && chown cloudron:cloudron /run/.yarnrc +fi + +cd /app/code/frappe-bench + # I've split the first-run checks in multiple places because it takes a lot of time # to copy from /app/code/frappe-bench/-orig to /app/data/frappe/ and then # chown recursively. During development we can delete the .docker/app/data/mariadb folder # without waiting for .docker/app/data/frapee folder to perform "first-run" again. # check for frappe framework files -# copy frappe and erpnext, then chown to cloudron (takes a while) +# copy frappe bench, then chown to cloudron (takes a while) if [[ ! -f /app/data/frappe/.initialized ]]; then echo ">>>> firstrun: setup /app/data/{config,sites,apps,logs}" - mkdir -p /app/data/frappe/{config,sites,apps,logs} + mkdir -p /app/data/frappe/{env,config,sites,apps,logs} + cp -R /app/code/frappe-bench/env-orig/* /app/data/frappe/env/ cp -R /app/code/frappe-bench/config-orig/* /app/data/frappe/config/ cp -R /app/code/frappe-bench/sites-orig/* /app/data/frappe/sites/ cp -R /app/code/frappe-bench/apps-orig/* /app/data/frappe/apps/ @@ -22,17 +34,20 @@ if [[ ! -f /app/data/frappe/.initialized ]]; then echo ">>>> Done frappe setup" fi +if [[ ! -f /app/data/frappe/patches.txt ]]; then + cp /app/code/frappe-bench/patches-orig.txt /app/data/frappe/patches.txt + chown cloudron:cloudron /app/data/frappe/patches.txt +fi + # Check for log folders (takes no time) -if [[ ! -f /app/data/.log-setup-complete ]]; then +if [[ ! -d /run/frappe/logs ]]; then echo ">>>> firstrun: setup /run/frappe/logs" mkdir -p /run/frappe/logs cp -R /app/code/frappe-bench/logs-orig/* /run/frappe/logs/ - chown -R cloudron:cloudron /run/frappe/logs - - touch /app/data/.log-setup-complete echo ">>>> Done frappe logs setup" fi +chown -R cloudron:cloudron /run/frappe/logs # Check if db setup is complete (takes no time) if [[ ! -f /app/data/mariadb/.initialized ]]; then @@ -51,20 +66,13 @@ echo ">>>> Done /app/data/mariadb setup" echo ">>>> Setup /run/mysqld/logs" if [[ ! -d /run/mysqld/logs ]]; then mkdir -p /run/mysqld/logs - cp -R /var/log/mysql-orig/* /run/mysqld/logs +## sometimes /var/log/mysql-orig/* doesn't exist, and cp failed; can't find a cause, so skipping on the logs part now. +# cp -R /var/log/mysql-orig/* /run/mysqld/logs fi chown -R mysql:mysql /run/mysqld/logs echo ">>>> Done setup /run/mysqld/logs" -if [[ ! -f /app/data/redis/.initialized ]]; then - echo ">>>> firstrun: setup /app/data/redis" - mkdir -p /app/data/redis - cp -R /etc/redis-orig/* /app/data/redis/ -fi -chown -R redis:redis /app/data/redis -echo ">>>> Done redis data setup" - -############# ################## +## Setup mariadb echo ">>>> Running mysqld_safe..." mkdir -p /app/data/tmp && chown mysql:mysql /app/data/tmp @@ -91,25 +99,13 @@ if [[ ! -f /app/data/mariadb/.root_password ]]; then mysql -uroot -proot -e "FLUSH PRIVILEGES;" echo "Done." fi -############# ################## - -############# ################## -echo ">>>> Setup directories for nginx" -if [[ ! -d /run/nginx/logs ]]; then - mkdir -p /run/nginx/logs -fi -chown -R cloudron:cloudron /run/nginx -echo ">>>> Done nginx dir setup" -############# ################## -############# ################## -echo ">>>> setup /run/supervisor/logs" -if [[ ! -d /run/supervisor/logs ]]; then - mkdir -p /run/supervisor/logs -fi -chown -R cloudron:cloudron /run/supervisor -echo ">>>> done /run/supervisor/logs" -############# ################## +## Set common redis configuration. +REDIS_URL="redis://${CLOUDRON_REDIS_HOST}:${CLOUDRON_REDIS_PORT}" +## Using sed because `bench config set-common-config -c redis_cache "redis://$CLOUDRON_REDIS_HOST"` didn't work. +sed -i "s|\"redis_cache\": \".*\"|\"redis_cache\": \"$REDIS_URL\"|" /app/data/frappe/sites/common_site_config.json +sed -i "s|\"redis_queue\": \".*\"|\"redis_queue\": \"$REDIS_URL\"|" /app/data/frappe/sites/common_site_config.json +sed -i "s|\"redis_socketio\": \".*\"|\"redis_socketio\": \"$REDIS_URL\"|" /app/data/frappe/sites/common_site_config.json ############# ################## DEFAULT_SITE=${CLOUDRON_APP_DOMAIN:-'cloudron.local'} @@ -118,12 +114,7 @@ if [[ ! -f "/app/data/frappe/sites/${DEFAULT_SITE}/.initialized" ]]; then echo ">>>> Creating default site with hostname: ${DEFAULT_SITE} ..." - echo 'frappe -erpnext -payments -hrms' >/app/data/frappe/sites/apps.txt - - cd /app/code/frappe-bench + echo 'frappe' >/app/data/frappe/sites/apps.txt echo ">>>> Generating passwords..." DB_ROOT_PWD=$(/app/data/frappe/sites/apps.txt echo ">>>> Running bench new-site..." + # Get and Install ErpNext app by default, as it cannot be installed after the initial setup of frappe website is complete. + gosu cloudron bench get-app --branch ${ERPNEXT_VERSION} --resolve-deps erpnext + /usr/local/bin/gosu cloudron:cloudron bench new-site \ --verbose \ --force \ @@ -140,7 +134,8 @@ hrms' >/app/data/frappe/sites/apps.txt --db-password "${DB_PWD}" \ --db-root-username "root" \ --db-root-password "${DB_ROOT_PWD}" \ - --admin-password "${SITE_PWD}" "${DEFAULT_SITE}" + --admin-password "${SITE_PWD}" "${DEFAULT_SITE}" \ + --install-app erpnext echo "Website Username: Administrator / Website Password: ${SITE_PWD}" >"/app/data/${DEFAULT_SITE}-credential.txt" @@ -150,57 +145,34 @@ hrms' >/app/data/frappe/sites/apps.txt echo ">>>> enable scheduler for ${DEFAULT_SITE}..." /usr/local/bin/gosu cloudron:cloudron bench scheduler enable + ############# ################## + echo ">>>> setting nginx port to 8888 for site ${DEFAULT_SITE}" + bench set-nginx-port ${DEFAULT_SITE} 8888 - echo ">>>> installing the payments module..." - /usr/local/bin/gosu cloudron:cloudron bench install-app payments - echo ">>>> done" + echo ">>>> bench setup nginx" + /usr/local/bin/gosu cloudron:cloudron bench setup nginx --yes --logging none - echo ">>>> installing erpnext..." - /usr/local/bin/gosu cloudron:cloudron bench install-app erpnext - echo ">>>> done" + sed -i 's|proxy_set_header X-Forwarded-Proto $scheme;|proxy_set_header X-Forwarded-Proto https; # patched for cloudron|g' /app/data/frappe/config/nginx.conf + echo ">>>> Done nginx setup" + ############# ################## - touch "/app/data/frappe/sites/${DEFAULT_SITE}/.initialized" -else - echo ">>>> Site ${DEFAULT_SITE} already setup." -fi - -############# ################## -echo ">>>> Setting up nginx, redis and supervisor..." -# "--logging none" only works "--logging combined" didn't work. -# Without this flag, "main" will be added to access_log, Causing nginx fail to start. -# --yes bypasses prompt -/usr/local/bin/gosu cloudron:cloudron bench setup nginx --yes --logging none -# fix "Conflicting scheme in header" error. -sed -i 's|proxy_set_header X-Forwarded-Proto $scheme;|proxy_set_header X-Forwarded-Proto https; # patched for cloudron|g' /app/data/frappe/config/nginx.conf - -/usr/local/bin/gosu cloudron:cloudron bench setup redis - -/usr/local/bin/gosu cloudron:cloudron bench setup supervisor --yes -echo ">>>> Done" + ############# ################## + echo ">>>> bench setup supervisor" -if [[ ! -f "/app/data/frappe/sites/${DEFAULT_SITE}/.hrms_installed" ]]; then + /usr/local/bin/gosu cloudron:cloudron bench setup supervisor --skip-redis --yes + sed -i "s,/app/code/frappe-bench/logs/,/run/frappe/logs/,g" /app/data/frappe/config/supervisor.conf - echo ">>>> Installing HRMS app (in background) to hostname: ${DEFAULT_SITE}" - - # Install HRMS app; requires Redis to be running, so we do "bench install-app hrms &" to run it as a background job. - # Right after this, supervisor process will start all the required processes (redis, etc) that this command needs. - - /usr/local/bin/gosu cloudron:cloudron bench install-app hrms & - echo ">>>> done" - - touch "/app/data/frappe/sites/${DEFAULT_SITE}/.hrms_installed" + echo ">>>> Done supervisor setup" + ############# ################## + touch "/app/data/frappe/sites/${DEFAULT_SITE}/.initialized" else - echo ">>>> HRMS already setup in ${DEFAULT_SITE}" + echo ">>>> Site ${DEFAULT_SITE} already setup." fi +############# ################## +## Starting supervisord echo ">>>> All done. Starting nginx & supervisord..." echo ">>>> To setup LDAP, open the web terminal and run /app/code/setup-ldap.sh" -echo '[program:nginx] -command=/usr/sbin/nginx -c /etc/nginx/nginx.conf -g "daemon off;" -autostart=true -autorestart=true -priority=10' >/app/data/frappe/config/supervisor-app-nginx.conf - -/usr/local/bin/gosu cloudron:cloudron /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon +/usr/local/bin/gosu cloudron:cloudron /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i frappe diff --git a/supervisor/app-nginx.conf b/supervisor/app-nginx.conf new file mode 100644 index 0000000..77ebddf --- /dev/null +++ b/supervisor/app-nginx.conf @@ -0,0 +1,8 @@ +[program:nginx] +priority=100 +directory=/tmp +command=/usr/sbin/nginx -c /app/pkg/nginx.conf -g "daemon off;" +autostart=true +autorestart=true +stdout_logfile=/run/nginx/supervisor-app-nginx-stdout.log +stderr_logfile=/run/nginx/supervisor-app-nginx-stderr.log \ No newline at end of file diff --git a/supervisord.conf b/supervisor/supervisord.conf similarity index 92% rename from supervisord.conf rename to supervisor/supervisord.conf index 9eed665..ad54103 100644 --- a/supervisord.conf +++ b/supervisor/supervisord.conf @@ -5,6 +5,7 @@ file=/run/supervisor/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700) [supervisord] +loglevel=warn logfile=/run/supervisor/logs/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/run/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/run/supervisor/logs/ ; ('AUTO' child log dir, default $TEMP) @@ -25,4 +26,4 @@ serverurl=unix:///run/supervisor/supervisor.sock ; use a unix:// URL for a unix ; include files themselves. [include] -files = /etc/supervisor/conf.d/*.conf \ No newline at end of file +files = /etc/supervisor/app-nginx.conf /app/data/frappe/config/supervisor.conf \ No newline at end of file