diff --git a/.github/scripts/get-latest-tags.sh b/.github/scripts/get-latest-tags.sh index cfcf85e9..46784ba6 100755 --- a/.github/scripts/get-latest-tags.sh +++ b/.github/scripts/get-latest-tags.sh @@ -4,9 +4,9 @@ set -e set -x get_tag() { - tags=$(git ls-remote --refs --tags --sort='v:refname' "https://github.com/$1" "v$2.*") - tag=$(echo "$tags" | tail -n1 | sed 's/.*\///') - echo "$tag" + tags=$(git ls-remote --refs --tags --sort='v:refname' "https://github.com/$1" "v$2.*") + tag=$(echo "$tags" | tail -n1 | sed 's/.*\///') + echo "$tag" } FRAPPE_VERSION=$(get_tag frappe/frappe "$VERSION") diff --git a/tests/functions.sh b/tests/functions.sh index 8453c499..e077dbd9 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -1,26 +1,26 @@ #!/bin/bash print_group() { - echo ::endgroup:: - echo "::group::$*" + echo ::endgroup:: + echo "::group::$*" } ping_site() { - print_group "Ping site $SITE_NAME" + print_group "Ping site $SITE_NAME" - echo Ping version - ping_res=$(curl -sS "http://$SITE_NAME/api/method/version") - echo "$ping_res" - if [[ -z $(echo "$ping_res" | grep "message" || echo "") ]]; then - echo "Ping failed" - exit 1 - fi + echo Ping version + ping_res=$(curl -sS "http://$SITE_NAME/api/method/version") + echo "$ping_res" + if [[ -z $(echo "$ping_res" | grep "message" || echo "") ]]; then + echo "Ping failed" + exit 1 + fi - echo Check index - index_res=$(curl -sS "http://$SITE_NAME") - if [[ -n $(echo "$index_res" | grep "Internal Server Error" || echo "") ]]; then - echo "Index check failed" - echo "$index_res" - exit 1 - fi + echo Check index + index_res=$(curl -sS "http://$SITE_NAME") + if [[ -n $(echo "$index_res" | grep "Internal Server Error" || echo "") ]]; then + echo "Index check failed" + echo "$index_res" + exit 1 + fi } diff --git a/tests/integration-test.sh b/tests/integration-test.sh index af7a8831..a76a5479 100755 --- a/tests/integration-test.sh +++ b/tests/integration-test.sh @@ -7,63 +7,63 @@ source tests/functions.sh project_name=frappe_bench_00 docker_compose_with_args() { - # shellcheck disable=SC2068 - docker-compose \ - -p $project_name \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-frappe.yml \ - -f installation/frappe-publish.yml \ - $@ + # shellcheck disable=SC2068 + docker-compose \ + -p $project_name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-frappe.yml \ + -f installation/frappe-publish.yml \ + $@ } check_migration_complete() { - print_group Check migration + print_group Check migration - container_id=$(docker_compose_with_args ps -q frappe-python) - cmd="docker logs ${container_id} 2>&1 | grep 'Starting gunicorn' || echo ''" + container_id=$(docker_compose_with_args ps -q frappe-python) + cmd="docker logs ${container_id} 2>&1 | grep 'Starting gunicorn' || echo ''" + worker_log=$(eval "$cmd") + INCREMENT=0 + + while [[ ${worker_log} != *"Starting gunicorn"* && ${INCREMENT} -lt 120 ]]; do + sleep 3 + ((INCREMENT = INCREMENT + 1)) + echo "Wait for migration to complete..." worker_log=$(eval "$cmd") - INCREMENT=0 + if [[ ${worker_log} != *"Starting gunicorn"* && ${INCREMENT} -eq 120 ]]; then + echo Migration timeout + docker logs "${container_id}" + exit 1 + fi + done - while [[ ${worker_log} != *"Starting gunicorn"* && ${INCREMENT} -lt 120 ]]; do - sleep 3 - ((INCREMENT = INCREMENT + 1)) - echo "Wait for migration to complete..." - worker_log=$(eval "$cmd") - if [[ ${worker_log} != *"Starting gunicorn"* && ${INCREMENT} -eq 120 ]]; then - echo Migration timeout - docker logs "${container_id}" - exit 1 - fi - done - - echo Migration Log - docker logs "${container_id}" + echo Migration Log + docker logs "${container_id}" } check_health() { - print_group Loop health check + print_group Loop health check - docker run --name frappe_doctor \ - -v "${project_name}_sites-vol:/home/frappe/frappe-bench/sites" \ - --network "${project_name}_default" \ - frappe/frappe-worker:edge doctor || true + docker run --name frappe_doctor \ + -v "${project_name}_sites-vol:/home/frappe/frappe-bench/sites" \ + --network "${project_name}_default" \ + frappe/frappe-worker:edge doctor || true - cmd='docker logs frappe_doctor | grep "Health check successful" || echo ""' + cmd='docker logs frappe_doctor | grep "Health check successful" || echo ""' + doctor_log=$(eval "$cmd") + INCREMENT=0 + + while [[ -z "${doctor_log}" && ${INCREMENT} -lt 60 ]]; do + sleep 1 + ((INCREMENT = INCREMENT + 1)) + container=$(docker start frappe_doctor) + echo "Restarting ${container}..." doctor_log=$(eval "$cmd") - INCREMENT=0 - while [[ -z "${doctor_log}" && ${INCREMENT} -lt 60 ]]; do - sleep 1 - ((INCREMENT = INCREMENT + 1)) - container=$(docker start frappe_doctor) - echo "Restarting ${container}..." - doctor_log=$(eval "$cmd") - - if [[ ${INCREMENT} -eq 60 ]]; then - docker logs "${container}" - exit 1 - fi - done + if [[ ${INCREMENT} -eq 60 ]]; then + docker logs "${container}" + exit 1 + fi + done } # Initial group @@ -81,23 +81,23 @@ docker_compose_with_args up -d --quiet-pull echo Start postgres docker pull postgres:11.8 -q docker run \ - --name postgresql \ - -d \ - -e POSTGRES_PASSWORD=admin \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - postgres:11.8 + --name postgresql \ + -d \ + -e POSTGRES_PASSWORD=admin \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + postgres:11.8 check_health print_group "Create new site " SITE_NAME=test.localhost docker run \ - --rm \ - -e SITE_NAME=$SITE_NAME \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:v13 new + --rm \ + -e SITE_NAME=$SITE_NAME \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:v13 new ping_site @@ -118,25 +118,25 @@ ping_site PG_SITE_NAME=pgsql.localhost print_group "Create new site (Postgres)" docker run \ - --rm \ - -e SITE_NAME=$PG_SITE_NAME \ - -e POSTGRES_HOST=postgresql \ - -e DB_ROOT_USER=postgres \ - -e POSTGRES_PASSWORD=admin \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge new + --rm \ + -e SITE_NAME=$PG_SITE_NAME \ + -e POSTGRES_HOST=postgresql \ + -e DB_ROOT_USER=postgres \ + -e POSTGRES_PASSWORD=admin \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge new check_migration_complete SITE_NAME=$PG_SITE_NAME ping_site print_group Backup site docker run \ - --rm \ - -e WITH_FILES=1 \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge backup + --rm \ + -e WITH_FILES=1 \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge backup MINIO_ACCESS_KEY="AKIAIOSFODNN7EXAMPLE" MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" @@ -144,39 +144,39 @@ MINIO_SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" print_group Prepare S3 server echo Start S3 server docker run \ - --name minio \ - -d \ - -e "MINIO_ACCESS_KEY=$MINIO_ACCESS_KEY" \ - -e "MINIO_SECRET_KEY=$MINIO_SECRET_KEY" \ - --network ${project_name}_default \ - minio/minio server /data + --name minio \ + -d \ + -e "MINIO_ACCESS_KEY=$MINIO_ACCESS_KEY" \ + -e "MINIO_SECRET_KEY=$MINIO_SECRET_KEY" \ + --network ${project_name}_default \ + minio/minio server /data echo Create bucket docker run \ - --rm \ - --network ${project_name}_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://frappe + --rm \ + --network ${project_name}_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://frappe print_group Push backup docker run \ - --rm \ - -e BUCKET_NAME=frappe \ - -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 ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge push-backup + --rm \ + -e BUCKET_NAME=frappe \ + -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 ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge push-backup print_group Prune and restart services docker_compose_with_args stop @@ -187,17 +187,17 @@ check_health print_group Restore backup from S3 docker run \ - --rm \ - -e MYSQL_ROOT_PASSWORD=admin \ - -e BUCKET_NAME=frappe \ - -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 ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge restore-backup + --rm \ + -e MYSQL_ROOT_PASSWORD=admin \ + -e BUCKET_NAME=frappe \ + -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 ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge restore-backup check_health ping_site @@ -206,78 +206,78 @@ SITE_NAME=$PG_SITE_NAME ping_site EDGE_SITE_NAME=edge.localhost print_group "Create new site (edge)" docker run \ - --rm \ - -e SITE_NAME=$EDGE_SITE_NAME \ - -e INSTALL_APPS=frappe \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge new + --rm \ + -e SITE_NAME=$EDGE_SITE_NAME \ + -e INSTALL_APPS=frappe \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge new check_health SITE_NAME=$EDGE_SITE_NAME ping_site print_group Migrate edge site docker run \ - --rm \ - -e MAINTENANCE_MODE=1 \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - -v ${project_name}_assets-vol:/home/frappe/frappe-bench/sites/assets \ - --network ${project_name}_default \ - frappe/frappe-worker:edge migrate + --rm \ + -e MAINTENANCE_MODE=1 \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + -v ${project_name}_assets-vol:/home/frappe/frappe-bench/sites/assets \ + --network ${project_name}_default \ + frappe/frappe-worker:edge migrate check_migration_complete print_group "Restore backup S3 (overwrite)" docker run \ - --rm \ - -e MYSQL_ROOT_PASSWORD=admin \ - -e BUCKET_NAME=frappe \ - -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 ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge restore-backup + --rm \ + -e MYSQL_ROOT_PASSWORD=admin \ + -e BUCKET_NAME=frappe \ + -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 ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge restore-backup check_migration_complete ping_site print_group "Check console for $SITE_NAME" docker run \ - --rm \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge console $SITE_NAME + --rm \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge console $SITE_NAME print_group "Check console for $PG_SITE_NAME" docker run \ - --rm \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge console $PG_SITE_NAME + --rm \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge console $PG_SITE_NAME print_group "Check drop site for $SITE_NAME (MariaDB)" docker run \ - --rm \ - -e SITE_NAME=$SITE_NAME \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge drop + --rm \ + -e SITE_NAME=$SITE_NAME \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge drop print_group "Check drop site for $PG_SITE_NAME (Postgres)" docker run \ - --rm \ - -e SITE_NAME=$PG_SITE_NAME \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:edge drop + --rm \ + -e SITE_NAME=$PG_SITE_NAME \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:edge drop print_group Check bench --help docker run \ - --rm \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - --user frappe \ - frappe/frappe-worker:edge bench --help + --rm \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + --user frappe \ + frappe/frappe-worker:edge bench --help diff --git a/tests/test-erpnext.sh b/tests/test-erpnext.sh index e2eb6902..c83151a9 100755 --- a/tests/test-erpnext.sh +++ b/tests/test-erpnext.sh @@ -16,29 +16,29 @@ cat .env print_group Start services docker-compose \ - -p $project_name \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/erpnext-publish.yml \ - up -d + -p $project_name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-erpnext.yml \ + -f installation/erpnext-publish.yml \ + up -d print_group Fix permissions docker run \ - --rm \ - --user root \ - -v ${project_name}_sites-vol:/sites \ - -v ${project_name}_assets-vol:/assets \ - -v ${project_name}_logs-vol:/logs \ - frappe/erpnext-worker:test chown -R 1000:1000 /logs /sites /assets + --rm \ + --user root \ + -v ${project_name}_sites-vol:/sites \ + -v ${project_name}_assets-vol:/assets \ + -v ${project_name}_logs-vol:/logs \ + frappe/erpnext-worker:test chown -R 1000:1000 /logs /sites /assets print_group Create site docker run \ - --rm \ - -e "SITE_NAME=$SITE_NAME" \ - -e "INSTALL_APPS=erpnext" \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/erpnext-worker:test new + --rm \ + -e "SITE_NAME=$SITE_NAME" \ + -e "INSTALL_APPS=erpnext" \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/erpnext-worker:test new ping_site rm .env diff --git a/tests/test-frappe.sh b/tests/test-frappe.sh index 035aa2c9..12131839 100755 --- a/tests/test-frappe.sh +++ b/tests/test-frappe.sh @@ -8,13 +8,13 @@ project_name="test_frappe" SITE_NAME="test_frappe.localhost" docker_compose_with_args() { - # shellcheck disable=SC2068 - docker-compose \ - -p $project_name \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-frappe.yml \ - -f installation/frappe-publish.yml \ - $@ + # shellcheck disable=SC2068 + docker-compose \ + -p $project_name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-frappe.yml \ + -f installation/frappe-publish.yml \ + $@ } echo ::group::Setup env @@ -29,11 +29,11 @@ docker_compose_with_args up -d print_group Create site docker run \ - --rm \ - -e "SITE_NAME=$SITE_NAME" \ - -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ - --network ${project_name}_default \ - frappe/frappe-worker:test new + --rm \ + -e "SITE_NAME=$SITE_NAME" \ + -v ${project_name}_sites-vol:/home/frappe/frappe-bench/sites \ + --network ${project_name}_default \ + frappe/frappe-worker:test new ping_site