Merge pull request #421 from frappe/develop

Release: ERPNext v12.18.0 and Frappe Framework v12.15.0
This commit is contained in:
Revant Nandgaonkar 2021-02-21 11:51:35 +05:30 committed by GitHub
commit 34f7702c75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 126 additions and 104 deletions

View file

@ -6,6 +6,12 @@ upstream socketio-server {
server ${FRAPPE_SOCKETIO}:${SOCKETIO_PORT} fail_timeout=0;
}
# Parse the X-Forwarded-Proto header - if set - defaulting to $scheme.
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $scheme;
https https;
}
server {
listen 80;
server_name $http_host;
@ -16,6 +22,12 @@ server {
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# Define ${UPSTREAM_REAL_IP_ADDRESS} as our trusted upstream address, so we will be using
# its ${UPSTREAM_REAL_IP_HEADER} address as our remote address
set_real_ip_from ${UPSTREAM_REAL_IP_ADDRESS};
real_ip_header ${UPSTREAM_REAL_IP_HEADER};
real_ip_recursive ${UPSTREAM_REAL_IP_RECURSIVE};
location /assets {
try_files $uri =404;
}
@ -27,10 +39,12 @@ server {
location /socket.io {
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Frappe-Site-Name $host;
proxy_set_header Origin $scheme://$http_host;
proxy_set_header Origin $proxy_x_forwarded_proto://$http_host;
proxy_set_header Host $http_host;
proxy_pass http://socketio-server;
@ -50,8 +64,8 @@ server {
}
location @webserver {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Frappe-Site-Name $host;
proxy_set_header Host $http_host;
proxy_set_header X-Use-X-Accel-Redirect True;

View file

@ -46,8 +46,8 @@ function configureEnv() {
}
function checkConnection() {
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/check_connection.py"
. /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/check_connection.py
}
function checkConfigExists() {
@ -68,9 +68,6 @@ if [[ ! -e /home/frappe/frappe-bench/sites/apps.txt ]]; then
find /home/frappe/frappe-bench/apps -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -r > /home/frappe/frappe-bench/sites/apps.txt
fi
# Allow user process to create files in logs directory
chown -R frappe:frappe /home/frappe/frappe-bench/logs
# symlink node_modules
ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \
/home/frappe/frappe-bench/apps/frappe/node_modules
@ -79,8 +76,6 @@ if [ "$1" = 'start' ]; then
configureEnv
checkConnection
chown frappe:frappe /home/frappe/frappe-bench/sites/common_site_config.json
if [[ -z "$WORKERS" ]]; then
export WORKERS=2
fi
@ -90,99 +85,67 @@ if [ "$1" = 'start' ]; then
fi
if [[ ! -z "$AUTO_MIGRATE" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/auto_migrate.py"
. /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/auto_migrate.py
fi
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& gunicorn -b 0.0.0.0:$FRAPPE_PORT \
--worker-tmp-dir /dev/shm \
--threads=4 \
--workers $WORKERS \
--worker-class=gthread \
--log-file=- \
-t 120 frappe.app:application --preload"
else
. /home/frappe/frappe-bench/env/bin/activate
gunicorn -b 0.0.0.0:$FRAPPE_PORT \
--worker-tmp-dir /dev/shm \
--threads=4 \
--workers $WORKERS \
--worker-class=gthread \
--log-file=- \
-t 120 frappe.app:application --preload
fi
. /home/frappe/frappe-bench/env/bin/activate
gunicorn -b 0.0.0.0:$FRAPPE_PORT \
--worker-tmp-dir /dev/shm \
--threads=4 \
--workers $WORKERS \
--worker-class=gthread \
--log-file=- \
-t 120 frappe.app:application --preload
elif [ "$1" = 'worker' ]; then
checkConfigExists
checkConnection
# default WORKER_TYPE=default
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/worker.py"
else
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/worker.py
fi
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/worker.py
elif [ "$1" = 'schedule' ]; then
checkConfigExists
checkConnection
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/background.py"
else
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/background.py
fi
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/background.py
elif [ "$1" = 'new' ]; then
checkConfigExists
checkConnection
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/new.py"
exit
else
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/new.py
fi
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/new.py
exit
elif [ "$1" = 'drop' ]; then
checkConfigExists
checkConnection
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/drop.py"
exit
else
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/drop.py
fi
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/drop.py
exit
elif [ "$1" = 'migrate' ]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/migrate.py"
. /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/migrate.py
exit
elif [ "$1" = 'doctor' ]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/doctor.py ${@:2}"
. /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/doctor.py ${@:2}
exit
elif [ "$1" = 'backup' ]; then
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/backup.py"
exit
else
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/backup.py
fi
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/backup.py
exit
elif [ "$1" = 'console' ]; then
@ -192,25 +155,20 @@ elif [ "$1" = 'console' ]; then
exit 1
fi
if [[ -z "$RUN_AS_ROOT" ]]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/console.py $2"
exit
else
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/console.py "$2"
fi
. /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/console.py "$2"
exit
elif [ "$1" = 'push-backup' ]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/push_backup.py"
. /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/push_backup.py
exit
elif [ "$1" = 'restore-backup' ]; then
su frappe -c ". /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/restore_backup.py"
. /home/frappe/frappe-bench/env/bin/activate \
&& python /home/frappe/frappe-bench/commands/restore_backup.py
exit
else

View file

@ -15,9 +15,20 @@ cd apps
git clone --depth 1 https://github.com/frappe/frappe ${BRANCH}
git clone --depth 1 ${APP_REPO} ${BRANCH} ${APP_NAME}
echo "Install frappe NodeJS dependencies . . ."
cd /home/frappe/frappe-bench/apps/frappe
yarn
echo "Install ${APP_NAME} NodeJS dependencies . . ."
cd /home/frappe/frappe-bench/apps/${APP_NAME}
yarn
echo "Build browser assets . . ."
cd /home/frappe/frappe-bench/apps/frappe
yarn production --app ${APP_NAME}
echo "Install frappe NodeJS production dependencies . . ."
cd /home/frappe/frappe-bench/apps/frappe
yarn install --production=true
echo "Install ${APP_NAME} NodeJS production dependencies . . ."
cd /home/frappe/frappe-bench/apps/${APP_NAME}
yarn install --production=true
mkdir -p /home/frappe/frappe-bench/sites/assets/${APP_NAME}

View file

@ -11,8 +11,6 @@ rsync -a --delete /var/www/html/assets/css /assets
rsync -a --delete /var/www/html/assets/frappe /assets
. /rsync
chmod -R 755 /assets
touch /var/www/html/sites/.build -r $(ls -td /assets/* | head -n 1)
if [[ -z "$FRAPPE_PY" ]]; then
@ -35,11 +33,26 @@ if [[ -z "$HTTP_TIMEOUT" ]]; then
export HTTP_TIMEOUT=120
fi
if [[ -z "$UPSTREAM_REAL_IP_ADDRESS" ]]; then
export UPSTREAM_REAL_IP_ADDRESS=127.0.0.1
fi
if [[ -z "$UPSTREAM_REAL_IP_RECURSIVE" ]]; then
export UPSTREAM_REAL_IP_RECURSIVE=off
fi
if [[ -z "$UPSTREAM_REAL_IP_HEADER" ]]; then
export UPSTREAM_REAL_IP_HEADER="X-Forwarded-For"
fi
envsubst '${FRAPPE_PY}
${FRAPPE_PY_PORT}
${FRAPPE_SOCKETIO}
${SOCKETIO_PORT}
${HTTP_TIMEOUT}' \
${HTTP_TIMEOUT}
${UPSTREAM_REAL_IP_ADDRESS}
${UPSTREAM_REAL_IP_RECURSIVE}
${UPSTREAM_REAL_IP_HEADER}' \
< /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
echo "Waiting for frappe-python to be available on $FRAPPE_PY port $FRAPPE_PY_PORT"

View file

@ -28,6 +28,8 @@ RUN cd /home/frappe/frappe-bench/apps/frappe \
COPY build/frappe-socketio/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
USER frappe
WORKDIR /home/frappe/frappe-bench/sites
ENTRYPOINT ["docker-entrypoint.sh"]

View file

@ -16,14 +16,14 @@ function checkConfigExists() {
if [ "$1" = 'start' ]; then
checkConfigExists
su frappe -c "node /home/frappe/frappe-bench/apps/frappe/socketio.js"
node /home/frappe/frappe-bench/apps/frappe/socketio.js
elif [ "$1" = 'doctor' ]; then
su frappe -c "node /home/frappe/frappe-bench/apps/frappe/health.js"
node /home/frappe/frappe-bench/apps/frappe/health.js
else
exec su frappe -c "$@"
exec -c "$@"
fi

View file

@ -47,6 +47,10 @@ RUN apt-get update -y && apt-get install \
&& wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh \
&& chown -R frappe:frappe /home/frappe
# Setup docker-entrypoint
COPY build/common/worker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
USER frappe
# Install nvm with node
RUN bash install.sh \
@ -65,7 +69,6 @@ RUN python -m venv env \
&& git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch ${GIT_BRANCH} \
&& pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe
USER root
# Copy scripts and templates
COPY build/common/commands/* /home/frappe/frappe-bench/commands/
COPY build/common/common_site_config.json.template /opt/frappe/common_site_config.json.template
@ -73,17 +76,10 @@ COPY build/common/worker/install_app.sh /usr/local/bin/install_app
COPY build/common/worker/bench /usr/local/bin/bench
COPY build/common/worker/healthcheck.sh /usr/local/bin/healthcheck.sh
# Setup docker-entrypoint
COPY build/common/worker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
# Use sites volume as working directory
WORKDIR /home/frappe/frappe-bench/sites
# Set ownership of sites directory
RUN chown -R frappe:frappe /home/frappe/frappe-bench/sites
VOLUME [ "/home/frappe/frappe-bench/sites", "/home/frappe/backups" ]
VOLUME [ "/home/frappe/frappe-bench/sites", "/home/frappe/backups", "/home/frappe/frappe-bench/logs" ]
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["start"]

View file

@ -68,6 +68,7 @@ services:
- redis-socketio
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
erpnext-worker-default:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -78,6 +79,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
erpnext-worker-short:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -90,6 +92,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
erpnext-worker-long:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -112,6 +115,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
redis-cache:
image: redis:latest
@ -154,6 +158,7 @@ services:
- INSTALL_APPS=${INSTALL_APPS}
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
volumes:
mariadb-vol:
@ -163,3 +168,4 @@ volumes:
assets-vol:
sites-vol:
cert-vol:
logs-vol:

View file

@ -142,6 +142,7 @@ services:
erpnext-nginx:
image: frappe/erpnext-nginx:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
environment:
- UPSTREAM_REAL_IP_ADDRESS=10.0.0.0/8
- FRAPPE_PY=erpnext-python
- FRAPPE_PY_PORT=8000
- FRAPPE_SOCKETIO=frappe-socketio

View file

@ -20,6 +20,9 @@ These variables are set on every container start. Change in these variables will
- `FRAPPE_SOCKETIO`: SocketIO host to reverse proxy. Default: 0.0.0.0
- `SOCKETIO_PORT`: SocketIO port to reverse proxy. Default: 9000
- `HTTP_TIMEOUT`: Nginx http timeout. Default: 120
- `UPSTREAM_REAL_IP_ADDRESS `: The trusted address (or ip range) of upstream proxy servers. If set, this will tell nginx to trust the X-Forwarded-For header from these proxy servers in determining the real IP address of connecting clients. Default: 127.0.0.1
- `UPSTREAM_REAL_IP_RECURSIVE`: When set to `on`, this will tell nginx to not just look to the last upstream proxy server in determining the real IP address. Default: off
- `UPSTREAM_REAL_IP_HEADER`: Set this to the header name sent by your upstream proxy server to indicate the real IP of connecting clients. Default: X-Forwarded-For
### frappe-socketio

View file

@ -244,7 +244,4 @@ check_env
prompt_config
setup_user
su - "$username" << EOF
install
EOF
install

View file

@ -43,6 +43,7 @@ services:
- SOCKETIO_PORT=9000
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
- assets-vol:/home/frappe/frappe-bench/sites/assets:rw
frappe-socketio:
@ -54,6 +55,7 @@ services:
- redis-socketio
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-default:
image: [app]-worker
@ -67,6 +69,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-short:
image: [app]-worker
@ -82,6 +85,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-long:
image: [app]-worker
@ -97,6 +101,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-schedule:
image: [app]-worker
@ -110,7 +115,9 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
volumes:
assets-vol:
sites-vol:
logs-vol:

View file

@ -41,6 +41,7 @@ services:
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- assets-vol:/home/frappe/frappe-bench/sites/assets:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-socketio:
image: frappe/frappe-socketio:${FRAPPE_VERSION}
@ -51,6 +52,7 @@ services:
- redis-socketio
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-default:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -64,6 +66,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-short:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -79,6 +82,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-long:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -94,6 +98,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-schedule:
image: frappe/erpnext-worker:${ERPNEXT_VERSION}
@ -107,7 +112,9 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
volumes:
assets-vol:
sites-vol:
logs-vol:

View file

@ -40,6 +40,7 @@ services:
- AUTO_MIGRATE=1
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
- assets-vol:/home/frappe/frappe-bench/sites/assets:rw
frappe-socketio:
@ -51,6 +52,7 @@ services:
- redis-socketio
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-default:
image: frappe/frappe-worker:${FRAPPE_VERSION}
@ -64,6 +66,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-short:
image: frappe/frappe-worker:${FRAPPE_VERSION}
@ -79,6 +82,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-worker-long:
image: frappe/frappe-worker:${FRAPPE_VERSION}
@ -94,6 +98,7 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
frappe-schedule:
image: frappe/frappe-worker:${FRAPPE_VERSION}
@ -107,7 +112,9 @@ services:
- redis-cache
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- logs-vol:/home/frappe/frappe-bench/logs:rw
volumes:
assets-vol:
sites-vol:
logs-vol: