From f74f730b5ea69c1e5c7c81e843031d98d2b1a696 Mon Sep 17 00:00:00 2001 From: Lev Date: Tue, 9 Nov 2021 13:05:29 +0300 Subject: [PATCH] chore: Fix lint issues (#553) * ci(Lint): Temporarily disable branch contraint * chore(erpnext-nginx): Fix linting * chore: Fix linting issues * ci(Lint): Add -x flag * ci(Lint): Fix push trigger * chore: Fix linting and formatting * fix: Gunicorn server start * chore(frappe-worker): Fix linting * chore(frappe-nginx): Fix linting * fix(erpnext-nginx): App installation * fix(erpnext-nginx): App installation * refactor(frappe-nginx): Use `find` instead of `ls` --- .github/scripts/get-latest-tags.sh | 16 +- .github/workflows/lint.yml | 2 + build/erpnext-nginx/install_app.sh | 15 +- build/frappe-nginx/docker-entrypoint.sh | 5 +- build/frappe-worker/docker-entrypoint.sh | 188 ++++++++++++----------- build/frappe-worker/healthcheck.sh | 6 +- build/frappe-worker/install_app.sh | 5 +- tests/integration-test.sh | 1 - tests/test-erpnext.sh | 1 - tests/test-frappe.sh | 1 - 10 files changed, 124 insertions(+), 116 deletions(-) diff --git a/.github/scripts/get-latest-tags.sh b/.github/scripts/get-latest-tags.sh index 0ca74acb..cfcf85e9 100755 --- a/.github/scripts/get-latest-tags.sh +++ b/.github/scripts/get-latest-tags.sh @@ -4,7 +4,7 @@ set -e set -x get_tag() { - tags=$(git ls-remote --refs --tags --sort='v:refname' https://github.com/$1 "v$2.*") + tags=$(git ls-remote --refs --tags --sort='v:refname' "https://github.com/$1" "v$2.*") tag=$(echo "$tags" | tail -n1 | sed 's/.*\///') echo "$tag" } @@ -12,11 +12,9 @@ get_tag() { FRAPPE_VERSION=$(get_tag frappe/frappe "$VERSION") ERPNEXT_VERSION=$(get_tag frappe/erpnext "$VERSION") -# shellcheck disable=SC2086 -echo "FRAPPE_VERSION=$FRAPPE_VERSION" >>$GITHUB_ENV -# shellcheck disable=SC2086 -echo "ERPNEXT_VERSION=$ERPNEXT_VERSION" >>$GITHUB_ENV -# shellcheck disable=SC2086 -echo "GIT_BRANCH=version-$VERSION" >>$GITHUB_ENV -# shellcheck disable=SC2086 -echo "VERSION=$VERSION" >>$GITHUB_ENV +cat <>"$GITHUB_ENV" +FRAPPE_VERSION=$FRAPPE_VERSION +ERPNEXT_VERSION=$ERPNEXT_VERSION +GIT_BRANCH=version-$VERSION +VERSION=$VERSION +EOL diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d7320dff..1dbd9007 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,3 +14,5 @@ jobs: steps: - uses: actions/checkout@v2 - uses: ludeeus/action-shellcheck@master + env: + SHELLCHECK_OPTS: -x diff --git a/build/erpnext-nginx/install_app.sh b/build/erpnext-nginx/install_app.sh index d3e30769..49f40e78 100755 --- a/build/erpnext-nginx/install_app.sh +++ b/build/erpnext-nginx/install_app.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + APP_NAME=${1} APP_REPO=${2} APP_BRANCH=${3} @@ -13,26 +15,29 @@ echo -ne "frappe\n${APP_NAME}" >/home/frappe/frappe-bench/sites/apps.txt mkdir -p apps cd apps -git clone --depth 1 https://github.com/frappe/frappe -b ${FRAPPE_BRANCH} -git clone --depth 1 ${APP_REPO} ${BRANCH} ${APP_NAME} +git clone --depth 1 https://github.com/frappe/frappe -b "${FRAPPE_BRANCH}" +# shellcheck disable=SC2086 +git clone --depth 1 "${APP_REPO}" ${BRANCH} "${APP_NAME}" echo "Install frappe NodeJS dependencies . . ." cd /home/frappe/frappe-bench/apps/frappe yarn echo "Install ${APP_NAME} NodeJS dependencies . . ." -cd /home/frappe/frappe-bench/apps/${APP_NAME} +cd "/home/frappe/frappe-bench/apps/${APP_NAME}" yarn echo "Build browser assets . . ." cd /home/frappe/frappe-bench/apps/frappe -yarn production --app ${APP_NAME} +yarn production --app "${APP_NAME}" echo "Install frappe NodeJS production dependencies . . ." cd /home/frappe/frappe-bench/apps/frappe yarn install --production=true echo "Install ${APP_NAME} NodeJS production dependencies . . ." -cd /home/frappe/frappe-bench/apps/${APP_NAME} +cd "/home/frappe/frappe-bench/apps/${APP_NAME}" yarn install --production=true +# shellcheck disable=SC2086 mkdir -p /home/frappe/frappe-bench/sites/assets/${APP_NAME} +# shellcheck disable=SC2086 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 diff --git a/build/frappe-nginx/docker-entrypoint.sh b/build/frappe-nginx/docker-entrypoint.sh index e1a29277..94277fc3 100755 --- a/build/frappe-nginx/docker-entrypoint.sh +++ b/build/frappe-nginx/docker-entrypoint.sh @@ -8,7 +8,7 @@ rsync -a --delete /var/www/html/assets/* /assets /rsync -touch /var/www/html/sites/.build -r "$(ls -td /assets/* | head -n 1)" +touch /var/www/html/sites/.build -r "$(find /assets -maxdepth 1 -name "*.*" | head -n 1)" [[ -z "${FRAPPE_PY}" ]] && FRAPPE_PY='0.0.0.0' @@ -36,6 +36,7 @@ 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" + # shellcheck disable=SC2016 envsubst '${FRAPPE_PY} ${FRAPPE_PY_PORT} ${FRAPPE_SOCKETIO} @@ -50,9 +51,11 @@ else fi echo "Waiting for frappe-python to be available on ${FRAPPE_PY} port ${FRAPPE_PY_PORT}" +# shellcheck disable=SC2016 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}" +# shellcheck disable=SC2016 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}" diff --git a/build/frappe-worker/docker-entrypoint.sh b/build/frappe-worker/docker-entrypoint.sh index 32d0c3ac..5065d2a9 100755 --- a/build/frappe-worker/docker-entrypoint.sh +++ b/build/frappe-worker/docker-entrypoint.sh @@ -34,6 +34,7 @@ function configureEnv() { export DB_HOST="${MARIADB_HOST:-$POSTGRES_HOST}" + # shellcheck disable=SC2016 envsubst '${DB_HOST} ${DB_PORT} ${REDIS_CACHE} @@ -72,120 +73,121 @@ ln -sfn /home/frappe/frappe-bench/sites/assets/frappe/node_modules \ case "$1" in - start) - configureEnv - checkConnection +start) + configureEnv + checkConnection - [[ -z "${WORKERS}" ]] && WORKERS='2' + [[ -z "${WORKERS}" ]] && WORKERS='2' - [[ -z "${FRAPPE_PORT}" ]] && FRAPPE_PORT='8000' + [[ -z "${FRAPPE_PORT}" ]] && FRAPPE_PORT='8000' - [[ -z "${WORKER_CLASS}" ]] && WORKER_CLASS='gthread' + [[ -z "${WORKER_CLASS}" ]] && WORKER_CLASS='gthread' - LOAD_CONFIG_FILE="" - [[ "${WORKER_CLASS}" == "gevent" ]] && - LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" + LOAD_CONFIG_FILE="" + [[ "${WORKER_CLASS}" == "gevent" ]] && + LOAD_CONFIG_FILE="-c /home/frappe/frappe-bench/commands/gevent_patch.py" - if [[ -n "${AUTO_MIGRATE}" ]]; then - /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/auto_migrate.py - fi + if [[ -n "${AUTO_MIGRATE}" ]]; then + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/auto_migrate.py + fi - /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} \ - --worker-class=${WORKER_CLASS} \ - --log-file=- \ - -t 120 frappe.app:application --preload - ;; + # shellcheck disable=SC2086 + /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} \ + --worker-class=${WORKER_CLASS} \ + --log-file=- \ + -t 120 frappe.app:application --preload + ;; - worker) - checkConfigExists - checkConnection +worker) + checkConfigExists + checkConnection - : "${WORKER_TYPE:=default}" - bench worker --queue $WORKER_TYPE - ;; + : "${WORKER_TYPE:=default}" + bench worker --queue $WORKER_TYPE + ;; - schedule) - checkConfigExists - checkConnection +schedule) + checkConfigExists + checkConnection - bench schedule - ;; + bench schedule + ;; - new) - checkConfigExists - checkConnection +new) + checkConfigExists + checkConnection - /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/new.py - exit - ;; + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/new.py + exit + ;; - drop) - checkConfigExists - checkConnection +drop) + checkConfigExists + checkConnection - : "${SITE_NAME:=site1.localhost}" - : "${DB_ROOT_USER:=root}" - : "${DB_ROOT_PASSWORD:=$POSTGRES_PASSWORD}" - : "${DB_ROOT_PASSWORD:=$MYSQL_ROOT_PASSWORD}" - : "${DB_ROOT_PASSWORD:=admin}" - if [[ -n $NO_BACKUP ]]; then - NO_BACKUP=--no-backup - fi - if [[ -n $FORCE ]]; then - FORCE=--force - fi + : "${SITE_NAME:=site1.localhost}" + : "${DB_ROOT_USER:=root}" + : "${DB_ROOT_PASSWORD:=$POSTGRES_PASSWORD}" + : "${DB_ROOT_PASSWORD:=$MYSQL_ROOT_PASSWORD}" + : "${DB_ROOT_PASSWORD:=admin}" + if [[ -n $NO_BACKUP ]]; then + NO_BACKUP=--no-backup + fi + if [[ -n $FORCE ]]; then + FORCE=--force + fi - bench drop-site \ - $SITE_NAME \ - --root-login $DB_ROOT_USER \ - --root-password $DB_ROOT_PASSWORD \ - --archived-sites-path /home/frappe/frappe-bench/sites/archive_sites \ - $NO_BACKUP $FORCE - ;; + bench drop-site \ + $SITE_NAME \ + --root-login $DB_ROOT_USER \ + --root-password $DB_ROOT_PASSWORD \ + --archived-sites-path /home/frappe/frappe-bench/sites/archive_sites \ + $NO_BACKUP $FORCE + ;; - migrate) - /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/migrate.py - exit - ;; +migrate) + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/migrate.py + exit + ;; - doctor) - /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/doctor.py "${@:2}" - exit - ;; +doctor) + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/doctor.py "${@:2}" + exit + ;; - backup) - if [[ -n $WITH_FILES ]]; then - WITH_FILES=--with-files - fi +backup) + if [[ -n $WITH_FILES ]]; then + WITH_FILES=--with-files + fi - for site in ${$SITES//:/ }; do - bench --site $site backup $WITH_FILES - done - ;; + for site in ${SITES//:/ }; do + bench --site "$site" backup $WITH_FILES + done + ;; - console) - if [[ -z "$2" ]]; then - echo "Need to specify a sitename with the command:" >&2 - echo "console " >&2 - exit 1 - fi +console) + if [[ -z "$2" ]]; then + echo "Need to specify a sitename with the command:" >&2 + echo "console " >&2 + exit 1 + fi - bench --site "$2" console - ;; + bench --site "$2" console + ;; - push-backup) - /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/push_backup.py - exit - ;; +push-backup) + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/push_backup.py + exit + ;; - restore-backup) - /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/restore_backup.py - exit - ;; - *) - exec "$@" - ;; +restore-backup) + /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/commands/restore_backup.py + exit + ;; +*) + exec "$@" + ;; esac diff --git a/build/frappe-worker/healthcheck.sh b/build/frappe-worker/healthcheck.sh index 6d378ded..3c4266ee 100755 --- a/build/frappe-worker/healthcheck.sh +++ b/build/frappe-worker/healthcheck.sh @@ -17,17 +17,17 @@ 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=$(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=$(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=$(echo "${REDIS_SOCKETIO}" | cut -f1 -d"/") fi echo "Check ${DB_HOST}:${DB_PORT}" diff --git a/build/frappe-worker/install_app.sh b/build/frappe-worker/install_app.sh index d7de0842..6e55ec74 100755 --- a/build/frappe-worker/install_app.sh +++ b/build/frappe-worker/install_app.sh @@ -6,5 +6,6 @@ APP_BRANCH=${3} [[ -n "${APP_BRANCH}" ]] && BRANCH="-b ${APP_BRANCH}" -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} +# shellcheck disable=SC2086 +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/integration-test.sh b/tests/integration-test.sh index 14483f26..c9a609ba 100755 --- a/tests/integration-test.sh +++ b/tests/integration-test.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck source=functions.sh source tests/functions.sh project_name=frappe_bench_00 diff --git a/tests/test-erpnext.sh b/tests/test-erpnext.sh index ac734164..343326f9 100755 --- a/tests/test-erpnext.sh +++ b/tests/test-erpnext.sh @@ -2,7 +2,6 @@ set -e -# shellcheck source=functions.sh source tests/functions.sh project_name="test_erpnext" diff --git a/tests/test-frappe.sh b/tests/test-frappe.sh index c4998300..c28e0cfd 100755 --- a/tests/test-frappe.sh +++ b/tests/test-frappe.sh @@ -2,7 +2,6 @@ set -e -# shellcheck source=functions.sh source tests/functions.sh project_name="test_frappe"