2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-11-08 14:21:05 +00:00

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
This commit is contained in:
pratikbalar 2021-06-23 09:13:24 +05:30
parent e6a5209001
commit 12eb5c92e4
7 changed files with 566 additions and 596 deletions

View File

@ -3,38 +3,36 @@
function configureEnv() { 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 "${MARIADB_HOST}" && -z "${POSTGRES_HOST}" ]]; then
if [[ -z "${POSTGRES_HOST}" ]]; then echo "MARIADB_HOST or POSTGRES_HOST is not set" >&2
echo "MARIADB_HOST or POSTGRES_HOST is not set" exit 1
exit 1
fi
fi fi
if [[ -z "${REDIS_CACHE}" ]]; then if [[ -z "${REDIS_CACHE}" ]]; then
echo "REDIS_CACHE is not set" echo "REDIS_CACHE is not set" >&2
exit 1 exit 1
fi fi
if [[ -z "${REDIS_QUEUE}" ]]; then if [[ -z "${REDIS_QUEUE}" ]]; then
echo "REDIS_QUEUE is not set" echo "REDIS_QUEUE is not set" >&2
exit 1 exit 1
fi fi
if [[ -z "${REDIS_SOCKETIO}" ]]; then if [[ -z "${REDIS_SOCKETIO}" ]]; then
echo "REDIS_SOCKETIO is not set" echo "REDIS_SOCKETIO is not set" >&2
exit 1 exit 1
fi fi
if [[ -z "${SOCKETIO_PORT}" ]]; then if [[ -z "${SOCKETIO_PORT}" ]]; then
echo "SOCKETIO_PORT is not set" echo "SOCKETIO_PORT is not set" >&2
exit 1 exit 1
fi fi
if [[ -z "${DB_PORT}" ]]; then if [[ -z "${DB_PORT}" ]]; then
export DB_PORT=3306 DB_PORT=3306
fi fi
export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}"
envsubst '${DB_HOST} envsubst '${DB_HOST}
${DB_PORT} ${DB_PORT}
@ -46,141 +44,143 @@ function configureEnv() {
} }
function checkConnection() { 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 python /home/frappe/frappe-bench/commands/check_connection.py
} }
function checkConfigExists() { function checkConfigExists() {
COUNTER=0 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 sleep 1
((COUNTER = COUNTER + 1)) ((COUNTER = COUNTER + 1))
echo "config file not created, retry ${COUNTER}" echo "config file not created, retry ${COUNTER}" >&2
done done
if [[ ! -e /home/frappe/frappe-bench/sites/common_site_config.json ]]; then 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 exit 1
fi fi
} }
if [[ ! -e /home/frappe/frappe-bench/sites/apps.txt ]]; then 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 fi
# symlink node_modules # symlink node_modules
ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \ ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \
/home/frappe/frappe-bench/apps/frappe/node_modules /home/frappe/frappe-bench/apps/frappe/node_modules
if [[ "$1" == 'start' ]]; then case "$1" in
configureEnv
checkConnection
if [[ -z "${WORKERS}" ]]; then start)
export WORKERS=2 configureEnv
fi checkConnection
if [[ -z "${FRAPPE_PORT}" ]]; then [[ -z "${WORKERS}" ]] && WORKERS='2'
export FRAPPE_PORT=8000
fi
if [[ -z "${WORKER_CLASS}" ]]; then [[ -z "${FRAPPE_PORT}" ]] && FRAPPE_PORT='8000'
export WORKER_CLASS=gthread
fi
export LOAD_CONFIG_FILE="" [[ -z "${WORKER_CLASS}" ]] && WORKER_CLASS='gthread'
if [ "${WORKER_CLASS}" = "gevent" ]; then
export LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py"
fi
if [[ ! -z "${AUTO_MIGRATE}" ]]; then LOAD_CONFIG_FILE=""
. /home/frappe/frappe-bench/env/bin/activate [[ "${WORKER_CLASS}" == "gevent" ]] &&
python /home/frappe/frappe-bench/commands/auto_migrate.py LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py"
fi
. /home/frappe/frappe-bench/env/bin/activate if [[ -n "${AUTO_MIGRATE}" ]]; then
gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \ /home/frappe/frappe-bench/env/bin/activate
--worker-tmp-dir /dev/shm \ python /home/frappe/frappe-bench/commands/auto_migrate.py
--threads=4 \ fi
--workers ${WORKERS} \
--worker-class=${WORKER_CLASS} \
--log-file=- \
-t 120 frappe.app:application --preload
elif [[ "$1" == 'worker' ]]; then /home/frappe/frappe-bench/env/bin/activate
checkConfigExists gunicorn ${LOAD_CONFIG_FILE} -b 0.0.0.0:${FRAPPE_PORT} \
checkConnection --worker-tmp-dir /dev/shm \
# default WORKER_TYPE=default --threads=4 \
--workers ${WORKERS} \
--worker-class=${WORKER_CLASS} \
--log-file=- \
-t 120 frappe.app:application --preload
;;
. /home/frappe/frappe-bench/env/bin/activate worker)
python /home/frappe/frappe-bench/commands/worker.py checkConfigExists
checkConnection
# default WORKER_TYPE=default
elif [[ "$1" == 'schedule' ]]; then /home/frappe/frappe-bench/env/bin/activate
checkConfigExists python /home/frappe/frappe-bench/commands/worker.py
checkConnection ;;
. /home/frappe/frappe-bench/env/bin/activate schedule)
python /home/frappe/frappe-bench/commands/background.py checkConfigExists
checkConnection
elif [[ "$1" == 'new' ]]; then /home/frappe/frappe-bench/env/bin/activate
checkConfigExists python /home/frappe/frappe-bench/commands/background.py
checkConnection
. /home/frappe/frappe-bench/env/bin/activate ;;
python /home/frappe/frappe-bench/commands/new.py
exit
elif [[ "$1" == 'drop' ]]; then new)
checkConfigExists checkConfigExists
checkConnection checkConnection
. /home/frappe/frappe-bench/env/bin/activate /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/drop.py python /home/frappe/frappe-bench/commands/new.py
exit exit
;;
elif [[ "$1" = 'migrate' ]]; then drop)
checkConfigExists
checkConnection
. /home/frappe/frappe-bench/env/bin/activate /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/migrate.py python /home/frappe/frappe-bench/commands/drop.py
exit 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 doctor)
python /home/frappe/frappe-bench/commands/doctor.py ${@:2} /home/frappe/frappe-bench/env/bin/activate
exit python /home/frappe/frappe-bench/commands/doctor.py "${@:2}"
exit
;;
elif [[ "$1" == 'backup' ]]; then backup)
. /home/frappe/frappe-bench/env/bin/activate /home/frappe/frappe-bench/env/bin/activate
python /home/frappe/frappe-bench/commands/backup.py python /home/frappe/frappe-bench/commands/backup.py
exit exit
;;
elif [[ "$1" == 'console' ]]; then console)
if [[ -z "$2" ]]; then
echo "Need to specify a sitename with the command:" >&2
echo "console <sitename>" >&2
exit 1
fi
if [[ -z "$2" ]]; then /home/frappe/frappe-bench/env/bin/activate
echo "Need to specify a sitename with the command:" python /home/frappe/frappe-bench/commands/console.py "$2"
echo "console <sitename>" exit
exit 1 ;;
fi
. /home/frappe/frappe-bench/env/bin/activate push-backup)
python /home/frappe/frappe-bench/commands/console.py "$2" /home/frappe/frappe-bench/env/bin/activate
exit python /home/frappe/frappe-bench/commands/push_backup.py
exit
;;
elif [[ "$1" = 'push-backup' ]]; then 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
python /home/frappe/frappe-bench/commands/push_backup.py exit
exit ;;
*)
elif [[ "$1" = 'restore-backup' ]]; then exec "$@"
;;
. /home/frappe/frappe-bench/env/bin/activate esac
python /home/frappe/frappe-bench/commands/restore_backup.py
exit
else
exec $@
fi

View File

@ -2,42 +2,42 @@
set -ea set -ea
function getUrl() { 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' COMMON_SITE_CONFIG_JSON='/home/frappe/frappe-bench/sites/common_site_config.json'
# Set DB Host and port # Set DB Host and port
DB_HOST=$(getUrl "$COMMON_SITE_CONFIG_JSON" "db_host") DB_HOST=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "db_host")
DB_PORT=$(getUrl "$COMMON_SITE_CONFIG_JSON" "db_port") DB_PORT=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "db_port")
if [[ -z "$DB_PORT" ]]; then if [[ -z "${DB_PORT}" ]]; then
DB_PORT=3306 DB_PORT=3306
fi fi
# Set REDIS host:port # Set REDIS host:port
REDIS_CACHE=$(getUrl "$COMMON_SITE_CONFIG_JSON" "redis_cache" | sed 's|redis://||g') REDIS_CACHE=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "redis_cache" | sed 's|redis://||g')
if [[ "$REDIS_CACHE" == *"/"* ]]; then if [[ "${REDIS_CACHE}" == *"/"* ]]; then
REDIS_CACHE=$(echo $REDIS_CACHE | cut -f1 -d"/") REDIS_CACHE=$(echo ${REDIS_CACHE} | cut -f1 -d"/")
fi fi
REDIS_QUEUE=$(getUrl "$COMMON_SITE_CONFIG_JSON" "redis_queue" | sed 's|redis://||g') REDIS_QUEUE=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "redis_queue" | sed 's|redis://||g')
if [[ "$REDIS_QUEUE" == *"/"* ]]; then if [[ "${REDIS_QUEUE}" == *"/"* ]]; then
REDIS_QUEUE=$(echo $REDIS_QUEUE | cut -f1 -d"/") REDIS_QUEUE=$(echo ${REDIS_QUEUE} | cut -f1 -d"/")
fi fi
REDIS_SOCKETIO=$(getUrl "$COMMON_SITE_CONFIG_JSON" "redis_socketio" | sed 's|redis://||g') REDIS_SOCKETIO=$(getUrl "${COMMON_SITE_CONFIG_JSON}" "redis_socketio" | sed 's|redis://||g')
if [[ "$REDIS_SOCKETIO" == *"/"* ]]; then if [[ "${REDIS_SOCKETIO}" == *"/"* ]]; then
REDIS_SOCKETIO=$(echo $REDIS_SOCKETIO | cut -f1 -d"/") REDIS_SOCKETIO=$(echo ${REDIS_SOCKETIO} | cut -f1 -d"/")
fi fi
echo "Check $DB_HOST:$DB_PORT" echo "Check ${DB_HOST}:${DB_PORT}"
wait-for-it "$DB_HOST:$DB_PORT" -t 1 wait-for-it "${DB_HOST}:${DB_PORT}" -t 1
echo "Check $REDIS_CACHE" echo "Check ${REDIS_CACHE}"
wait-for-it "$REDIS_CACHE" -t 1 wait-for-it "${REDIS_CACHE}" -t 1
echo "Check $REDIS_QUEUE" echo "Check ${REDIS_QUEUE}"
wait-for-it "$REDIS_QUEUE" -t 1 wait-for-it "${REDIS_QUEUE}" -t 1
echo "Check $REDIS_SOCKETIO" echo "Check ${REDIS_SOCKETIO}"
wait-for-it "$REDIS_SOCKETIO" -t 1 wait-for-it "${REDIS_SOCKETIO}" -t 1
if [[ "$1" = "-p" || "$1" = "--ping-service" ]]; then if [[ "$1" = "-p" || "$1" = "--ping-service" ]]; then
echo "Check $2" echo "Check $2"

View File

@ -6,11 +6,11 @@ APP_BRANCH=${3}
cd /home/frappe/frappe-bench/ cd /home/frappe/frappe-bench/
. env/bin/activate env/bin/activate
cd ./apps 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} git clone --depth 1 -o upstream ${APP_REPO} ${BRANCH} ${APP_NAME}
pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/${APP_NAME} pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/${APP_NAME}

View File

@ -9,7 +9,7 @@ FRAPPE_BRANCH=${4}
mkdir -p /home/frappe/frappe-bench/sites/assets mkdir -p /home/frappe/frappe-bench/sites/assets
cd /home/frappe/frappe-bench 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 mkdir -p apps
cd 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} 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 # 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/frappe /assets" >/rsync
echo "rsync -a --delete /var/www/html/assets/${APP_NAME} /assets" >> /rsync echo "rsync -a --delete /var/www/html/assets/${APP_NAME} /assets" >>/rsync
chmod +x /rsync chmod +x /rsync
rm /home/frappe/frappe-bench/sites/apps.txt rm /home/frappe/frappe-bench/sites/apps.txt

View File

@ -1,63 +1,38 @@
#!/bin/bash #!/bin/bash -ae
## Thanks ## Thanks
# https://serverfault.com/a/919212 # https://serverfault.com/a/919212
## ##
set -e
rsync -a --delete /var/www/html/assets/* /assets 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 [[ -z "${FRAPPE_PY}" ]] && FRAPPE_PY='0.0.0.0'
export FRAPPE_PY=0.0.0.0
fi
if [[ -z "$FRAPPE_PY_PORT" ]]; then [[ -z "${FRAPPE_PY_PORT}" ]] && FRAPPE_PY_PORT='8000'
export FRAPPE_PY_PORT=8000
fi
if [[ -z "$FRAPPE_SOCKETIO" ]]; then [[ -z "${FRAPPE_SOCKETIO}" ]] && FRAPPE_SOCKETIO='0.0.0.0'
export FRAPPE_SOCKETIO=0.0.0.0
fi
if [[ -z "$SOCKETIO_PORT" ]]; then [[ -z "${SOCKETIO_PORT}" ]] && SOCKETIO_PORT='9000'
export SOCKETIO_PORT=9000
fi
if [[ -z "$HTTP_TIMEOUT" ]]; then [[ -z "${HTTP_TIMEOUT}" ]] && HTTP_TIMEOUT='120'
export HTTP_TIMEOUT=120
fi
if [[ -z "$UPSTREAM_REAL_IP_ADDRESS" ]]; then [[ -z "${UPSTREAM_REAL_IP_ADDRESS}" ]] && UPSTREAM_REAL_IP_ADDRESS='127.0.0.1'
export UPSTREAM_REAL_IP_ADDRESS=127.0.0.1
fi
if [[ -z "$UPSTREAM_REAL_IP_RECURSIVE" ]]; then [[ -z "${UPSTREAM_REAL_IP_RECURSIVE}" ]] && UPSTREAM_REAL_IP_RECURSIVE='off'
export UPSTREAM_REAL_IP_RECURSIVE=off
fi
if [[ -z "$UPSTREAM_REAL_IP_HEADER" ]]; then [[ -z "${UPSTREAM_REAL_IP_HEADER}" ]] && UPSTREAM_REAL_IP_HEADER='X-Forwarded-For'
export UPSTREAM_REAL_IP_HEADER="X-Forwarded-For"
fi
if [[ -z "$FRAPPE_SITE_NAME_HEADER" ]]; then [[ -z "${FRAPPE_SITE_NAME_HEADER}" ]] && FRAPPE_SITE_NAME_HEADER="\$host"
export FRAPPE_SITE_NAME_HEADER="\$host"
fi
if [[ -z "$HTTP_HOST" ]]; then [[ -z "${HTTP_HOST}" ]] && HTTP_HOST="\$http_host"
export HTTP_HOST="\$http_host"
fi
if [[ -z "$SKIP_NGINX_TEMPLATE_GENERATION" ]]; then [[ -z "${SKIP_NGINX_TEMPLATE_GENERATION}" ]] && SKIP_NGINX_TEMPLATE_GENERATION='0'
export SKIP_NGINX_TEMPLATE_GENERATION=0
fi
if [[ $SKIP_NGINX_TEMPLATE_GENERATION -eq 1 ]] if [[ ${SKIP_NGINX_TEMPLATE_GENERATION} == 1 ]]; then
then
echo "Skipping default NGINX template generation. Please mount your own NGINX config file inside /etc/nginx/conf.d" echo "Skipping default NGINX template generation. Please mount your own NGINX config file inside /etc/nginx/conf.d"
else else
echo "Generating default template" echo "Generating default template"
@ -71,14 +46,14 @@ else
${FRAPPE_SITE_NAME_HEADER} ${FRAPPE_SITE_NAME_HEADER}
${HTTP_HOST} ${HTTP_HOST}
${UPSTREAM_REAL_IP_HEADER}' \ ${UPSTREAM_REAL_IP_HEADER}' \
< /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf </etc/nginx/conf.d/default.conf.template >/etc/nginx/conf.d/default.conf
fi fi
echo "Waiting for frappe-python to be available on $FRAPPE_PY port $FRAPPE_PY_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 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 "Frappe-python available on ${FRAPPE_PY} port ${FRAPPE_PY_PORT}"
echo "Waiting for frappe-socketio to be available on $FRAPPE_SOCKETIO port $SOCKETIO_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 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 "Frappe-socketio available on ${FRAPPE_SOCKETIO} port ${SOCKETIO_PORT}"
exec "$@" exec "$@"

View File

@ -3,8 +3,7 @@
set -euo pipefail set -euo pipefail
IFS=$'\n\t' IFS=$'\n\t'
[ -z "$DEBUG" ] & [ "${DEBUG}" == 1 ] && set -o xtrace [[ -z "${DEBUG}" && "${DEBUG}" == 1 ]] && set -o xtrace
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$__dir" 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" frappe_docker_url="https://github.com/frappe/frappe_docker"
env_file="$__dir/.env" env_file="$__dir/.env"
function check_root() {
check_root() { if [[ $EUID != 0 ]]; then
if [[ $EUID -ne 0 ]]; then echo "This script must be run as root. Login as root or use sudo." >&2
echo "This script must be run as root. Login as root or use sudo." 1>&2 exit 1
exit 1 fi
fi
} }
check_git() { function check_git() {
if [ ! -x "$(command -v git)" ]; then if [[ ! -x "$(command -v git)" ]]; then
echo "Git is not installed. Please install git before continuing." echo "Git is not installed. Please install git before continuing." >&2
exit 1 exit 1
fi fi
} }
check_docker() { function check_docker() {
if [ ! -x "$(command -v docker)" ]; then if [[ ! -x "$(command -v docker)" ]]; then
read -rp "No docker installation found. Press Enter to install docker or ctrl+c to exit." read -rp "No docker installation found. Press Enter to install docker or ctrl+c to exit." >&2
curl -fsSL https://get.docker.com | sh curl -fsSL https://get.docker.com | sh
fi fi
if [ ! -x "$(command -v docker)" ]; then if [[ ! -x "$(command -v docker)" ]]; then
echo "Docker installation failed. Exiting." echo "Docker installation failed. Exiting." >&2
exit 1 exit 1
fi fi
} }
check_env() { function check_env() {
if [ ! -f "$env_file" ]; then if [[ ! -f "$env_file" ]]; then
echo "No environment file found. This file is required for setting up Frappe/ERPNext Docker." cat <<CHOOSE >&2
echo "Would you like to fetch the default environment file?" No environment file found. This file is required for setting up Frappe/ERPNext Docker.
echo "(NOTE: You will be prompted to set it up later)" Would you like to fetch the default environment file?
read -rp "Press Enter to fetch the configuration file, or create a .env file and re-run the script." (NOTE: You will be prompted to set it up later)
curl -fsSL "$env_url" -o "$env_file" CHOOSE
fi 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() { function clone_repository() {
echo "Cloning Repository: $1" echo "Cloning Repository: $1"
git clone "$2" git clone "$2"
} }
get_config() { function get_config() {
if [ -n "$2" ]; then if [[ -n "$2" ]]; then
config_file="$2" config_file="$2"
else else
config_file="$env_file" config_file="$env_file"
fi fi
line=$(grep -E "^$=" "$config_file") line=$(grep -E "^$=" "$config_file")
line_result=$(echo "$line" | awk -F"=" '{print $2}') line_result=$(echo "$line" | awk -F"=" '{print $2}')
} }
get_install_version() { function get_install_version() {
echo "Choose a version you would like to setup [current: $1]:" cat <<CHOOSE >&2
echo "1. develop (edge)" Choose a version you would like to setup [current: $1]:
echo "2. version-12" 1. develop (edge)
echo "3. version-11" 2. version-12
echo "Please enter your choice [1-3]: " 3. version-11
select choice in "1" "2" "3"; do Please enter your choice [1-3]:
case $choice in CHOOSE
1 ) version="edge" ;; select choice in "1" "2" "3"; do
2 ) version="version-12" ;; case ${choice} in
3 ) version="version-11" ;; 1) version="edge" ;;
esac 2) version="version-12" ;;
done 3) version="version-11" ;;
esac
done
} }
prompt_config() { function prompt_config() {
# inspired by discourse_docker # inspired by discourse_docker
get_config "VERSION" get_config "VERSION"
local install_version=$line_result local install_version=$line_result
get_config "MYSQL_ROOT_PASSWORD" get_config "MYSQL_ROOT_PASSWORD"
local mysql_password=$line_result local mysql_password=$line_result
get_config "SITES" get_config "SITES"
local sites=$line_result local sites=$line_result
get_config "LETSENCRYPT_EMAIL" get_config "LETSENCRYPT_EMAIL"
local letsencrypt_email=$line_result local letsencrypt_email=$line_result
echo "Would you like to setup networking for docker? [y/n]" 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 "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 select choice in "y" "n"; do
case $choice in case $choice in
y ) setup_networking=1 ;; y)
n ) setup_networking=0 setup_letsencrypt=1
setup_letsencrypt=0 ;; echo "Please ensure that all the required domains point to this IP address."
esac read -rp "Enter an Email Address to setup LetsEncrypt with: " letsencrypt_email
;;
n)
setup_letsencrypt=0
echo "Skipping LetsEncrypt Setup."
;;
esac
done done
if [ -n "$letsencrypt_email" ] & [ "$setup_networking" -ne "0" ]; then fi
echo "Would you like to setup LetsEncrypt? [y/n]"
select choice in "y" "n"; do local new_value=""
case $choice in local config_state="n"
y ) setup_letsencrypt=1
echo "Please ensure that all the required domains point to this IP address." echo
read -rp "Enter an Email Address to setup LetsEncrypt with: " letsencrypt_email ;;
n ) setup_letsencrypt=0 get_install_version "$install_version"
echo "Skipping LetsEncrypt Setup." ;; install_version="$version"
esac
done 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 fi
local new_value="" if [[ -n "$sites" ]]; then
local config_state="n" 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
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" echo "Saving the current configuration file to $env_file"
install_version="$version"
while [ "$config_state" = "n" ]; do cat <<EOF >"$env_file"
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"
VERSION=$install_version VERSION=$install_version
MYSQL_ROOT_PASSWORD=$mysql_password MYSQL_ROOT_PASSWORD=$mysql_password
SITES=$sites SITES=$sites
$([ "$setup_letsencrypt" -ne "0" ] && echo "LETSENCRYPT_EMAIL=$letsencrypt_email") $([ "$setup_letsencrypt" -ne "0" ] && echo "LETSENCRYPT_EMAIL=$letsencrypt_email")
EOF EOF
setup_configuration=$(<"$env_file") setup_configuration=$(<"$env_file")
} }
setup_user() { setup_user() {
echo "The rest of the setup requires a user account." 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." echo "You may use an existing account, or set up a new one right away."
read -rp "Enter username: " username read -rp "Enter username: " username
if grep -E "^$username" /etc/passwd > /dev/null; then if grep -E "^$username" /etc/passwd >/dev/null; then
echo "User $username already exists." 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 else
read -rsp "Enter password: " password echo "Failed to add user to the system."
password="$(perl -e 'print crypt($ARGV[0], "password")' "$password")" echo "Please add a user manually and re-run the script."
if useradd -m -p "$password" "$username" -s "$(command -v bash)"; then exit 1
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
fi fi
fi
if ! getent group docker > /dev/null 2>&1 ; then if ! getent group docker >/dev/null 2>&1; then
echo "Creating group: docker" echo "Creating group: docker"
groupadd docker groupadd docker
fi fi
echo "Adding user $username to group: docker" echo "Adding user $username to group: docker"
usermod -aG docker "$username" usermod -aG docker "$username"
newgrp docker newgrp docker
} }
install() { install() {
if [ "$setup_letsencrypt" -ne "0" ] & [ "$setup_networking" -ne "0" ]; then if [[ "$setup_letsencrypt" != "0" && "$setup_networking" != "0" ]]; then
echo "Setting up NGINX Proxy for LetsEncrypt" echo "Setting up NGINX Proxy for LetsEncrypt"
clone_repository "Docker Compose LetsEncrypt NGINX Proxy Companion" "$docker_nginx_url" clone_repository "Docker Compose LetsEncrypt NGINX Proxy Companion" "$docker_nginx_url"
cd "$(basename "$docker_nginx_url")" cd "$(basename "$docker_nginx_url")"
if [ -f .env.sample ]; then if [[ -f .env.sample ]]; then
cp .env.sample env cp .env.sample env
fi
./start.sh > /dev/null 2>&1
cd "$(eval echo ~"$username")"
fi fi
./start.sh >/dev/null 2>&1
cd "$(eval echo ~"$username")"
fi
echo "Setting up Frappe/ERPNext" echo "Setting up Frappe/ERPNext"
clone_repository "Frappe/ERPNext Docker" "$frappe_docker_url" clone_repository "Frappe/ERPNext Docker" "$frappe_docker_url"
cd "$(basename "$frappe_docker_url")" cd "$(basename "$frappe_docker_url")"
echo "$setup_configuration" > .env echo "$setup_configuration" >.env
echo "Enter a name for the project." echo "Enter a name for the project."
read -rp "This project name will be used to setup the docker instance: [erpnext_docker]" project_name read -rp "This project name will be used to setup the docker instance: [erpnext_docker]" project_name
if [ -z "$project_name" ]; then if [[ -z "$project_name" ]]; then
echo "Setting the project name to erpnext_docker" echo "Setting the project name to erpnext_docker"
project_name="erpnext_docker" project_name="erpnext_docker"
fi fi
docker-compose \ docker-compose \
--project-name "$project_name" \ --project-name "$project_name" \
--project-directory . up -d \ --project-directory . up -d \
-f installation/docker-compose-frappe.yml \ -f installation/docker-compose-frappe.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
"$( (( setup_networking == 1 )) && printf %s '-f installation/docker-compose-networks.yml' )" "$( ((setup_networking == 1)) && printf %s '-f installation/docker-compose-networks.yml')"
get_config "SITES" "$(pwd)/.env" get_config "SITES" "$(pwd)/.env"
local sites=$line_result local sites=$line_result
docker exec \ docker exec \
-e "SITE_NAME=$sites" \ -e "SITE_NAME=$sites" \
-e "INSTALL_ERPNEXT=1" \ -e "INSTALL_ERPNEXT=1" \
-it "$project_name"_erpnext-python_1 docker-entrypoint.sh new -it "$project_name"_erpnext-python_1 docker-entrypoint.sh new
echo "Installation Complete!" echo "Installation Complete!"
} }
check_root check_root
@ -244,4 +252,4 @@ check_env
prompt_config prompt_config
setup_user setup_user
install install

View File

@ -4,47 +4,47 @@ ENDULINE='\e[0m'
NEWLINE='\n' NEWLINE='\n'
function checkMigrationComplete() { function checkMigrationComplete() {
echo "Check Migration" echo "Check Migration"
CONTAINER_ID=$(docker-compose \ CONTAINER_ID=$(docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
ps -q erpnext-python) 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") DOCKER_LOG=$(docker logs ${CONTAINER_ID} 2>&1 | grep "Starting gunicorn")
INCREMENT=0 if [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -eq 60 ]]; then
while [[ ${DOCKER_LOG} != *"Starting gunicorn"* && ${INCREMENT} -lt 60 ]]; do docker logs ${CONTAINER_ID}
sleep 3 exit 1
echo "Wait for migration to complete ..." fi
((INCREMENT = INCREMENT + 1)) done
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 "${ULINE}Migration Log${ENDULINE}" echo -e "${ULINE}Migration Log${ENDULINE}"
docker logs ${CONTAINER_ID} docker logs ${CONTAINER_ID}
} }
function loopHealthCheck() { function loopHealthCheck() {
echo "Create Container to Check MariaDB" echo "Create Container to Check MariaDB"
docker run --name frappe_doctor \ docker run --name frappe_doctor \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge doctor || true 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 "") FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "")
while [[ -z "${FRAPPE_LOG}" ]]; do done
sleep 1 echo "Health check successful"
CONTAINER=$(docker start frappe_doctor)
echo "Restarting ${CONTAINER} ..."
FRAPPE_LOG=$(docker logs frappe_doctor | grep "Health check successful" || echo "")
done
echo "Health check successful"
} }
echo -e "${ULINE}Copy env-example file${ENDULINE}" 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}" echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}"
docker-compose \ docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
pull pull
docker pull postgres:11.8 docker pull postgres:11.8
docker-compose \ docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
up -d up -d
# Start postgres # Start postgres
docker run --name postgresql -d \ docker run --name postgresql -d \
-e "POSTGRES_PASSWORD=admin" \ -e "POSTGRES_PASSWORD=admin" \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
postgres:11.8 postgres:11.8
loopHealthCheck loopHealthCheck
echo -e "${NEWLINE}${ULINE}Create new site (v13)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Create new site (v13)${ENDULINE}"
docker run -it \ docker run -it \
-e "SITE_NAME=test.localhost" \ -e "SITE_NAME=test.localhost" \
-e "INSTALL_APPS=erpnext" \ -e "INSTALL_APPS=erpnext" \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:v13 new frappe/erpnext-worker:v13 new
echo -e "${NEWLINE}${ULINE}Ping created site${ENDULINE}" echo -e "${NEWLINE}${ULINE}Ping created site${ENDULINE}"
curl -sS http://test.localhost/api/method/version 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}" echo -e "${NEWLINE}${ULINE}Restart containers with edge image${ENDULINE}"
docker-compose \ docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
stop stop
docker-compose \ docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
up -d up -d
checkMigrationComplete checkMigrationComplete
@ -113,157 +113,144 @@ echo -e "${NEWLINE}${ULINE}Ping migrated site${ENDULINE}"
sleep 3 sleep 3
curl -sS http://test.localhost/api/method/version curl -sS http://test.localhost/api/method/version
echo -e "${NEWLINE}${ULINE}Check Migrated Site Index Page${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check Migrated Site Index Page${ENDULINE}"
curl -s http://test.localhost | w3m -T text/html -dump curl -s http://test.localhost | w3m -T text/html -dump
echo -e "${NEWLINE}${ULINE}Create new site (pgsql)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Create new site (pgsql)${ENDULINE}"
docker run -it \ docker run -it \
-e "SITE_NAME=pgsql.localhost" \ -e "SITE_NAME=pgsql.localhost" \
-e "POSTGRES_HOST=postgresql" \ -e "POSTGRES_HOST=postgresql" \
-e "DB_ROOT_USER=postgres" \ -e "DB_ROOT_USER=postgres" \
-e "POSTGRES_PASSWORD=admin" \ -e "POSTGRES_PASSWORD=admin" \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge new frappe/erpnext-worker:edge new
echo -e "${NEWLINE}${ULINE}Check New PGSQL Site${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check New PGSQL Site${ENDULINE}"
sleep 3 sleep 3
RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "")
INCREMENT=0 INCREMENT=0
while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do
sleep 1 sleep 1
echo -e "${ULINE}Wait for restoration to complete ..." echo -e "${ULINE}Wait for restoration to complete ..."
RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "")
((INCREMENT = INCREMENT + 1)) ((INCREMENT = INCREMENT + 1))
if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then
CONTAINER_ID=$(docker-compose \ CONTAINER_ID=$(docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
ps -q erpnext-python) ps -q erpnext-python)
docker logs ${CONTAINER_ID} docker logs ${CONTAINER_ID}
exit 1 exit 1
fi fi
done done
echo -e "${NEWLINE}${ULINE}Ping new pgsql site${ENDULINE}" echo -e "${NEWLINE}${ULINE}Ping new pgsql site${ENDULINE}"
echo $RESTORE_STATUS echo $RESTORE_STATUS
echo -e "${NEWLINE}${ULINE}Check New PGSQL Index Page${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check New PGSQL Index Page${ENDULINE}"
curl -s http://pgsql.localhost | w3m -T text/html -dump curl -s http://pgsql.localhost | w3m -T text/html -dump
echo -e "${NEWLINE}${ULINE}Backup site${ENDULINE}" echo -e "${NEWLINE}${ULINE}Backup site${ENDULINE}"
docker run -it \ docker run -it \
-e "WITH_FILES=1" \ -e "WITH_FILES=1" \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge backup frappe/erpnext-worker:edge backup
export MINIO_ACCESS_KEY="AKIAIOSFODNN7EXAMPLE" MINIO_ACCESS_KEY="AKIAIOSFODNN7EXAMPLE"
export MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
echo -e "${ULINE}Start MinIO container for s3 compatible storage${ENDULINE}" echo -e "${ULINE}Start MinIO container for s3 compatible storage${ENDULINE}"
docker run -d --name minio \ docker run -d --name minio \
-e "MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}" \ -e "MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}" \
-e "MINIO_SECRET_KEY=${MINIO_SECRET_KEY}" \ -e "MINIO_SECRET_KEY=${MINIO_SECRET_KEY}" \
--network frappebench00_default \ --network frappebench00_default \
minio/minio server /data minio/minio server /data
echo -e "${NEWLINE}${ULINE}Create bucket named erpnext${ENDULINE}" echo -e "${NEWLINE}${ULINE}Create bucket named erpnext${ENDULINE}"
docker run \ docker run \
--network frappebench00_default \ --network frappebench00_default \
vltgroup/s3cmd:latest s3cmd --access_key=${MINIO_ACCESS_KEY} \ vltgroup/s3cmd:latest s3cmd --access_key=${MINIO_ACCESS_KEY} \
--secret_key=${MINIO_SECRET_KEY} \ --secret_key=${MINIO_SECRET_KEY} \
--region=us-east-1 \ --region=us-east-1 \
--no-ssl \ --no-ssl \
--host=minio:9000 \ --host=minio:9000 \
--host-bucket=minio:9000 \ --host-bucket=minio:9000 \
mb s3://erpnext mb s3://erpnext
echo -e "${NEWLINE}${NEWLINE}${ULINE}Push backup to MinIO s3${ENDULINE}" echo -e "${NEWLINE}${NEWLINE}${ULINE}Push backup to MinIO s3${ENDULINE}"
docker run \ docker run \
-e BUCKET_NAME=erpnext \ -e BUCKET_NAME=erpnext \
-e REGION=us-east-1 \ -e REGION=us-east-1 \
-e BUCKET_DIR=local \ -e BUCKET_DIR=local \
-e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \
-e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \
-e ENDPOINT_URL=http://minio:9000 \ -e ENDPOINT_URL=http://minio:9000 \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge push-backup frappe/erpnext-worker:edge push-backup
echo -e "${NEWLINE}${ULINE}Stop Services${ENDULINE}" echo -e "${NEWLINE}${ULINE}Stop Services${ENDULINE}"
docker-compose \ docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
stop stop
echo -e "${NEWLINE}${ULINE}Prune Containers${ENDULINE}" echo -e "${NEWLINE}${ULINE}Prune Containers${ENDULINE}"
docker container prune -f && docker volume prune -f docker container prune -f && docker volume prune -f
echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}" echo -e "${NEWLINE}${ULINE}Start Services${ENDULINE}"
docker-compose \ docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
up -d up -d
loopHealthCheck loopHealthCheck
echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3${ENDULINE}" echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3${ENDULINE}"
docker run \ docker run \
-e MYSQL_ROOT_PASSWORD=admin \ -e MYSQL_ROOT_PASSWORD=admin \
-e BUCKET_NAME=erpnext \ -e BUCKET_NAME=erpnext \
-e BUCKET_DIR=local \ -e BUCKET_DIR=local \
-e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \
-e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \
-e ENDPOINT_URL=http://minio:9000 \ -e ENDPOINT_URL=http://minio:9000 \
-e REGION=us-east-1 \ -e REGION=us-east-1 \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge restore-backup frappe/erpnext-worker:edge restore-backup
echo -e "${NEWLINE}${ULINE}Check Restored Site (test)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check Restored Site (test)${ENDULINE}"
sleep 3 sleep 3
RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "")
INCREMENT=0 INCREMENT=0
while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do
sleep 1 sleep 1
echo "Wait for restoration to complete ..." echo "Wait for restoration to complete ..."
RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "")
((INCREMENT = INCREMENT + 1)) ((INCREMENT = INCREMENT + 1))
if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then
CONTAINER_ID=$(docker-compose \ CONTAINER_ID=$(docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
ps -q erpnext-python) ps -q erpnext-python)
docker logs ${CONTAINER_ID} docker logs ${CONTAINER_ID}
exit 1 exit 1
fi fi
done done
echo -e "${ULINE}Ping restored site (test)${ENDULINE}" echo -e "${ULINE}Ping restored site (test)${ENDULINE}"
echo ${RESTORE_STATUS} echo ${RESTORE_STATUS}
echo -e "${NEWLINE}${ULINE}Check Restored Site Index Page (test)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check Restored Site Index Page (test)${ENDULINE}"
curl -s http://test.localhost | w3m -T text/html -dump 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 "") RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "")
INCREMENT=0 INCREMENT=0
while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do
sleep 1 sleep 1
echo "Wait for restoration to complete ..." echo "Wait for restoration to complete ..."
RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://pgsql.localhost/api/method/version || echo "")
((INCREMENT = INCREMENT + 1)) ((INCREMENT = INCREMENT + 1))
if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then
CONTAINER_ID=$(docker-compose \ CONTAINER_ID=$(docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
ps -q erpnext-python) ps -q erpnext-python)
docker logs ${CONTAINER_ID} docker logs ${CONTAINER_ID}
exit 1 exit 1
fi fi
done done
echo -e "${ULINE}Ping restored site (pgsql)${ENDULINE}" 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}" echo -e "${NEWLINE}${ULINE}Create new site (edge)${ENDULINE}"
docker run -it \ docker run -it \
-e "SITE_NAME=edge.localhost" \ -e "SITE_NAME=edge.localhost" \
-e "INSTALL_APPS=erpnext" \ -e "INSTALL_APPS=erpnext" \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge new frappe/erpnext-worker:edge new
echo -e "${NEWLINE}${ULINE}Check New Edge Site${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check New Edge Site${ENDULINE}"
sleep 3 sleep 3
RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "")
INCREMENT=0 INCREMENT=0
while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do
sleep 1 sleep 1
echo -e "${ULINE}Wait for restoration to complete ...${ENDULINE}" echo -e "${ULINE}Wait for restoration to complete ...${ENDULINE}"
RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://edge.localhost/api/method/version || echo "")
((INCREMENT = INCREMENT + 1)) ((INCREMENT = INCREMENT + 1))
if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then
CONTAINER_ID=$(docker-compose \ CONTAINER_ID=$(docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
ps -q erpnext-python) ps -q erpnext-python)
docker logs ${CONTAINER_ID} docker logs ${CONTAINER_ID}
exit 1 exit 1
fi fi
done done
echo -e "${NEWLINE}${ULINE}Ping new edge site${ENDULINE}" 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}" echo -e "${NEWLINE}${ULINE}Migrate command in edge container${ENDULINE}"
docker run -it \ docker run -it \
-e "MAINTENANCE_MODE=1" \ -e "MAINTENANCE_MODE=1" \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
-v frappebench00_assets-vol:/home/frappe/frappe-bench/sites/assets \ -v frappebench00_assets-vol:/home/frappe/frappe-bench/sites/assets \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge migrate frappe/erpnext-worker:edge migrate
checkMigrationComplete checkMigrationComplete
echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3 (Overwrite)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Restore backup from MinIO / S3 (Overwrite)${ENDULINE}"
docker run \ docker run \
-e MYSQL_ROOT_PASSWORD=admin \ -e MYSQL_ROOT_PASSWORD=admin \
-e BUCKET_NAME=erpnext \ -e BUCKET_NAME=erpnext \
-e BUCKET_DIR=local \ -e BUCKET_DIR=local \
-e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \ -e ACCESS_KEY_ID=${MINIO_ACCESS_KEY} \
-e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \ -e SECRET_ACCESS_KEY=${MINIO_SECRET_KEY} \
-e ENDPOINT_URL=http://minio:9000 \ -e ENDPOINT_URL=http://minio:9000 \
-e REGION=us-east-1 \ -e REGION=us-east-1 \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge restore-backup frappe/erpnext-worker:edge restore-backup
echo -e "${NEWLINE}${ULINE}Check Overwritten Site${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check Overwritten Site${ENDULINE}"
sleep 3 sleep 3
RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "")
INCREMENT=0 INCREMENT=0
while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do while [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -lt 60 ]]; do
sleep 1 sleep 1
echo -e "${ULINE}Wait for restoration to complete ..." echo -e "${ULINE}Wait for restoration to complete ..."
RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "") RESTORE_STATUS=$(curl -sS http://test.localhost/api/method/version || echo "")
((INCREMENT = INCREMENT + 1)) ((INCREMENT = INCREMENT + 1))
if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then if [[ -z "${RESTORE_STATUS}" && ${INCREMENT} -eq 60 ]]; then
CONTAINER_ID=$(docker-compose \ CONTAINER_ID=$(docker-compose \
--project-name frappebench00 \ --project-name frappebench00 \
-f installation/docker-compose-common.yml \ -f installation/docker-compose-common.yml \
-f installation/docker-compose-erpnext.yml \ -f installation/docker-compose-erpnext.yml \
-f installation/erpnext-publish.yml \ -f installation/erpnext-publish.yml \
ps -q erpnext-python) ps -q erpnext-python)
docker logs ${CONTAINER_ID} docker logs ${CONTAINER_ID}
exit 1 exit 1
fi fi
done done
echo -e "${NEWLINE}${ULINE}Ping overwritten site${ENDULINE}" 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}" echo -e "${NEWLINE}${ULINE}Check console command for site test.localhost${ENDULINE}"
docker run \ docker run \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge console test.localhost frappe/erpnext-worker:edge console test.localhost
echo -e "${NEWLINE}${ULINE}Check console command for site pgsql.localhost${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check console command for site pgsql.localhost${ENDULINE}"
docker run \ docker run \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge console pgsql.localhost frappe/erpnext-worker:edge console pgsql.localhost
echo -e "${NEWLINE}${ULINE}Check drop site: test.localhost (mariadb)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check drop site: test.localhost (mariadb)${ENDULINE}"
docker run \ docker run \
-e SITE_NAME=test.localhost \ -e SITE_NAME=test.localhost \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge drop frappe/erpnext-worker:edge drop
echo -e "${NEWLINE}${ULINE}Check drop site: pgsql.localhost (pgsql)${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check drop site: pgsql.localhost (pgsql)${ENDULINE}"
docker run \ docker run \
-e SITE_NAME=pgsql.localhost \ -e SITE_NAME=pgsql.localhost \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
frappe/erpnext-worker:edge drop frappe/erpnext-worker:edge drop
echo -e "${NEWLINE}${ULINE}Check bench --help${ENDULINE}" echo -e "${NEWLINE}${ULINE}Check bench --help${ENDULINE}"
docker run \ docker run \
-v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \ -v frappebench00_sites-vol:/home/frappe/frappe-bench/sites \
--network frappebench00_default \ --network frappebench00_default \
--user frappe \ --user frappe \
frappe/erpnext-worker:edge bench --help frappe/erpnext-worker:edge bench --help