From e6a520900132c2300ceca317917fc1d7d13cd0bb Mon Sep 17 00:00:00 2001 From: pratikbalar Date: Tue, 22 Jun 2021 15:44:25 +0530 Subject: [PATCH 1/7] refactor: style as per google style guide (tried) - https://google.github.io/styleguide/ --- build/common/worker/docker-entrypoint.sh | 91 ++++---- build/common/worker/healthcheck.sh | 2 +- build/frappe-socketio/docker-entrypoint.sh | 16 +- tests/docker-test.sh | 233 ++++++++++----------- 4 files changed, 160 insertions(+), 182 deletions(-) diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index a3082442..48208dc8 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -1,36 +1,36 @@ #!/bin/bash function configureEnv() { - if [ ! -f /home/frappe/frappe-bench/sites/common_site_config.json ]; then + if [[ ! -f /home/frappe/frappe-bench/sites/common_site_config.json ]]; then - if [[ -z "$MARIADB_HOST" ]]; then - if [[ -z "$POSTGRES_HOST" ]]; then + if [[ -z "${MARIADB_HOST}" ]]; then + if [[ -z "${POSTGRES_HOST}" ]]; then echo "MARIADB_HOST or POSTGRES_HOST is not set" exit 1 fi fi - if [[ -z "$REDIS_CACHE" ]]; then + if [[ -z "${REDIS_CACHE}" ]]; then echo "REDIS_CACHE is not set" exit 1 fi - if [[ -z "$REDIS_QUEUE" ]]; then + if [[ -z "${REDIS_QUEUE}" ]]; then echo "REDIS_QUEUE is not set" exit 1 fi - if [[ -z "$REDIS_SOCKETIO" ]]; then + if [[ -z "${REDIS_SOCKETIO}" ]]; then echo "REDIS_SOCKETIO is not set" exit 1 fi - if [[ -z "$SOCKETIO_PORT" ]]; then + if [[ -z "${SOCKETIO_PORT}" ]]; then echo "SOCKETIO_PORT is not set" exit 1 fi - if [[ -z "$DB_PORT" ]]; then + if [[ -z "${DB_PORT}" ]]; then export DB_PORT=3306 fi @@ -41,21 +41,21 @@ function configureEnv() { ${REDIS_CACHE} ${REDIS_QUEUE} ${REDIS_SOCKETIO} - ${SOCKETIO_PORT}' < /opt/frappe/common_site_config.json.template > /home/frappe/frappe-bench/sites/common_site_config.json + ${SOCKETIO_PORT}' /home/frappe/frappe-bench/sites/common_site_config.json fi } function checkConnection() { - . /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() { COUNTER=0 - while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]] && [[ $COUNTER -le 30 ]] ; do - sleep 1 - (( COUNTER=COUNTER+1 )) - echo "config file not created, retry $COUNTER" + while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]] && [[ ${COUNTER} -le 30 ]]; do + sleep 1 + ((COUNTER = COUNTER + 1)) + echo "config file not created, retry ${COUNTER}" done if [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]]; then @@ -65,49 +65,49 @@ function checkConfigExists() { } 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 + 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 # symlink node_modules ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \ /home/frappe/frappe-bench/apps/frappe/node_modules -if [ "$1" = 'start' ]; then +if [[ "$1" == 'start' ]]; then configureEnv checkConnection - if [[ -z "$WORKERS" ]]; then + if [[ -z "${WORKERS}" ]]; then export WORKERS=2 fi - if [[ -z "$FRAPPE_PORT" ]]; then + if [[ -z "${FRAPPE_PORT}" ]]; then export FRAPPE_PORT=8000 fi - if [[ -z "$WORKER_CLASS" ]]; then + if [[ -z "${WORKER_CLASS}" ]]; then export WORKER_CLASS=gthread fi export LOAD_CONFIG_FILE="" - if [ "$WORKER_CLASS" = "gevent" ]; then + if [ "${WORKER_CLASS}" = "gevent" ]; then export LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" fi - if [[ ! -z "$AUTO_MIGRATE" ]]; then - . /home/frappe/frappe-bench/env/bin/activate \ - && python /home/frappe/frappe-bench/commands/auto_migrate.py + if [[ ! -z "${AUTO_MIGRATE}" ]]; then + . /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/auto_migrate.py fi . /home/frappe/frappe-bench/env/bin/activate - gunicorn $LOAD_CONFIG_FILE -b 0.0.0.0:$FRAPPE_PORT \ + gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ --worker-tmp-dir /dev/shm \ --threads=4 \ - --workers $WORKERS \ - --worker-class=$WORKER_CLASS \ + --workers ${WORKERS} \ + --worker-class=${WORKER_CLASS} \ --log-file=- \ -t 120 frappe.app:application --preload -elif [ "$1" = 'worker' ]; then +elif [[ "$1" == 'worker' ]]; then checkConfigExists checkConnection # default WORKER_TYPE=default @@ -115,14 +115,14 @@ elif [ "$1" = 'worker' ]; then . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/worker.py -elif [ "$1" = 'schedule' ]; then +elif [[ "$1" == 'schedule' ]]; then checkConfigExists checkConnection . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/background.py -elif [ "$1" = 'new' ]; then +elif [[ "$1" == 'new' ]]; then checkConfigExists checkConnection @@ -130,7 +130,7 @@ elif [ "$1" = 'new' ]; then python /home/frappe/frappe-bench/commands/new.py exit -elif [ "$1" = 'drop' ]; then +elif [[ "$1" == 'drop' ]]; then checkConfigExists checkConnection @@ -138,25 +138,25 @@ elif [ "$1" = 'drop' ]; then python /home/frappe/frappe-bench/commands/drop.py exit -elif [ "$1" = 'migrate' ]; then +elif [[ "$1" = 'migrate' ]]; then - . /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 +elif [[ "$1" == 'doctor' ]]; then - . /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 +elif [[ "$1" == 'backup' ]]; then . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/backup.py exit -elif [ "$1" = 'console' ]; then +elif [[ "$1" == 'console' ]]; then if [[ -z "$2" ]]; then echo "Need to specify a sitename with the command:" @@ -168,20 +168,19 @@ elif [ "$1" = 'console' ]; then python /home/frappe/frappe-bench/commands/console.py "$2" exit -elif [ "$1" = 'push-backup' ]; then +elif [[ "$1" = 'push-backup' ]]; then - . /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 +elif [[ "$1" = 'restore-backup' ]]; then - . /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 - exec $@ fi diff --git a/build/common/worker/healthcheck.sh b/build/common/worker/healthcheck.sh index 78973bea..d6566924 100755 --- a/build/common/worker/healthcheck.sh +++ b/build/common/worker/healthcheck.sh @@ -39,7 +39,7 @@ wait-for-it "$REDIS_QUEUE" -t 1 echo "Check $REDIS_SOCKETIO" wait-for-it "$REDIS_SOCKETIO" -t 1 -if [[ "$1" = "-p" ]] || [[ "$1" = "--ping-service" ]]; then +if [[ "$1" = "-p" || "$1" = "--ping-service" ]]; then echo "Check $2" wait-for-it "$2" -t 1 fi diff --git a/build/frappe-socketio/docker-entrypoint.sh b/build/frappe-socketio/docker-entrypoint.sh index 6535eda6..a7ac66b2 100755 --- a/build/frappe-socketio/docker-entrypoint.sh +++ b/build/frappe-socketio/docker-entrypoint.sh @@ -1,11 +1,11 @@ -#!/bin/bash +#!/bin/bash -e function checkConfigExists() { COUNTER=0 - while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]] && [[ $COUNTER -le 30 ]] ; do - sleep 1 - let COUNTER=COUNTER+1 - echo "config file not created, retry $COUNTER" + while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json && ${COUNTER} -le 30 ]]; do + ((COUNTER = COUNTER + 1)) + echo "config file not created, retry ${COUNTER}" + sleep 1 done if [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]]; then @@ -14,16 +14,14 @@ function checkConfigExists() { fi } -if [ "$1" = 'start' ]; then +if [[ "$1" == 'start' ]]; then checkConfigExists node /home/frappe/frappe-bench/apps/frappe/socketio.js -elif [ "$1" = 'doctor' ]; then - +elif [[ "$1" == 'doctor' ]]; then node /home/frappe/frappe-bench/apps/frappe/health.js else - exec -c "$@" fi diff --git a/tests/docker-test.sh b/tests/docker-test.sh index f1ca5972..0a03b233 100755 --- a/tests/docker-test.sh +++ b/tests/docker-test.sh @@ -1,4 +1,7 @@ #!/bin/bash +ULINE='\e[1m\e[4m' +ENDULINE='\e[0m' +NEWLINE='\n' function checkMigrationComplete() { echo "Check Migration" @@ -9,21 +12,21 @@ function checkMigrationComplete() { -f installation/erpnext-publish.yml \ ps -q erpnext-python) - DOCKER_LOG=$(docker logs $CONTAINER_ID 2>&1 | grep "Starting gunicorn") + DOCKER_LOG=$(docker logs ${CONTAINER_ID} 2>&1 | grep "Starting gunicorn") INCREMENT=0 - while [[ $DOCKER_LOG != *"Starting gunicorn"* && $INCREMENT -lt 60 ]]; do + while [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -lt 60 ]]; do sleep 3 echo "Wait for migration to complete ..." - ((INCREMENT=INCREMENT+1)) - DOCKER_LOG=$(docker logs $CONTAINER_ID 2>&1 | grep "Starting gunicorn") - if [[ $DOCKER_LOG != *"Starting gunicorn"* && $INCREMENT -eq 60 ]]; then - docker logs $CONTAINER_ID + ((INCREMENT = INCREMENT + 1)) + DOCKER_LOG=$(docker logs ${CONTAINER_ID} 2>&1 | grep "Starting gunicorn") + if [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -eq 60 ]]; then + docker logs ${CONTAINER_ID} exit 1 fi done - echo -e "\e[4mMigration Log\e[0m" - docker logs $CONTAINER_ID + echo -e "${ULINE}Migration Log${ENDULINE}" + docker logs ${CONTAINER_ID} } function loopHealthCheck() { @@ -35,24 +38,22 @@ function loopHealthCheck() { echo "Loop Health Check" FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "") - while [[ -z "$FRAPPE_LOG" ]]; do + while [[ -z "${FRAPPE_LOG}" ]]; do sleep 1 CONTAINER=$(docker start frappe_doctor) - echo "Restarting $CONTAINER ..." + echo "Restarting ${CONTAINER} ..." FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "") done echo "Health check successful" } -echo -e "\e[1m\e[4mCopy env-example file\e[0m" +echo -e "${ULINE}Copy env-example file${ENDULINE}" cp env-example .env -echo -e "\n" -echo -e "\e[1m\e[4mSet version to v13\e[0m" +echo -e "${NEWLINE}${ULINE}Set version to v13${ENDULINE}" sed -i -e "s/edge/v13/g" .env -echo -e "\n" -echo -e "\e[1m\e[4mStart Services\e[0m" +echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}" docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ @@ -74,30 +75,25 @@ docker run --name postgresql -d \ postgres:11.8 loopHealthCheck -echo -e "\n" -echo -e "\e[1m\e[4mCreate new site (v13)\e[0m" +echo -e "${NEWLINE}${ULINE}Create new site (v13)${ENDULINE}" docker run -it \ -e "SITE_NAME=test.localhost" \ -e "INSTALL_APPS=erpnext" \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:v13 new -echo -e "\n" -echo -e "\e[1m\e[4mPing created site\e[0m" +echo -e "${NEWLINE}${ULINE}Ping created site${ENDULINE}" curl -sS http://test.localhost/api/method/version -echo -e "\n" -echo -e "\e[1m\e[4mCheck Created Site Index Page\e[0m" +echo -e "${NEWLINE}${ULINE}Check Created Site Index Page${ENDULINE}" curl -s http://test.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mSet version to edge\e[0m" +echo -e "${NEWLINE}${ULINE}Set version to edge${ENDULINE}" sed -i -e "s/v13/edge/g" .env -echo -e "\n" -echo -e "\e[1m\e[4mRestart containers with edge image\e[0m" +echo -e "${NEWLINE}${ULINE}Restart containers with edge image${ENDULINE}" docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ @@ -112,18 +108,17 @@ docker-compose \ up -d checkMigrationComplete -echo -e "\n" -echo -e "\e[1m\e[4mPing migrated site\e[0m" +echo -e "${NEWLINE}${ULINE}Ping migrated site${ENDULINE}" sleep 3 curl -sS http://test.localhost/api/method/version -echo -e "\n" -echo -e "\e[1m\e[4mCheck Migrated Site Index Page\e[0m" + +echo -e "${NEWLINE}${ULINE}Check Migrated Site Index Page${ENDULINE}" curl -s http://test.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mCreate new site (pgsql)\e[0m" + +echo -e "${NEWLINE}${ULINE}Create new site (pgsql)${ENDULINE}" docker run -it \ -e "SITE_NAME=pgsql.localhost" \ -e "POSTGRES_HOST=postgresql" \ @@ -132,96 +127,95 @@ docker run -it \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge new -echo -e "\n" -echo -e "\e[1m\e[4mCheck New PGSQL Site\e[0m" + +echo -e "${NEWLINE}${ULINE}Check New PGSQL Site${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") INCREMENT=0 -while [[ -z "$RESTORE_STATUS" && $INCREMENT -lt 60 ]]; do +while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do sleep 1 - echo -e "\e[1m\e[4mWait for restoration to complete ..." + echo -e "${ULINE}Wait for restoration to complete ..." RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") - ((INCREMENT=INCREMENT+1)) - if [[ -z "$RESTORE_STATUS" && $INCREMENT -eq 60 ]]; then + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then CONTAINER_ID=$(docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ ps -q erpnext-python) - docker logs $CONTAINER_ID + docker logs ${CONTAINER_ID} exit 1 fi done -echo -e "\n" -echo -e "\e[1m\e[4mPing new pgsql site\e[0m" + +echo -e "${NEWLINE}${ULINE}Ping new pgsql site${ENDULINE}" echo $RESTORE_STATUS -echo -e "\n" -echo -e "\e[1m\e[4mCheck New PGSQL Index Page\e[0m" + +echo -e "${NEWLINE}${ULINE}Check New PGSQL Index Page${ENDULINE}" curl -s http://pgsql.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mBackup site\e[0m" + +echo -e "${NEWLINE}${ULINE}Backup site${ENDULINE}" docker run -it \ -e "WITH_FILES=1" \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge backup -echo -e "\n" export MINIO_ACCESS_KEY="AKIAIOSFODNN7EXAMPLE" export MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" -echo -e "\e[1m\e[4mStart MinIO container for s3 compatible storage\e[0m" +echo -e "${ULINE}Start MinIO container for s3 compatible storage${ENDULINE}" docker run -d --name minio \ - -e "MINIO_ACCESS_KEY=$MINIO_ACCESS_KEY" \ - -e "MINIO_SECRET_KEY=$MINIO_SECRET_KEY" \ - --network frappebench00_default \ - minio/minio server /data -echo -e "\n" + -e "MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}" \ + -e "MINIO_SECRET_KEY=${MINIO_SECRET_KEY}" \ + --network frappebench00_default \ + minio/minio server /data -echo -e "\e[1m\e[4mCreate bucket named erpnext\e[0m" + +echo -e "${NEWLINE}${ULINE}Create bucket named erpnext${ENDULINE}" docker run \ --network frappebench00_default \ - vltgroup/s3cmd:latest s3cmd --access_key=$MINIO_ACCESS_KEY \ - --secret_key=$MINIO_SECRET_KEY \ + vltgroup/s3cmd:latest s3cmd --access_key=${MINIO_ACCESS_KEY} \ + --secret_key=${MINIO_SECRET_KEY} \ --region=us-east-1 \ --no-ssl \ --host=minio:9000 \ --host-bucket=minio:9000 \ mb s3://erpnext -echo -e "\n" -echo -e "\e[1m\e[4mPush backup to MinIO s3\e[0m" + +echo -e "${NEWLINE}${NEWLINE}${ULINE}Push backup to MinIO s3${ENDULINE}" docker run \ -e BUCKET_NAME=erpnext \ -e REGION=us-east-1 \ -e BUCKET_DIR=local \ - -e ACCESS_KEY_ID=$MINIO_ACCESS_KEY \ - -e SECRET_ACCESS_KEY=$MINIO_SECRET_KEY \ + -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ + -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ -e ENDPOINT_URL=http://minio:9000 \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge push-backup -echo -e "\n" -echo -e "\e[1m\e[4mStop Services\e[0m" + +echo -e "${NEWLINE}${ULINE}Stop Services${ENDULINE}" docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ stop -echo -e "\n" -echo -e "\e[1m\e[4mPrune Containers\e[0m" + +echo -e "${NEWLINE}${ULINE}Prune Containers${ENDULINE}" docker container prune -f && docker volume prune -f -echo -e "\n" -echo -e "\e[1m\e[4mStart Services\e[0m" + +echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}" docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ @@ -230,120 +224,112 @@ docker-compose \ up -d loopHealthCheck -echo -e "\n" -echo -e "\e[1m\e[4mRestore backup from MinIO / S3\e[0m" + +echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3${ENDULINE}" docker run \ -e MYSQL_ROOT_PASSWORD=admin \ -e BUCKET_NAME=erpnext \ -e BUCKET_DIR=local \ - -e ACCESS_KEY_ID=$MINIO_ACCESS_KEY \ - -e SECRET_ACCESS_KEY=$MINIO_SECRET_KEY \ + -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ + -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ -e ENDPOINT_URL=http://minio:9000 \ -e REGION=us-east-1 \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge restore-backup -echo -e "\n" -echo -e "\e[1m\e[4mCheck Restored Site (test)\e[0m" +echo -e "${NEWLINE}${ULINE}Check Restored Site (test)${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") INCREMENT=0 -while [[ -z "$RESTORE_STATUS" && $INCREMENT -lt 60 ]]; do +while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do sleep 1 echo "Wait for restoration to complete ..." RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") - ((INCREMENT=INCREMENT+1)) - if [[ -z "$RESTORE_STATUS" && $INCREMENT -eq 60 ]]; then + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then CONTAINER_ID=$(docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ ps -q erpnext-python) - docker logs $CONTAINER_ID + docker logs ${CONTAINER_ID} exit 1 fi done -echo -e "\e[1m\e[4mPing restored site (test)\e[0m" -echo $RESTORE_STATUS -echo -e "\n" +echo -e "${ULINE}Ping restored site (test)${ENDULINE}" +echo ${RESTORE_STATUS} -echo -e "\e[1m\e[4mCheck Restored Site Index Page (test)\e[0m" + +echo -e "${NEWLINE}${ULINE}Check Restored Site Index Page (test)${ENDULINE}" curl -s http://test.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mCheck Restored Site (pgsql)\e[0m" +echo -e "${NEWLINE}${ULINE}Check Restored Site (pgsql)${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") INCREMENT=0 -while [[ -z "$RESTORE_STATUS" && $INCREMENT -lt 60 ]]; do +while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do sleep 1 echo "Wait for restoration to complete ..." RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") - ((INCREMENT=INCREMENT+1)) - if [[ -z "$RESTORE_STATUS" && $INCREMENT -eq 60 ]]; then + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then CONTAINER_ID=$(docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ ps -q erpnext-python) - docker logs $CONTAINER_ID + docker logs ${CONTAINER_ID} exit 1 fi done -echo -e "\e[1m\e[4mPing restored site (pgsql)\e[0m" -echo $RESTORE_STATUS -echo -e "\n" +echo -e "${ULINE}Ping restored site (pgsql)${ENDULINE}" +echo ${RESTORE_STATUS} -echo -e "\e[1m\e[4mCheck Restored Site Index Page (pgsql)\e[0m" +echo -e "${NEWLINE}${ULINE}Check Restored Site Index Page (pgsql)${ENDULINE}" curl -s http://pgsql.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mCreate new site (edge)\e[0m" +echo -e "${NEWLINE}${ULINE}Create new site (edge)${ENDULINE}" docker run -it \ -e "SITE_NAME=edge.localhost" \ -e "INSTALL_APPS=erpnext" \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge new -echo -e "\n" -echo -e "\e[1m\e[4mCheck New Edge Site\e[0m" +echo -e "${NEWLINE}${ULINE}Check New Edge Site${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") INCREMENT=0 -while [[ -z "$RESTORE_STATUS" && $INCREMENT -lt 60 ]]; do +while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do sleep 1 - echo -e "\e[1m\e[4mWait for restoration to complete ..." + echo -e "${ULINE}Wait for restoration to complete ...${ENDULINE}" RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") - ((INCREMENT=INCREMENT+1)) - if [[ -z "$RESTORE_STATUS" && $INCREMENT -eq 60 ]]; then + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then CONTAINER_ID=$(docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ ps -q erpnext-python) - docker logs $CONTAINER_ID + docker logs ${CONTAINER_ID} exit 1 fi done -echo -e "\n" -echo -e "\e[1m\e[4mPing new edge site\e[0m" -echo $RESTORE_STATUS -echo -e "\n" +echo -e "${NEWLINE}${ULINE}Ping new edge site${ENDULINE}" +echo ${RESTORE_STATUS} -echo -e "\e[1m\e[4mCheck New Edge Index Page\e[0m" +echo -e "${NEWLINE}${ULINE}Check New Edge Index Page${ENDULINE}" curl -s http://edge.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mMigrate command in edge container\e[0m" +echo -e "${NEWLINE}${ULINE}Migrate command in edge container${ENDULINE}" docker run -it \ -e "MAINTENANCE_MODE=1" \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ @@ -352,79 +338,74 @@ docker run -it \ frappe/erpnext-worker:edge migrate checkMigrationComplete -echo -e "\n" -echo -e "\e[1m\e[4mRestore backup from MinIO / S3 (Overwrite)\e[0m" +echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3 (Overwrite)${ENDULINE}" docker run \ -e MYSQL_ROOT_PASSWORD=admin \ -e BUCKET_NAME=erpnext \ -e BUCKET_DIR=local \ - -e ACCESS_KEY_ID=$MINIO_ACCESS_KEY \ - -e SECRET_ACCESS_KEY=$MINIO_SECRET_KEY \ + -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ + -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ -e ENDPOINT_URL=http://minio:9000 \ -e REGION=us-east-1 \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge restore-backup -echo -e "\n" -echo -e "\e[1m\e[4mCheck Overwritten Site\e[0m" +echo -e "${NEWLINE}${ULINE}Check Overwritten Site${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") INCREMENT=0 -while [[ -z "$RESTORE_STATUS" && $INCREMENT -lt 60 ]]; do +while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do sleep 1 - echo -e "\e[1m\e[4mWait for restoration to complete ..." + echo -e "${ULINE}Wait for restoration to complete ..." RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") - ((INCREMENT=INCREMENT+1)) - if [[ -z "$RESTORE_STATUS" && $INCREMENT -eq 60 ]]; then + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then CONTAINER_ID=$(docker-compose \ --project-name frappebench00 \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ ps -q erpnext-python) - docker logs $CONTAINER_ID + docker logs ${CONTAINER_ID} exit 1 fi done -echo -e "\n" -echo -e "\e[1m\e[4mPing overwritten site\e[0m" -echo $RESTORE_STATUS -echo -e "\n" +echo -e "${NEWLINE}${ULINE}Ping overwritten site${ENDULINE}" +echo ${RESTORE_STATUS} -echo -e "\e[1m\e[4mCheck Overwritten Index Page\e[0m" +echo -e "${NEWLINE}${ULINE}Check Overwritten Index Page${ENDULINE}" curl -s http://test.localhost | w3m -T text/html -dump -echo -e "\n" -echo -e "\e[1m\e[4mCheck console command for site test.localhost\e[0m" +echo -e "${NEWLINE}${ULINE}Check console command for site test.localhost${ENDULINE}" docker run \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge console test.localhost -echo -e "\e[1m\e[4mCheck console command for site pgsql.localhost\e[0m" +echo -e "${NEWLINE}${ULINE}Check console command for site pgsql.localhost${ENDULINE}" docker run \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge console pgsql.localhost -echo -e "\e[1m\e[4mCheck drop site: test.localhost (mariadb)\e[0m" +echo -e "${NEWLINE}${ULINE}Check drop site: test.localhost (mariadb)${ENDULINE}" docker run \ -e SITE_NAME=test.localhost \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge drop -echo -e "\e[1m\e[4mCheck drop site: pgsql.localhost (pgsql)\e[0m" +echo -e "${NEWLINE}${ULINE}Check drop site: pgsql.localhost (pgsql)${ENDULINE}" docker run \ -e SITE_NAME=pgsql.localhost \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ frappe/erpnext-worker:edge drop -echo -e "\e[1m\e[4mCheck bench --help\e[0m" +echo -e "${NEWLINE}${ULINE}Check bench --help${ENDULINE}" docker run \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ --network frappebench00_default \ From 12eb5c92e4ba6d349a1582ea01e4ea90cd705dbb Mon Sep 17 00:00:00 2001 From: pratikbalar Date: Wed, 23 Jun 2021 09:13:24 +0530 Subject: [PATCH 2/7] refactor: bash scripts [stip travis] - shellchecke and shfmt checked and formatted - indentation 2 spaces - redirect errors to stderr - short if where possible - add function string to clarify visuaally identify its a funtion - make [ ... ] to [[ ... ]] - use == for comparision - use cat based notes - remove unecessary spaces - double quotes where needed --- build/common/worker/docker-entrypoint.sh | 208 +++++----- build/common/worker/healthcheck.sh | 42 +-- build/common/worker/install_app.sh | 6 +- build/erpnext-nginx/install_app.sh | 6 +- build/frappe-nginx/docker-entrypoint.sh | 69 ++-- frappe-installer | 370 +++++++++--------- tests/docker-test.sh | 461 +++++++++++------------ 7 files changed, 566 insertions(+), 596 deletions(-) diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index 48208dc8..f4aab241 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -3,38 +3,36 @@ function configureEnv() { if [[ ! -f /home/frappe/frappe-bench/sites/common_site_config.json ]]; then - if [[ -z "${MARIADB_HOST}" ]]; then - if [[ -z "${POSTGRES_HOST}" ]]; then - echo "MARIADB_HOST or POSTGRES_HOST is not set" - exit 1 - fi + if [[ -z "${MARIADB_HOST}" && -z "${POSTGRES_HOST}" ]]; then + echo "MARIADB_HOST or POSTGRES_HOST is not set" >&2 + exit 1 fi if [[ -z "${REDIS_CACHE}" ]]; then - echo "REDIS_CACHE is not set" + echo "REDIS_CACHE is not set" >&2 exit 1 fi if [[ -z "${REDIS_QUEUE}" ]]; then - echo "REDIS_QUEUE is not set" + echo "REDIS_QUEUE is not set" >&2 exit 1 fi if [[ -z "${REDIS_SOCKETIO}" ]]; then - echo "REDIS_SOCKETIO is not set" + echo "REDIS_SOCKETIO is not set" >&2 exit 1 fi if [[ -z "${SOCKETIO_PORT}" ]]; then - echo "SOCKETIO_PORT is not set" + echo "SOCKETIO_PORT is not set" >&2 exit 1 fi if [[ -z "${DB_PORT}" ]]; then - export DB_PORT=3306 + DB_PORT=3306 fi - export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" + DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" envsubst '${DB_HOST} ${DB_PORT} @@ -46,141 +44,143 @@ function configureEnv() { } function checkConnection() { - . /home/frappe/frappe-bench/env/bin/activate + /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/check_connection.py } function checkConfigExists() { COUNTER=0 - while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]] && [[ ${COUNTER} -le 30 ]]; do + while [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json && ${COUNTER} -le 30 ]]; do sleep 1 ((COUNTER = COUNTER + 1)) - echo "config file not created, retry ${COUNTER}" + echo "config file not created, retry ${COUNTER}" >&2 done if [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]]; then - echo "timeout: config file not created" + echo "timeout: config file not created" >&2 exit 1 fi } 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 + 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 # symlink node_modules ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \ /home/frappe/frappe-bench/apps/frappe/node_modules -if [[ "$1" == 'start' ]]; then - configureEnv - checkConnection +case "$1" in - if [[ -z "${WORKERS}" ]]; then - export WORKERS=2 - fi + start) + configureEnv + checkConnection - if [[ -z "${FRAPPE_PORT}" ]]; then - export FRAPPE_PORT=8000 - fi + [[ -z "${WORKERS}" ]] && WORKERS='2' - if [[ -z "${WORKER_CLASS}" ]]; then - export WORKER_CLASS=gthread - fi + [[ -z "${FRAPPE_PORT}" ]] && FRAPPE_PORT='8000' - export LOAD_CONFIG_FILE="" - if [ "${WORKER_CLASS}" = "gevent" ]; then - export LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" - fi + [[ -z "${WORKER_CLASS}" ]] && WORKER_CLASS='gthread' - if [[ ! -z "${AUTO_MIGRATE}" ]]; then - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/auto_migrate.py - fi + LOAD_CONFIG_FILE="" + [[ "${WORKER_CLASS}" == "gevent" ]] && + LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" - . /home/frappe/frappe-bench/env/bin/activate - gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ - --worker-tmp-dir /dev/shm \ - --threads=4 \ - --workers ${WORKERS} \ - --worker-class=${WORKER_CLASS} \ - --log-file=- \ - -t 120 frappe.app:application --preload + if [[ -n "${AUTO_MIGRATE}" ]]; then + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/auto_migrate.py + fi -elif [[ "$1" == 'worker' ]]; then - checkConfigExists - checkConnection - # default WORKER_TYPE=default + /home/frappe/frappe-bench/env/bin/activate + gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ + --worker-tmp-dir /dev/shm \ + --threads=4 \ + --workers ${WORKERS} \ + --worker-class=${WORKER_CLASS} \ + --log-file=- \ + -t 120 frappe.app:application --preload + ;; - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/worker.py + worker) + checkConfigExists + checkConnection + # default WORKER_TYPE=default -elif [[ "$1" == 'schedule' ]]; then - checkConfigExists - checkConnection + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/worker.py + ;; - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/background.py + schedule) + checkConfigExists + checkConnection -elif [[ "$1" == 'new' ]]; then - checkConfigExists - checkConnection + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/background.py - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/new.py - exit + ;; -elif [[ "$1" == 'drop' ]]; then - checkConfigExists - checkConnection + new) + checkConfigExists + checkConnection - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/drop.py - exit + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/new.py + exit + ;; -elif [[ "$1" = 'migrate' ]]; then + drop) + checkConfigExists + checkConnection - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/migrate.py - exit + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/drop.py + exit + ;; -elif [[ "$1" == 'doctor' ]]; then + migrate) + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/migrate.py + exit + ;; - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/doctor.py ${@:2} - exit + doctor) + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/doctor.py "${@:2}" + exit + ;; -elif [[ "$1" == 'backup' ]]; then + backup) - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/backup.py - exit + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/backup.py + exit + ;; -elif [[ "$1" == 'console' ]]; then + console) + if [[ -z "$2" ]]; then + echo "Need to specify a sitename with the command:" >&2 + echo "console " >&2 + exit 1 + fi - if [[ -z "$2" ]]; then - echo "Need to specify a sitename with the command:" - echo "console " - exit 1 - fi + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/console.py "$2" + exit + ;; - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/console.py "$2" - exit + push-backup) + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/push_backup.py + exit + ;; -elif [[ "$1" = 'push-backup' ]]; then - - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/push_backup.py - exit - -elif [[ "$1" = 'restore-backup' ]]; then - - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/restore_backup.py - exit - -else - exec $@ - -fi + restore-backup) + /home/frappe/frappe-bench/env/bin/activate + python /home/frappe/frappe-bench/commands/restore_backup.py + exit + ;; + *) + exec "$@" + ;; +esac diff --git a/build/common/worker/healthcheck.sh b/build/common/worker/healthcheck.sh index d6566924..6d378ded 100755 --- a/build/common/worker/healthcheck.sh +++ b/build/common/worker/healthcheck.sh @@ -2,42 +2,42 @@ set -ea function getUrl() { - cat ${1} | grep $2 | awk -v word=$2 '$word { gsub(/[",]/,"",$2); print $2}' | tr -d '\n' + grep "$2" "$1" | awk -v word="$2" '$word { gsub(/[",]/,"",$2); print $2}' | tr -d '\n' } COMMON_SITE_CONFIG_JSON='/home/frappe/frappe-bench/sites/common_site_config.json' # Set DB Host and port -DB_HOST=$(getUrl "$COMMON_SITE_CONFIG_JSON" "db_host") -DB_PORT=$(getUrl "$COMMON_SITE_CONFIG_JSON" "db_port") -if [[ -z "$DB_PORT" ]]; then +DB_HOST=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "db_host") +DB_PORT=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "db_port") +if [[ -z "${DB_PORT}" ]]; then DB_PORT=3306 fi # Set REDIS host:port -REDIS_CACHE=$(getUrl "$COMMON_SITE_CONFIG_JSON" "redis_cache" | sed 's|redis://||g') -if [[ "$REDIS_CACHE" == *"/"* ]]; then - REDIS_CACHE=$(echo $REDIS_CACHE | cut -f1 -d"/") +REDIS_CACHE=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "redis_cache" | sed 's|redis://||g') +if [[ "${REDIS_CACHE}" == *"/"* ]]; then + REDIS_CACHE=$(echo ${REDIS_CACHE} | cut -f1 -d"/") fi -REDIS_QUEUE=$(getUrl "$COMMON_SITE_CONFIG_JSON" "redis_queue" | sed 's|redis://||g') -if [[ "$REDIS_QUEUE" == *"/"* ]]; then - REDIS_QUEUE=$(echo $REDIS_QUEUE | cut -f1 -d"/") +REDIS_QUEUE=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "redis_queue" | sed 's|redis://||g') +if [[ "${REDIS_QUEUE}" == *"/"* ]]; then + REDIS_QUEUE=$(echo ${REDIS_QUEUE} | cut -f1 -d"/") fi -REDIS_SOCKETIO=$(getUrl "$COMMON_SITE_CONFIG_JSON" "redis_socketio" | sed 's|redis://||g') -if [[ "$REDIS_SOCKETIO" == *"/"* ]]; then - REDIS_SOCKETIO=$(echo $REDIS_SOCKETIO | cut -f1 -d"/") +REDIS_SOCKETIO=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "redis_socketio" | sed 's|redis://||g') +if [[ "${REDIS_SOCKETIO}" == *"/"* ]]; then + REDIS_SOCKETIO=$(echo ${REDIS_SOCKETIO} | cut -f1 -d"/") fi -echo "Check $DB_HOST:$DB_PORT" -wait-for-it "$DB_HOST:$DB_PORT" -t 1 -echo "Check $REDIS_CACHE" -wait-for-it "$REDIS_CACHE" -t 1 -echo "Check $REDIS_QUEUE" -wait-for-it "$REDIS_QUEUE" -t 1 -echo "Check $REDIS_SOCKETIO" -wait-for-it "$REDIS_SOCKETIO" -t 1 +echo "Check ${DB_HOST}:${DB_PORT}" +wait-for-it "${DB_HOST}:${DB_PORT}" -t 1 +echo "Check ${REDIS_CACHE}" +wait-for-it "${REDIS_CACHE}" -t 1 +echo "Check ${REDIS_QUEUE}" +wait-for-it "${REDIS_QUEUE}" -t 1 +echo "Check ${REDIS_SOCKETIO}" +wait-for-it "${REDIS_SOCKETIO}" -t 1 if [[ "$1" = "-p" || "$1" = "--ping-service" ]]; then echo "Check $2" diff --git a/build/common/worker/install_app.sh b/build/common/worker/install_app.sh index ceb8d3bd..3168c124 100755 --- a/build/common/worker/install_app.sh +++ b/build/common/worker/install_app.sh @@ -6,11 +6,11 @@ APP_BRANCH=${3} cd /home/frappe/frappe-bench/ -. env/bin/activate +env/bin/activate cd ./apps -[ "${APP_BRANCH}" ] && BRANCH="-b ${APP_BRANCH}" +[[ -n "${APP_BRANCH}" ]] && BRANCH="-b ${APP_BRANCH}" git clone --depth 1 -o upstream ${APP_REPO} ${BRANCH} ${APP_NAME} -pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/${APP_NAME} \ No newline at end of file +pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/${APP_NAME} diff --git a/build/erpnext-nginx/install_app.sh b/build/erpnext-nginx/install_app.sh index 49aee3d0..d3e30769 100755 --- a/build/erpnext-nginx/install_app.sh +++ b/build/erpnext-nginx/install_app.sh @@ -9,7 +9,7 @@ FRAPPE_BRANCH=${4} mkdir -p /home/frappe/frappe-bench/sites/assets cd /home/frappe/frappe-bench -echo -e "frappe\n${APP_NAME}" > /home/frappe/frappe-bench/sites/apps.txt +echo -ne "frappe\n${APP_NAME}" >/home/frappe/frappe-bench/sites/apps.txt mkdir -p apps cd apps @@ -36,8 +36,8 @@ mkdir -p /home/frappe/frappe-bench/sites/assets/${APP_NAME} cp -R /home/frappe/frappe-bench/apps/${APP_NAME}/${APP_NAME}/public/* /home/frappe/frappe-bench/sites/assets/${APP_NAME} # Add frappe and all the apps available under in frappe-bench here -echo "rsync -a --delete /var/www/html/assets/frappe /assets" > /rsync -echo "rsync -a --delete /var/www/html/assets/${APP_NAME} /assets" >> /rsync +echo "rsync -a --delete /var/www/html/assets/frappe /assets" >/rsync +echo "rsync -a --delete /var/www/html/assets/${APP_NAME} /assets" >>/rsync chmod +x /rsync rm /home/frappe/frappe-bench/sites/apps.txt diff --git a/build/frappe-nginx/docker-entrypoint.sh b/build/frappe-nginx/docker-entrypoint.sh index 68314676..e1a29277 100755 --- a/build/frappe-nginx/docker-entrypoint.sh +++ b/build/frappe-nginx/docker-entrypoint.sh @@ -1,63 +1,38 @@ -#!/bin/bash +#!/bin/bash -ae ## Thanks # https://serverfault.com/a/919212 ## -set -e - rsync -a --delete /var/www/html/assets/* /assets -. /rsync +/rsync -touch /var/www/html/sites/.build -r $(ls -td /assets/* | head -n 1) +touch /var/www/html/sites/.build -r "$(ls -td /assets/* | head -n 1)" -if [[ -z "$FRAPPE_PY" ]]; then - export FRAPPE_PY=0.0.0.0 -fi +[[ -z "${FRAPPE_PY}" ]] && FRAPPE_PY='0.0.0.0' -if [[ -z "$FRAPPE_PY_PORT" ]]; then - export FRAPPE_PY_PORT=8000 -fi +[[ -z "${FRAPPE_PY_PORT}" ]] && FRAPPE_PY_PORT='8000' -if [[ -z "$FRAPPE_SOCKETIO" ]]; then - export FRAPPE_SOCKETIO=0.0.0.0 -fi +[[ -z "${FRAPPE_SOCKETIO}" ]] && FRAPPE_SOCKETIO='0.0.0.0' -if [[ -z "$SOCKETIO_PORT" ]]; then - export SOCKETIO_PORT=9000 -fi +[[ -z "${SOCKETIO_PORT}" ]] && SOCKETIO_PORT='9000' -if [[ -z "$HTTP_TIMEOUT" ]]; then - export HTTP_TIMEOUT=120 -fi +[[ -z "${HTTP_TIMEOUT}" ]] && HTTP_TIMEOUT='120' -if [[ -z "$UPSTREAM_REAL_IP_ADDRESS" ]]; then - export UPSTREAM_REAL_IP_ADDRESS=127.0.0.1 -fi +[[ -z "${UPSTREAM_REAL_IP_ADDRESS}" ]] && UPSTREAM_REAL_IP_ADDRESS='127.0.0.1' -if [[ -z "$UPSTREAM_REAL_IP_RECURSIVE" ]]; then - export UPSTREAM_REAL_IP_RECURSIVE=off -fi +[[ -z "${UPSTREAM_REAL_IP_RECURSIVE}" ]] && UPSTREAM_REAL_IP_RECURSIVE='off' -if [[ -z "$UPSTREAM_REAL_IP_HEADER" ]]; then - export UPSTREAM_REAL_IP_HEADER="X-Forwarded-For" -fi +[[ -z "${UPSTREAM_REAL_IP_HEADER}" ]] && UPSTREAM_REAL_IP_HEADER='X-Forwarded-For' -if [[ -z "$FRAPPE_SITE_NAME_HEADER" ]]; then - export FRAPPE_SITE_NAME_HEADER="\$host" -fi +[[ -z "${FRAPPE_SITE_NAME_HEADER}" ]] && FRAPPE_SITE_NAME_HEADER="\$host" -if [[ -z "$HTTP_HOST" ]]; then - export HTTP_HOST="\$http_host" -fi +[[ -z "${HTTP_HOST}" ]] && HTTP_HOST="\$http_host" -if [[ -z "$SKIP_NGINX_TEMPLATE_GENERATION" ]]; then - export SKIP_NGINX_TEMPLATE_GENERATION=0 -fi +[[ -z "${SKIP_NGINX_TEMPLATE_GENERATION}" ]] && SKIP_NGINX_TEMPLATE_GENERATION='0' -if [[ $SKIP_NGINX_TEMPLATE_GENERATION -eq 1 ]] -then +if [[ ${SKIP_NGINX_TEMPLATE_GENERATION} == 1 ]]; then echo "Skipping default NGINX template generation. Please mount your own NGINX config file inside /etc/nginx/conf.d" else echo "Generating default template" @@ -71,14 +46,14 @@ else ${FRAPPE_SITE_NAME_HEADER} ${HTTP_HOST} ${UPSTREAM_REAL_IP_HEADER}' \ - < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf + /etc/nginx/conf.d/default.conf fi -echo "Waiting for frappe-python to be available on $FRAPPE_PY port $FRAPPE_PY_PORT" -timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' $FRAPPE_PY $FRAPPE_PY_PORT -echo "Frappe-python available on $FRAPPE_PY port $FRAPPE_PY_PORT" -echo "Waiting for frappe-socketio to be available on $FRAPPE_SOCKETIO port $SOCKETIO_PORT" -timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' $FRAPPE_SOCKETIO $SOCKETIO_PORT -echo "Frappe-socketio available on $FRAPPE_SOCKETIO port $SOCKETIO_PORT" +echo "Waiting for frappe-python to be available on ${FRAPPE_PY} port ${FRAPPE_PY_PORT}" +timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' ${FRAPPE_PY} ${FRAPPE_PY_PORT} +echo "Frappe-python available on ${FRAPPE_PY} port ${FRAPPE_PY_PORT}" +echo "Waiting for frappe-socketio to be available on ${FRAPPE_SOCKETIO} port ${SOCKETIO_PORT}" +timeout 10 bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/$0/$1; do sleep 1; done' ${FRAPPE_SOCKETIO} ${SOCKETIO_PORT} +echo "Frappe-socketio available on ${FRAPPE_SOCKETIO} port ${SOCKETIO_PORT}" exec "$@" diff --git a/frappe-installer b/frappe-installer index e3290bdd..e379f84b 100755 --- a/frappe-installer +++ b/frappe-installer @@ -3,8 +3,7 @@ set -euo pipefail IFS=$'\n\t' -[ -z "$DEBUG" ] & [ "${DEBUG}" == 1 ] && set -o xtrace - +[[ -z "${DEBUG}" && "${DEBUG}" == 1 ]] && set -o xtrace __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$__dir" @@ -14,227 +13,236 @@ docker_nginx_url="https://github.com/evertramos/docker-compose-letsencrypt-nginx frappe_docker_url="https://github.com/frappe/frappe_docker" env_file="$__dir/.env" - -check_root() { - if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root. Login as root or use sudo." 1>&2 - exit 1 - fi +function check_root() { + if [[ $EUID != 0 ]]; then + echo "This script must be run as root. Login as root or use sudo." >&2 + exit 1 + fi } -check_git() { - if [ ! -x "$(command -v git)" ]; then - echo "Git is not installed. Please install git before continuing." - exit 1 - fi +function check_git() { + if [[ ! -x "$(command -v git)" ]]; then + echo "Git is not installed. Please install git before continuing." >&2 + exit 1 + fi } -check_docker() { - if [ ! -x "$(command -v docker)" ]; then - read -rp "No docker installation found. Press Enter to install docker or ctrl+c to exit." - curl -fsSL https://get.docker.com | sh - fi - if [ ! -x "$(command -v docker)" ]; then - echo "Docker installation failed. Exiting." - exit 1 - fi +function check_docker() { + if [[ ! -x "$(command -v docker)" ]]; then + read -rp "No docker installation found. Press Enter to install docker or ctrl+c to exit." >&2 + curl -fsSL https://get.docker.com | sh + fi + if [[ ! -x "$(command -v docker)" ]]; then + echo "Docker installation failed. Exiting." >&2 + exit 1 + fi } -check_env() { - if [ ! -f "$env_file" ]; then - echo "No environment file found. This file is required for setting up Frappe/ERPNext Docker." - echo "Would you like to fetch the default environment file?" - echo "(NOTE: You will be prompted to set it up later)" - read -rp "Press Enter to fetch the configuration file, or create a .env file and re-run the script." - curl -fsSL "$env_url" -o "$env_file" - fi +function check_env() { + if [[ ! -f "$env_file" ]]; then + cat <&2 + No environment file found. This file is required for setting up Frappe/ERPNext Docker. + Would you like to fetch the default environment file? + (NOTE: You will be prompted to set it up later) +CHOOSE + read -rp "Press Enter to fetch the configuration file, or create a .env file and re-run the script." + curl -fsSL "$env_url" -o "$env_file" + fi } -clone_repository() { - echo "Cloning Repository: $1" - git clone "$2" +function clone_repository() { + echo "Cloning Repository: $1" + git clone "$2" } -get_config() { - if [ -n "$2" ]; then - config_file="$2" - else - config_file="$env_file" - fi - line=$(grep -E "^$=" "$config_file") - line_result=$(echo "$line" | awk -F"=" '{print $2}') +function get_config() { + if [[ -n "$2" ]]; then + config_file="$2" + else + config_file="$env_file" + fi + line=$(grep -E "^$=" "$config_file") + line_result=$(echo "$line" | awk -F"=" '{print $2}') } -get_install_version() { - echo "Choose a version you would like to setup [current: $1]:" - echo "1. develop (edge)" - echo "2. version-12" - echo "3. version-11" - echo "Please enter your choice [1-3]: " - select choice in "1" "2" "3"; do - case $choice in - 1 ) version="edge" ;; - 2 ) version="version-12" ;; - 3 ) version="version-11" ;; - esac - done +function get_install_version() { + cat <&2 + Choose a version you would like to setup [current: $1]: + 1. develop (edge) + 2. version-12 + 3. version-11 + Please enter your choice [1-3]: +CHOOSE + select choice in "1" "2" "3"; do + case ${choice} in + 1) version="edge" ;; + 2) version="version-12" ;; + 3) version="version-11" ;; + esac + done } -prompt_config() { - # inspired by discourse_docker - get_config "VERSION" - local install_version=$line_result - get_config "MYSQL_ROOT_PASSWORD" - local mysql_password=$line_result - get_config "SITES" - local sites=$line_result - get_config "LETSENCRYPT_EMAIL" - local letsencrypt_email=$line_result +function prompt_config() { + # inspired by discourse_docker + get_config "VERSION" + local install_version=$line_result + get_config "MYSQL_ROOT_PASSWORD" + local mysql_password=$line_result + get_config "SITES" + local sites=$line_result + get_config "LETSENCRYPT_EMAIL" + local letsencrypt_email=$line_result - echo "Would you like to setup networking for docker? [y/n]" - echo "This is required if you wish to access the instance from other machines." + echo "Would you like to setup networking for docker? [y/n]" + echo "This is required if you wish to access the instance from other machines." + select choice in "y" "n"; do + case $choice in + y) setup_networking=1 ;; + n) + setup_networking=0 + setup_letsencrypt=0 + ;; + esac + done + if [[ -n "$letsencrypt_email" && "$setup_networking" -ne "0" ]]; then + echo "Would you like to setup LetsEncrypt? [y/n]" select choice in "y" "n"; do - case $choice in - y ) setup_networking=1 ;; - n ) setup_networking=0 - setup_letsencrypt=0 ;; - esac + case $choice in + y) + setup_letsencrypt=1 + echo "Please ensure that all the required domains point to this IP address." + read -rp "Enter an Email Address to setup LetsEncrypt with: " letsencrypt_email + ;; + n) + setup_letsencrypt=0 + echo "Skipping LetsEncrypt Setup." + ;; + esac done - if [ -n "$letsencrypt_email" ] & [ "$setup_networking" -ne "0" ]; then - echo "Would you like to setup LetsEncrypt? [y/n]" - select choice in "y" "n"; do - case $choice in - y ) setup_letsencrypt=1 - echo "Please ensure that all the required domains point to this IP address." - read -rp "Enter an Email Address to setup LetsEncrypt with: " letsencrypt_email ;; - n ) setup_letsencrypt=0 - echo "Skipping LetsEncrypt Setup." ;; - esac - done + fi + + local new_value="" + local config_state="n" + + echo + + get_install_version "$install_version" + install_version="$version" + + while [[ "$config_state" == "n" ]]; do + if [[ -n "$mysql_password" ]]; then + read -srp "Enter MySQL Password [$mysql_password]: " new_value + if [[ -n "$new_value" ]]; then + mysql_password="$new_value" + fi fi - local new_value="" - local config_state="n" + if [[ -n "$sites" ]]; then + read -rp "Enter sitename to setup [$sites]: " new_value + if [[ -n "$new_value" ]]; then + sites="$new_value" + fi + fi + + if [[ "$setup_letsencrypt" != "0" ]]; then + read -rp "Enter email address for LetsEncrypt [$letsencrypt_email]: " new_value + if [[ -n "$new_value" ]]; then + letsencrypt_email=$new_value + fi + fi + + echo "Current Configuration:" + echo "Version: $([[ "$install_version" == "edge" ]] && echo "develop" || echo "$install_version")" + echo "MySQL Root Password: $mysql_password" + echo "Sites: $sites" + + if [[ "$setup_letsencrypt" != "0" ]]; then + echo "LetsEncrypt Email Address: $letsencrypt_email" + fi echo + echo "Does this configuration look okay?" + read -rp "Press Enter to continue, 'n' to try again, or ctrl+c to exit: " config_state + done - get_install_version "$install_version" - install_version="$version" + echo "Saving the current configuration file to $env_file" - while [ "$config_state" = "n" ]; do - if [ -n "$mysql_password" ]; then - read -srp "Enter MySQL Password [$mysql_password]: " new_value - if [ -n "$new_value" ]; then - mysql_password="$new_value" - fi - fi - - if [ -n "$sites" ]; then - read -rp "Enter sitename to setup [$sites]: " new_value - if [ -n "$new_value" ]; then - sites="$new_value" - fi - fi - - if [ "$setup_letsencrypt" -ne "0" ]; then - read -rp "Enter email address for LetsEncrypt [$letsencrypt_email]: " new_value - if [ -n "$new_value" ]; then - letsencrypt_email=$new_value - fi - fi - - echo "Current Configuration:" - echo "Version: $([ "$install_version" = "edge" ] && echo "develop" || echo "$install_version")" - echo "MySQL Root Password: $mysql_password" - echo "Sites: $sites" - - if [ "$setup_letsencrypt" -ne "0" ]; then - echo "LetsEncrypt Email Address: $letsencrypt_email" - fi - - echo - echo "Does this configuration look okay?" - read -rp "Press Enter to continue, 'n' to try again, or ctrl+c to exit: " config_state - done - - echo "Saving the current configuration file to $env_file" - - cat << EOF > "$env_file" + cat <"$env_file" VERSION=$install_version MYSQL_ROOT_PASSWORD=$mysql_password SITES=$sites $([ "$setup_letsencrypt" -ne "0" ] && echo "LETSENCRYPT_EMAIL=$letsencrypt_email") EOF - setup_configuration=$(<"$env_file") + setup_configuration=$(<"$env_file") } setup_user() { - echo "The rest of the setup requires a user account." - echo "You may use an existing account, or set up a new one right away." - read -rp "Enter username: " username - if grep -E "^$username" /etc/passwd > /dev/null; then - echo "User $username already exists." + echo "The rest of the setup requires a user account." + echo "You may use an existing account, or set up a new one right away." + read -rp "Enter username: " username + if grep -E "^$username" /etc/passwd >/dev/null; then + echo "User $username already exists." + else + read -rsp "Enter password: " password + password="$(perl -e 'print crypt($ARGV[0], "password")' "$password")" + if useradd -m -p "$password" "$username" -s "$(command -v bash)"; then + echo "User $username has been added to the system." else - read -rsp "Enter password: " password - password="$(perl -e 'print crypt($ARGV[0], "password")' "$password")" - if useradd -m -p "$password" "$username" -s "$(command -v bash)"; then - echo "User $username has been added to the system." - else - echo "Failed to add user to the system." - echo "Please add a user manually and re-run the script." - exit 1 - fi + echo "Failed to add user to the system." + echo "Please add a user manually and re-run the script." + exit 1 fi + fi - if ! getent group docker > /dev/null 2>&1 ; then - echo "Creating group: docker" - groupadd docker - fi - echo "Adding user $username to group: docker" - usermod -aG docker "$username" - newgrp docker + if ! getent group docker >/dev/null 2>&1; then + echo "Creating group: docker" + groupadd docker + fi + echo "Adding user $username to group: docker" + usermod -aG docker "$username" + newgrp docker } install() { - if [ "$setup_letsencrypt" -ne "0" ] & [ "$setup_networking" -ne "0" ]; then - echo "Setting up NGINX Proxy for LetsEncrypt" - clone_repository "Docker Compose LetsEncrypt NGINX Proxy Companion" "$docker_nginx_url" - cd "$(basename "$docker_nginx_url")" - if [ -f .env.sample ]; then - cp .env.sample env - fi - ./start.sh > /dev/null 2>&1 - cd "$(eval echo ~"$username")" + if [[ "$setup_letsencrypt" != "0" && "$setup_networking" != "0" ]]; then + echo "Setting up NGINX Proxy for LetsEncrypt" + clone_repository "Docker Compose LetsEncrypt NGINX Proxy Companion" "$docker_nginx_url" + cd "$(basename "$docker_nginx_url")" + if [[ -f .env.sample ]]; then + cp .env.sample env fi + ./start.sh >/dev/null 2>&1 + cd "$(eval echo ~"$username")" + fi - echo "Setting up Frappe/ERPNext" - clone_repository "Frappe/ERPNext Docker" "$frappe_docker_url" - cd "$(basename "$frappe_docker_url")" - echo "$setup_configuration" > .env - echo "Enter a name for the project." - read -rp "This project name will be used to setup the docker instance: [erpnext_docker]" project_name - if [ -z "$project_name" ]; then - echo "Setting the project name to erpnext_docker" - project_name="erpnext_docker" - fi + echo "Setting up Frappe/ERPNext" + clone_repository "Frappe/ERPNext Docker" "$frappe_docker_url" + cd "$(basename "$frappe_docker_url")" + echo "$setup_configuration" >.env + echo "Enter a name for the project." + read -rp "This project name will be used to setup the docker instance: [erpnext_docker]" project_name + if [[ -z "$project_name" ]]; then + echo "Setting the project name to erpnext_docker" + project_name="erpnext_docker" + fi - docker-compose \ - --project-name "$project_name" \ - --project-directory . up -d \ - -f installation/docker-compose-frappe.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/docker-compose-common.yml \ - "$( (( setup_networking == 1 )) && printf %s '-f installation/docker-compose-networks.yml' )" + docker-compose \ + --project-name "$project_name" \ + --project-directory . up -d \ + -f installation/docker-compose-frappe.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/docker-compose-common.yml \ + "$( ((setup_networking == 1)) && printf %s '-f installation/docker-compose-networks.yml')" - get_config "SITES" "$(pwd)/.env" - local sites=$line_result + get_config "SITES" "$(pwd)/.env" + local sites=$line_result - docker exec \ - -e "SITE_NAME=$sites" \ - -e "INSTALL_ERPNEXT=1" \ - -it "$project_name"_erpnext-python_1 docker-entrypoint.sh new + docker exec \ + -e "SITE_NAME=$sites" \ + -e "INSTALL_ERPNEXT=1" \ + -it "$project_name"_erpnext-python_1 docker-entrypoint.sh new - echo "Installation Complete!" + echo "Installation Complete!" } check_root @@ -244,4 +252,4 @@ check_env prompt_config setup_user -install \ No newline at end of file +install diff --git a/tests/docker-test.sh b/tests/docker-test.sh index 0a03b233..5b917f21 100755 --- a/tests/docker-test.sh +++ b/tests/docker-test.sh @@ -4,47 +4,47 @@ ENDULINE='\e[0m' NEWLINE='\n' function checkMigrationComplete() { - echo "Check Migration" - CONTAINER_ID=$(docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - ps -q erpnext-python) + echo "Check Migration" + CONTAINER_ID=$(docker-compose \ + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + ps -q erpnext-python) + DOCKER_LOG=$(docker logs ${CONTAINER_ID} 2>&1 | grep "Starting gunicorn") + INCREMENT=0 + while [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -lt 60 ]]; do + sleep 3 + echo "Wait for migration to complete ..." + ((INCREMENT = INCREMENT + 1)) DOCKER_LOG=$(docker logs ${CONTAINER_ID} 2>&1 | grep "Starting gunicorn") - INCREMENT=0 - while [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -lt 60 ]]; do - sleep 3 - echo "Wait for migration to complete ..." - ((INCREMENT = INCREMENT + 1)) - DOCKER_LOG=$(docker logs ${CONTAINER_ID} 2>&1 | grep "Starting gunicorn") - if [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -eq 60 ]]; then - docker logs ${CONTAINER_ID} - exit 1 - fi - done + if [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -eq 60 ]]; then + docker logs ${CONTAINER_ID} + exit 1 + fi + done - echo -e "${ULINE}Migration Log${ENDULINE}" - docker logs ${CONTAINER_ID} + echo -e "${ULINE}Migration Log${ENDULINE}" + docker logs ${CONTAINER_ID} } function loopHealthCheck() { - echo "Create Container to Check MariaDB" - docker run --name frappe_doctor \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge doctor || true + echo "Create Container to Check MariaDB" + docker run --name frappe_doctor \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge doctor || true - echo "Loop Health Check" + echo "Loop Health Check" + FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "") + while [[ -z "${FRAPPE_LOG}" ]]; do + sleep 1 + CONTAINER=$(docker start frappe_doctor) + echo "Restarting ${CONTAINER} ..." FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "") - while [[ -z "${FRAPPE_LOG}" ]]; do - sleep 1 - CONTAINER=$(docker start frappe_doctor) - echo "Restarting ${CONTAINER} ..." - FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "") - done - echo "Health check successful" + done + echo "Health check successful" } echo -e "${ULINE}Copy env-example file${ENDULINE}" @@ -55,34 +55,34 @@ sed -i -e "s/edge/v13/g" .env echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}" docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - pull + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + pull docker pull postgres:11.8 docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - up -d + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + up -d # Start postgres docker run --name postgresql -d \ - -e "POSTGRES_PASSWORD=admin" \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - postgres:11.8 + -e "POSTGRES_PASSWORD=admin" \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + postgres:11.8 loopHealthCheck echo -e "${NEWLINE}${ULINE}Create new site (v13)${ENDULINE}" docker run -it \ - -e "SITE_NAME=test.localhost" \ - -e "INSTALL_APPS=erpnext" \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:v13 new + -e "SITE_NAME=test.localhost" \ + -e "INSTALL_APPS=erpnext" \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:v13 new echo -e "${NEWLINE}${ULINE}Ping created site${ENDULINE}" curl -sS http://test.localhost/api/method/version @@ -95,17 +95,17 @@ sed -i -e "s/v13/edge/g" .env echo -e "${NEWLINE}${ULINE}Restart containers with edge image${ENDULINE}" docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - stop + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + stop docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - up -d + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + up -d checkMigrationComplete @@ -113,157 +113,144 @@ echo -e "${NEWLINE}${ULINE}Ping migrated site${ENDULINE}" sleep 3 curl -sS http://test.localhost/api/method/version - echo -e "${NEWLINE}${ULINE}Check Migrated Site Index Page${ENDULINE}" curl -s http://test.localhost | w3m -T text/html -dump - echo -e "${NEWLINE}${ULINE}Create new site (pgsql)${ENDULINE}" docker run -it \ - -e "SITE_NAME=pgsql.localhost" \ - -e "POSTGRES_HOST=postgresql" \ - -e "DB_ROOT_USER=postgres" \ - -e "POSTGRES_PASSWORD=admin" \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge new - + -e "SITE_NAME=pgsql.localhost" \ + -e "POSTGRES_HOST=postgresql" \ + -e "DB_ROOT_USER=postgres" \ + -e "POSTGRES_PASSWORD=admin" \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge new echo -e "${NEWLINE}${ULINE}Check New PGSQL Site${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") INCREMENT=0 while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do - sleep 1 - echo -e "${ULINE}Wait for restoration to complete ..." - RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") - ((INCREMENT = INCREMENT + 1)) - if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then - CONTAINER_ID=$(docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - ps -q erpnext-python) - docker logs ${CONTAINER_ID} - exit 1 - fi + sleep 1 + echo -e "${ULINE}Wait for restoration to complete ..." + RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then + CONTAINER_ID=$(docker-compose \ + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + ps -q erpnext-python) + docker logs ${CONTAINER_ID} + exit 1 + fi done - echo -e "${NEWLINE}${ULINE}Ping new pgsql site${ENDULINE}" echo $RESTORE_STATUS - echo -e "${NEWLINE}${ULINE}Check New PGSQL Index Page${ENDULINE}" curl -s http://pgsql.localhost | w3m -T text/html -dump - echo -e "${NEWLINE}${ULINE}Backup site${ENDULINE}" docker run -it \ - -e "WITH_FILES=1" \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge backup + -e "WITH_FILES=1" \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge backup -export MINIO_ACCESS_KEY="AKIAIOSFODNN7EXAMPLE" -export MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" +MINIO_ACCESS_KEY="AKIAIOSFODNN7EXAMPLE" +MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" echo -e "${ULINE}Start MinIO container for s3 compatible storage${ENDULINE}" docker run -d --name minio \ - -e "MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}" \ - -e "MINIO_SECRET_KEY=${MINIO_SECRET_KEY}" \ - --network frappebench00_default \ - minio/minio server /data - + -e "MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}" \ + -e "MINIO_SECRET_KEY=${MINIO_SECRET_KEY}" \ + --network frappebench00_default \ + minio/minio server /data echo -e "${NEWLINE}${ULINE}Create bucket named erpnext${ENDULINE}" docker run \ - --network frappebench00_default \ - vltgroup/s3cmd:latest s3cmd --access_key=${MINIO_ACCESS_KEY} \ - --secret_key=${MINIO_SECRET_KEY} \ - --region=us-east-1 \ - --no-ssl \ - --host=minio:9000 \ - --host-bucket=minio:9000 \ - mb s3://erpnext - + --network frappebench00_default \ + vltgroup/s3cmd:latest s3cmd --access_key=${MINIO_ACCESS_KEY} \ + --secret_key=${MINIO_SECRET_KEY} \ + --region=us-east-1 \ + --no-ssl \ + --host=minio:9000 \ + --host-bucket=minio:9000 \ + mb s3://erpnext echo -e "${NEWLINE}${NEWLINE}${ULINE}Push backup to MinIO s3${ENDULINE}" docker run \ - -e BUCKET_NAME=erpnext \ - -e REGION=us-east-1 \ - -e BUCKET_DIR=local \ - -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ - -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ - -e ENDPOINT_URL=http://minio:9000 \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge push-backup - + -e BUCKET_NAME=erpnext \ + -e REGION=us-east-1 \ + -e BUCKET_DIR=local \ + -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ + -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ + -e ENDPOINT_URL=http://minio:9000 \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge push-backup echo -e "${NEWLINE}${ULINE}Stop Services${ENDULINE}" docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - stop - + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + stop echo -e "${NEWLINE}${ULINE}Prune Containers${ENDULINE}" docker container prune -f && docker volume prune -f - echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}" docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - up -d + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + up -d loopHealthCheck - echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3${ENDULINE}" docker run \ - -e MYSQL_ROOT_PASSWORD=admin \ - -e BUCKET_NAME=erpnext \ - -e BUCKET_DIR=local \ - -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ - -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ - -e ENDPOINT_URL=http://minio:9000 \ - -e REGION=us-east-1 \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge restore-backup + -e MYSQL_ROOT_PASSWORD=admin \ + -e BUCKET_NAME=erpnext \ + -e BUCKET_DIR=local \ + -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ + -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ + -e ENDPOINT_URL=http://minio:9000 \ + -e REGION=us-east-1 \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge restore-backup echo -e "${NEWLINE}${ULINE}Check Restored Site (test)${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") INCREMENT=0 while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do - sleep 1 - echo "Wait for restoration to complete ..." - RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") - ((INCREMENT = INCREMENT + 1)) - if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then - CONTAINER_ID=$(docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - ps -q erpnext-python) - docker logs ${CONTAINER_ID} - exit 1 - fi + sleep 1 + echo "Wait for restoration to complete ..." + RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then + CONTAINER_ID=$(docker-compose \ + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + ps -q erpnext-python) + docker logs ${CONTAINER_ID} + exit 1 + fi done echo -e "${ULINE}Ping restored site (test)${ENDULINE}" echo ${RESTORE_STATUS} - echo -e "${NEWLINE}${ULINE}Check Restored Site Index Page (test)${ENDULINE}" curl -s http://test.localhost | w3m -T text/html -dump @@ -272,20 +259,20 @@ sleep 3 RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") INCREMENT=0 while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do - sleep 1 - echo "Wait for restoration to complete ..." - RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") - ((INCREMENT = INCREMENT + 1)) - if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then - CONTAINER_ID=$(docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - ps -q erpnext-python) - docker logs ${CONTAINER_ID} - exit 1 - fi + sleep 1 + echo "Wait for restoration to complete ..." + RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then + CONTAINER_ID=$(docker-compose \ + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + ps -q erpnext-python) + docker logs ${CONTAINER_ID} + exit 1 + fi done echo -e "${ULINE}Ping restored site (pgsql)${ENDULINE}" @@ -296,31 +283,31 @@ curl -s http://pgsql.localhost | w3m -T text/html -dump echo -e "${NEWLINE}${ULINE}Create new site (edge)${ENDULINE}" docker run -it \ - -e "SITE_NAME=edge.localhost" \ - -e "INSTALL_APPS=erpnext" \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge new + -e "SITE_NAME=edge.localhost" \ + -e "INSTALL_APPS=erpnext" \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge new echo -e "${NEWLINE}${ULINE}Check New Edge Site${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") INCREMENT=0 while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do - sleep 1 - echo -e "${ULINE}Wait for restoration to complete ...${ENDULINE}" - RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") - ((INCREMENT = INCREMENT + 1)) - if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then - CONTAINER_ID=$(docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - ps -q erpnext-python) - docker logs ${CONTAINER_ID} - exit 1 - fi + sleep 1 + echo -e "${ULINE}Wait for restoration to complete ...${ENDULINE}" + RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then + CONTAINER_ID=$(docker-compose \ + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + ps -q erpnext-python) + docker logs ${CONTAINER_ID} + exit 1 + fi done echo -e "${NEWLINE}${ULINE}Ping new edge site${ENDULINE}" @@ -331,46 +318,46 @@ curl -s http://edge.localhost | w3m -T text/html -dump echo -e "${NEWLINE}${ULINE}Migrate command in edge container${ENDULINE}" docker run -it \ - -e "MAINTENANCE_MODE=1" \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - -v frappebench00_assets-vol:/home/frappe/frappe-bench/sites/assets \ - --network frappebench00_default \ - frappe/erpnext-worker:edge migrate + -e "MAINTENANCE_MODE=1" \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + -v frappebench00_assets-vol:/home/frappe/frappe-bench/sites/assets \ + --network frappebench00_default \ + frappe/erpnext-worker:edge migrate checkMigrationComplete echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3 (Overwrite)${ENDULINE}" docker run \ - -e MYSQL_ROOT_PASSWORD=admin \ - -e BUCKET_NAME=erpnext \ - -e BUCKET_DIR=local \ - -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ - -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ - -e ENDPOINT_URL=http://minio:9000 \ - -e REGION=us-east-1 \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge restore-backup + -e MYSQL_ROOT_PASSWORD=admin \ + -e BUCKET_NAME=erpnext \ + -e BUCKET_DIR=local \ + -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ + -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ + -e ENDPOINT_URL=http://minio:9000 \ + -e REGION=us-east-1 \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge restore-backup echo -e "${NEWLINE}${ULINE}Check Overwritten Site${ENDULINE}" sleep 3 RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") INCREMENT=0 while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do - sleep 1 - echo -e "${ULINE}Wait for restoration to complete ..." - RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") - ((INCREMENT = INCREMENT + 1)) - if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then - CONTAINER_ID=$(docker-compose \ - --project-name frappebench00 \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - ps -q erpnext-python) - docker logs ${CONTAINER_ID} - exit 1 - fi + sleep 1 + echo -e "${ULINE}Wait for restoration to complete ..." + RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") + ((INCREMENT = INCREMENT + 1)) + if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then + CONTAINER_ID=$(docker-compose \ + --project-name frappebench00 \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + ps -q erpnext-python) + docker logs ${CONTAINER_ID} + exit 1 + fi done echo -e "${NEWLINE}${ULINE}Ping overwritten site${ENDULINE}" @@ -381,33 +368,33 @@ curl -s http://test.localhost | w3m -T text/html -dump echo -e "${NEWLINE}${ULINE}Check console command for site test.localhost${ENDULINE}" docker run \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge console test.localhost + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge console test.localhost echo -e "${NEWLINE}${ULINE}Check console command for site pgsql.localhost${ENDULINE}" docker run \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge console pgsql.localhost + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge console pgsql.localhost echo -e "${NEWLINE}${ULINE}Check drop site: test.localhost (mariadb)${ENDULINE}" docker run \ - -e SITE_NAME=test.localhost \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge drop + -e SITE_NAME=test.localhost \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge drop echo -e "${NEWLINE}${ULINE}Check drop site: pgsql.localhost (pgsql)${ENDULINE}" docker run \ - -e SITE_NAME=pgsql.localhost \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - frappe/erpnext-worker:edge drop + -e SITE_NAME=pgsql.localhost \ + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + frappe/erpnext-worker:edge drop echo -e "${NEWLINE}${ULINE}Check bench --help${ENDULINE}" docker run \ - -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ - --network frappebench00_default \ - --user frappe \ - frappe/erpnext-worker:edge bench --help + -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ + --network frappebench00_default \ + --user frappe \ + frappe/erpnext-worker:edge bench --help From 6c8c1c01beb509b5819cb25d069e3eaa421a06c6 Mon Sep 17 00:00:00 2001 From: pratikbalar Date: Wed, 23 Jun 2021 09:58:14 +0530 Subject: [PATCH 3/7] refactor: fix permission issue --- build/common/worker/docker-entrypoint.sh | 26 ++++++++++++------------ build/common/worker/install_app.sh | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index f4aab241..53db3141 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -44,7 +44,7 @@ function configureEnv() { } function checkConnection() { - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/check_connection.py } @@ -88,11 +88,11 @@ case "$1" in LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" if [[ -n "${AUTO_MIGRATE}" ]]; then - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/auto_migrate.py fi - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ --worker-tmp-dir /dev/shm \ --threads=4 \ @@ -107,7 +107,7 @@ case "$1" in checkConnection # default WORKER_TYPE=default - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/worker.py ;; @@ -115,7 +115,7 @@ case "$1" in checkConfigExists checkConnection - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/background.py ;; @@ -124,7 +124,7 @@ case "$1" in checkConfigExists checkConnection - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/new.py exit ;; @@ -133,26 +133,26 @@ case "$1" in checkConfigExists checkConnection - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/drop.py exit ;; migrate) - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/migrate.py exit ;; doctor) - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/doctor.py "${@:2}" exit ;; backup) - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/backup.py exit ;; @@ -164,19 +164,19 @@ case "$1" in exit 1 fi - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/console.py "$2" exit ;; push-backup) - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/push_backup.py exit ;; restore-backup) - /home/frappe/frappe-bench/env/bin/activate + . /home/frappe/frappe-bench/env/bin/activate python /home/frappe/frappe-bench/commands/restore_backup.py exit ;; diff --git a/build/common/worker/install_app.sh b/build/common/worker/install_app.sh index 3168c124..ae463711 100755 --- a/build/common/worker/install_app.sh +++ b/build/common/worker/install_app.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -ex APP_NAME=${1} APP_REPO=${2} @@ -6,7 +6,7 @@ APP_BRANCH=${3} cd /home/frappe/frappe-bench/ -env/bin/activate +. env/bin/activate cd ./apps From 391ee4c74e7a88a90679af9a144fda1f1abab808 Mon Sep 17 00:00:00 2001 From: pratikbalar Date: Wed, 23 Jun 2021 12:26:11 +0530 Subject: [PATCH 4/7] refactor: export db host to [skip travis] - to pass shellcheck rule SC2034 --- build/common/worker/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index 53db3141..bbee3b2e 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -32,7 +32,7 @@ function configureEnv() { DB_PORT=3306 fi - DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" + export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" envsubst '${DB_HOST} ${DB_PORT} From 86a2fcc1faea96999f0321d4f368c476f62629ec Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 24 Jun 2021 16:54:17 +0530 Subject: [PATCH 5/7] ci: check shell script format --- .travis.yml | 3 +- CONTRIBUTING.md | 30 ++++++++++++++++++ build/common/worker/docker-entrypoint.sh | 39 ++++++++---------------- build/common/worker/install_app.sh | 10 ++---- tests/check-format.sh | 11 +++++++ 5 files changed, 58 insertions(+), 35 deletions(-) create mode 100755 tests/check-format.sh diff --git a/.travis.yml b/.travis.yml index 9a2b7c9f..6d6f8fcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -156,8 +156,9 @@ jobs: - sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose - sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose - - sudo apt-get update && sudo apt-get -y install w3m + - sudo apt-get update && sudo apt-get -y install w3m shellcheck script: + - ./tests/check-format.sh - docker build -t frappe/frappe-socketio:edge -f build/frappe-socketio/Dockerfile . - docker build -t frappe/frappe-worker:develop -f build/frappe-worker/Dockerfile . - docker build -t frappe/erpnext-worker:edge -f build/erpnext-worker/Dockerfile . diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6e1bc6da..2faf73be 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,3 +36,33 @@ Place relevant markdown file(s) in the `docs` directory and index them in README # Wiki Add alternatives that can be used optionally along with frappe_docker. Add articles to list on home page as well. + +# Prerequisites to pass CI + +### Check shell script format + +Use the following script + +```shell +./tests/check-format.sh +``` + +### Build images locally + +Use the following commands + +```shell +docker build -t frappe/frappe-socketio:edge -f build/frappe-socketio/Dockerfile . +docker build -t frappe/frappe-worker:develop -f build/frappe-worker/Dockerfile . +docker build -t frappe/erpnext-worker:edge -f build/erpnext-worker/Dockerfile . +docker build -t frappe/frappe-nginx:develop -f build/frappe-nginx/Dockerfile . +docker build -t frappe/erpnext-nginx:edge -f build/erpnext-nginx/Dockerfile . +``` + +### Test running docker containers + +Use the following script + +```shell +./tests/docker-test.sh +``` diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index bbee3b2e..9047ab40 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -44,8 +44,7 @@ function configureEnv() { } function checkConnection() { - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/check_connection.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/check_connection.py } function checkConfigExists() { @@ -88,12 +87,10 @@ case "$1" in LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" if [[ -n "${AUTO_MIGRATE}" ]]; then - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/auto_migrate.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/auto_migrate.py fi - . /home/frappe/frappe-bench/env/bin/activate - gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ + /home/frappe/frappe-bench/env/bin/gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ --worker-tmp-dir /dev/shm \ --threads=4 \ --workers ${WORKERS} \ @@ -107,16 +104,14 @@ case "$1" in checkConnection # default WORKER_TYPE=default - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/worker.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/worker.py ;; schedule) checkConfigExists checkConnection - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/background.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/background.py ;; @@ -124,8 +119,7 @@ case "$1" in checkConfigExists checkConnection - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/new.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/new.py exit ;; @@ -133,27 +127,23 @@ case "$1" in checkConfigExists checkConnection - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/drop.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/drop.py exit ;; migrate) - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/migrate.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/migrate.py exit ;; doctor) - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/doctor.py "${@:2}" + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/doctor.py "${@:2}" exit ;; backup) - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/backup.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/backup.py exit ;; @@ -164,20 +154,17 @@ case "$1" in exit 1 fi - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/console.py "$2" + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/console.py "$2" exit ;; push-backup) - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/push_backup.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/push_backup.py exit ;; restore-backup) - . /home/frappe/frappe-bench/env/bin/activate - python /home/frappe/frappe-bench/commands/restore_backup.py + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/restore_backup.py exit ;; *) diff --git a/build/common/worker/install_app.sh b/build/common/worker/install_app.sh index ae463711..d7de0842 100755 --- a/build/common/worker/install_app.sh +++ b/build/common/worker/install_app.sh @@ -4,13 +4,7 @@ APP_NAME=${1} APP_REPO=${2} APP_BRANCH=${3} -cd /home/frappe/frappe-bench/ - -. env/bin/activate - -cd ./apps - [[ -n "${APP_BRANCH}" ]] && BRANCH="-b ${APP_BRANCH}" -git clone --depth 1 -o upstream ${APP_REPO} ${BRANCH} ${APP_NAME} -pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/${APP_NAME} +git clone --depth 1 -o upstream ${APP_REPO} ${BRANCH} /home/frappe/frappe-bench/apps/${APP_NAME} +/home/frappe/frappe-bench/env/bin/pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/${APP_NAME} diff --git a/tests/check-format.sh b/tests/check-format.sh new file mode 100755 index 00000000..4a1d70aa --- /dev/null +++ b/tests/check-format.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Checking bash scripts with shellcheck" >&2 + +shellcheck --check-sourced --severity=style --color=always --exclude=SC2164,SC2086,SC2012,SC2016 \ + build/common/worker/docker-entrypoint.sh \ + build/common/worker/healthcheck.sh \ + build/common/worker/install_app.sh \ + build/erpnext-nginx/install_app.sh \ + build/frappe-nginx/docker-entrypoint.sh \ + build/frappe-socketio/docker-entrypoint.sh From 577f93a3b71a5a55f2ae2be6524833dc0dd57fc9 Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Thu, 24 Jun 2021 17:37:15 +0530 Subject: [PATCH 6/7] fix: export DB_PORT environment variable --- build/common/worker/docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/common/worker/docker-entrypoint.sh b/build/common/worker/docker-entrypoint.sh index 9047ab40..56ec3a9e 100755 --- a/build/common/worker/docker-entrypoint.sh +++ b/build/common/worker/docker-entrypoint.sh @@ -29,7 +29,7 @@ function configureEnv() { fi if [[ -z "${DB_PORT}" ]]; then - DB_PORT=3306 + export DB_PORT=3306 fi export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" From f0399fa389469c2b22705f2c37237740722256b6 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 24 Jun 2021 17:43:25 +0530 Subject: [PATCH 7/7] ci: fix check format script [skip travis] --- tests/check-format.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/check-format.sh b/tests/check-format.sh index 4a1d70aa..144984b3 100755 --- a/tests/check-format.sh +++ b/tests/check-format.sh @@ -2,10 +2,6 @@ echo "Checking bash scripts with shellcheck" >&2 -shellcheck --check-sourced --severity=style --color=always --exclude=SC2164,SC2086,SC2012,SC2016 \ - build/common/worker/docker-entrypoint.sh \ - build/common/worker/healthcheck.sh \ - build/common/worker/install_app.sh \ - build/erpnext-nginx/install_app.sh \ - build/frappe-nginx/docker-entrypoint.sh \ - build/frappe-socketio/docker-entrypoint.sh +while IFS= read -r shellfile; do + shellcheck --check-sourced --severity=style --color=always --exclude=SC2164,SC2086,SC2012,SC2016 ${shellfile} +done < <(find ./build -name "*.sh")