From 5c86f8d45d6fb3330252fbc25e8638976e5b3f31 Mon Sep 17 00:00:00 2001 From: Aashwin Mohan Date: Thu, 12 Dec 2024 12:59:23 +0000 Subject: [PATCH] Improvements Improvements --- .gitignore | 3 +- README.md | 2 +- ...er-compose.yml => docker-compose.local.yml | 2 +- docker-run-local.sh | 39 ------------------- docker/scripts/configure-base-store.sh | 6 ++- docker/scripts/configure-hyva.sh | 3 -- docker/scripts/configure-rvvup.sh | 25 +++++++----- docker/scripts/fix-perms.sh | 1 + docker/scripts/post-magento-setup.sh | 11 +++++- docker/scripts/rebuild-magento.sh | 2 +- docker/scripts/run-on-local-volume.sh | 17 ++------ docker/scripts/setup.sh | 13 +++---- run-e2e-tests.sh | 22 ----------- scripts/helpers/wait-for-server-startup.sh | 36 +++++++++++++++++ scripts/local-bash.sh | 4 ++ scripts/local-cmd.sh | 4 ++ scripts/local-rebuild.sh | 5 +++ scripts/local-run.sh | 21 ++++++++++ scripts/run-e2e-tests.sh | 11 ++++++ 19 files changed, 127 insertions(+), 100 deletions(-) rename local.docker-compose.yml => docker-compose.local.yml (96%) delete mode 100755 docker-run-local.sh delete mode 100755 run-e2e-tests.sh create mode 100755 scripts/helpers/wait-for-server-startup.sh create mode 100755 scripts/local-bash.sh create mode 100755 scripts/local-cmd.sh create mode 100755 scripts/local-rebuild.sh create mode 100755 scripts/local-run.sh create mode 100755 scripts/run-e2e-tests.sh diff --git a/.gitignore b/.gitignore index ccc6c02..3b9b3c5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ playwright-report/ hyva/ .idea/ -.env \ No newline at end of file +vendor/ +.env diff --git a/README.md b/README.md index 3587a2b..7c6d9a2 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ npx playwright install This will spin up a docker container with magento with hyva + rvvup plugin installed and run the test against this container. ```bash -./run-e2e-tests.sh +./scripts/run-e2e-tests.sh ``` ### If you have an existing store, to run the tests, use the following command: diff --git a/local.docker-compose.yml b/docker-compose.local.yml similarity index 96% rename from local.docker-compose.yml rename to docker-compose.local.yml index d776afc..bcaf1ff 100644 --- a/local.docker-compose.yml +++ b/docker-compose.local.yml @@ -27,7 +27,7 @@ services: - MAGENTO_PASSWORD=password1 - MAGENTO_EMAIL=admin@test.com - RVVUP_API_KEY=$RVVUP_API_KEY - - RVVUP_HYVA_CHECKOUT_VERSION=$RVVUP_HYVA_CHECKOUT_VERSION + - RVVUP_HYVA_CHECKOUT_VERSION=local - MAGENTO_REPO_PUBLIC_KEY=$MAGENTO_REPO_PUBLIC_KEY - MAGENTO_REPO_PRIVATE_KEY=$MAGENTO_REPO_PRIVATE_KEY - HYVA_SSH_PRIVATE_KEY=$HYVA_SSH_PRIVATE_KEY diff --git a/docker-run-local.sh b/docker-run-local.sh deleted file mode 100755 index e817061..0000000 --- a/docker-run-local.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -start=$(date +%s) -docker compose down -v -HOST="local.dev.rvvuptech.com:89" -# Ideally, this commit is pushed to docker hub and we don't rebuild everytime, but for now we rebuild temporarily. -docker image rm magento-hyva-checkout-magento:latest -docker compose up -d -attempt=1 -while true; do - http_status=$(curl -o /dev/null -s -w "%{http_code}\n" -I "http://${HOST}/magento_version") - - if [ "$http_status" -eq 200 ]; then - echo -e "\rServer responded with 200 OK / Time taken: $(($(date +%s) - start)) seconds, continuing..." - break - else - echo -ne "\rAttempt $attempt: Waiting for server to be up (Might take a couple of minutes). Current status code: $http_status / Time taken: $(($(date +%s) - start)) seconds" - attempt=$((attempt + 1)) - sleep 2 - fi -done - -echo "Commiting base image" -docker commit magento-hyva-checkout-magento-1 magento-hyva-store:latest -echo "Restarting server with volume attached" -docker compose -f local.docker-compose.yml up -d - -attempt=1 -while true; do - http_status=$(curl -o /dev/null -s -w "%{http_code}\n" -I "http://${HOST}/magento_version") - - if [ "$http_status" -eq 200 ]; then - echo -e "\rServer responded with 200 OK / Time taken: $(($(date +%s) - start)) seconds, continuing..." - break - else - echo -ne "\rAttempt $attempt: Waiting for server to be up (Might take a couple of minutes). Current status code: $http_status / Time taken: $(($(date +%s) - start)) seconds" - attempt=$((attempt + 1)) - sleep 2 - fi -done \ No newline at end of file diff --git a/docker/scripts/configure-base-store.sh b/docker/scripts/configure-base-store.sh index a0ebf3d..2f25e46 100755 --- a/docker/scripts/configure-base-store.sh +++ b/docker/scripts/configure-base-store.sh @@ -19,4 +19,8 @@ bin/magento config:set system/smtp/port $MAGENTO_SMTP_PORT bin/magento sampledata:deploy -composer require n98/magerun2-dist \ No newline at end of file +# Disable opcache +sed -i 's/^opcache\.enable *= *1/opcache.enable = 0/' /opt/bitnami/php/etc/php.ini +sed -i 's/^opcache\.enable_cli *= *1/opcache.enable_cli = 0/' /opt/bitnami/php/etc/php.ini + +composer require n98/magerun2-dist diff --git a/docker/scripts/configure-hyva.sh b/docker/scripts/configure-hyva.sh index ff8a8d8..6e4fa8a 100755 --- a/docker/scripts/configure-hyva.sh +++ b/docker/scripts/configure-hyva.sh @@ -14,7 +14,4 @@ composer config repositories.hyva-themes/magento2-order-cancellation-webapi git composer config repositories.hyva-themes/hyva-checkout git git@gitlab.hyva.io:hyva-checkout/checkout.git composer require --prefer-source hyva-themes/magento2-default-theme composer require --prefer-source hyva-themes/magento2-hyva-checkout:^1.1 -bin/magento setup:upgrade bin/magento config:set dev/template/minify_html 0 -vendor/bin/n98-magerun2 config:store:set design/theme/theme_id 5 --scope=stores --scope-id=1 -vendor/bin/n98-magerun2 config:store:set hyva_themes_checkout/general/checkout default diff --git a/docker/scripts/configure-rvvup.sh b/docker/scripts/configure-rvvup.sh index 80c9807..0350346 100755 --- a/docker/scripts/configure-rvvup.sh +++ b/docker/scripts/configure-rvvup.sh @@ -1,14 +1,21 @@ echo "Running configure-rvvup.sh" cd /bitnami/magento -#composer require rvvup/module-magento-payments-hyva-checkout:$RVVUP_HYVA_CHECKOUT_VERSION -mkdir -p app/code/Rvvup/PaymentsHyvaCheckout - rm -rf generated/ -#bin/magento setup:upgrade -#bin/magento setup:di:compile -#bin/magento setup:static-content:deploy -f -#bin/magento cache:flush -bin/magento config:set payment/rvvup/jwt $RVVUP_API_KEY -bin/magento config:set payment/rvvup/active 1 +if [ "$RVVUP_HYVA_CHECKOUT_VERSION" == "local" ]; then + # Run the command for "local" + echo "Running local version setup..." +# composer config allow-plugins.wikimedia/composer-merge-plugin true +# composer require wikimedia/composer-merge-plugin +# jq '.extra."merge-plugin"."include" += ["app/code/Rvvup/composer.json"]' composer.json > composer-temp.json && mv composer-temp.json composer.json +# jq '.extra."merge-plugin"."merge-dev" = false' composer.json > composer-temp.json && mv composer-temp.json composer.json +# composer update -W + composer require rvvup/module-magento-payments:1.6.0 hyva-themes/magento2-compat-module-fallback:^1.0 hyva-themes/magento2-hyva-checkout:^1.1 magewirephp/magewire:* + mkdir -p app/code/Rvvup/PaymentsHyvaCheckout + +else + # Run the command for other values + echo "Running setup for version: $RVVUP_HYVA_CHECKOUT_VERSION" + composer require rvvup/module-magento-payments-hyva-checkout:$RVVUP_HYVA_CHECKOUT_VERSION +fi diff --git a/docker/scripts/fix-perms.sh b/docker/scripts/fix-perms.sh index 24a40a1..92ad319 100755 --- a/docker/scripts/fix-perms.sh +++ b/docker/scripts/fix-perms.sh @@ -3,3 +3,4 @@ mkdir -p var/cache mkdir -p var/log find var vendor pub/static pub/media app/etc generated var/log var/cache \( -type f -or -type d \) -exec chmod u+w {} +; chown -R daemon:daemon ./ +rm -rf var/cache/* var/generation/* var/page_cache/* var/view_preprocessed/* var/di/* pub/static/* generated/* diff --git a/docker/scripts/post-magento-setup.sh b/docker/scripts/post-magento-setup.sh index 8cb3acb..341e601 100755 --- a/docker/scripts/post-magento-setup.sh +++ b/docker/scripts/post-magento-setup.sh @@ -2,7 +2,16 @@ echo "Running post-magento-setup.sh" cd /bitnami/magento +bin/magento setup:upgrade + bin/magento hyva:config:generate npm --prefix vendor/hyva-themes/magento2-default-theme/web/tailwind/ ci npm --prefix vendor/hyva-themes/magento2-default-theme/web/tailwind/ run build-prod -bin/magento setup:upgrade + +/rvvup/scripts/rebuild-magento.sh + +vendor/bin/n98-magerun2 config:store:set design/theme/theme_id 5 --scope=stores --scope-id=1 +vendor/bin/n98-magerun2 config:store:set hyva_themes_checkout/general/checkout default + +bin/magento config:set payment/rvvup/jwt $RVVUP_API_KEY +bin/magento config:set payment/rvvup/active 1 diff --git a/docker/scripts/rebuild-magento.sh b/docker/scripts/rebuild-magento.sh index e35cc48..9f61b31 100755 --- a/docker/scripts/rebuild-magento.sh +++ b/docker/scripts/rebuild-magento.sh @@ -1,4 +1,4 @@ -echo "Running run on local" +echo "Running Rebuild Magento" cd /bitnami/magento/ bin/magento setup:upgrade bin/magento setup:di:compile diff --git a/docker/scripts/run-on-local-volume.sh b/docker/scripts/run-on-local-volume.sh index 0c5ce4d..7969787 100755 --- a/docker/scripts/run-on-local-volume.sh +++ b/docker/scripts/run-on-local-volume.sh @@ -1,15 +1,4 @@ -echo "Running run on local" +echo "Running against local volume" cd /bitnami/magento/ -#composer config allow-plugins.wikimedia/composer-merge-plugin true -#composer require wikimedia/composer-merge-plugin -#jq '.extra."merge-plugin"."include" += ["app/code/Rvvup/composer.json"]' composer.json > composer-temp.json && mv composer-temp.json composer.json -#jq '.extra."merge-plugin"."merge-dev" = false' composer.json > composer-temp.json && mv composer-temp.json composer.json -#composer update -W -composer require rvvup/module-magento-payments:1.6.0 hyva-themes/magento2-compat-module-fallback:^1.0 hyva-themes/magento2-hyva-checkout:^1.1 magewirephp/magewire:* -bin/magento setup:upgrade -bin/magento setup:di:compile -bin/magento setup:static-content:deploy -f -bin/magento config:set payment/rvvup/jwt $RVVUP_API_KEY -bin/magento config:set payment/rvvup/active 1 -bin/magento cache:flush -/rvvup/scripts/fix-perms.sh; + +/rvvup/scripts/rebuild-magento.sh diff --git a/docker/scripts/setup.sh b/docker/scripts/setup.sh index 478e913..c9cd66c 100755 --- a/docker/scripts/setup.sh +++ b/docker/scripts/setup.sh @@ -3,14 +3,13 @@ echo "Running setup.sh" /rvvup/scripts/configure-hyva.sh; /rvvup/scripts/configure-rvvup.sh; /rvvup/scripts/post-magento-setup.sh; -/rvvup/scripts/fix-perms.sh; + cd /bitnami/magento -echo "echo \"Run file\"" > /rvvup/scripts/configure-base-store.sh -echo "echo \"Run file\"" > /rvvup/scripts/configure-hyva.sh -echo "echo \"Run file\"" > /rvvup/scripts/configure-rvvup.sh +# Only run in first attempt, then reset +echo "echo \"Ignored running base store config\"" > /rvvup/scripts/configure-base-store.sh +echo "echo \"Ignored running hyva setup\"" > /rvvup/scripts/configure-hyva.sh +echo "echo \"Ignored running rvvup config\"" > /rvvup/scripts/configure-rvvup.sh echo "/rvvup/scripts/run-on-local-volume.sh" > /rvvup/scripts/post-magento-setup.sh -sed -i 's/^opcache\.enable *= *1/opcache.enable = 0/' /opt/bitnami/php/etc/php.ini -sed -i 's/^opcache\.enable_cli *= *1/opcache.enable_cli = 0/' /opt/bitnami/php/etc/php.ini -rm -rf var/cache/* var/generation/* var/page_cache/* var/view_preprocessed/* var/di/* pub/static/* generated/* +/rvvup/scripts/fix-perms.sh; /opt/bitnami/scripts/magento/run.sh; diff --git a/run-e2e-tests.sh b/run-e2e-tests.sh deleted file mode 100755 index b489e34..0000000 --- a/run-e2e-tests.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -start=$(date +%s) -docker compose up -d --build -attempt=1 -while true; do - http_status=$(curl -o /dev/null -s -w "%{http_code}\n" -I "http://local.dev.rvvuptech.com:89/magento_version") - - if [ "$http_status" -eq 200 ]; then - echo -e "\rServer responded with 200 OK / Time taken: $(($(date +%s) - start)) seconds, continuing..." - break - else - echo -ne "\rAttempt $attempt: Waiting for server to be up (Might take a couple of minutes). Current status code: $http_status / Time taken: $(($(date +%s) - start)) seconds" - attempt=$((attempt + 1)) - sleep 2 - fi -done - -if [ "$1" == "--ui" ]; then - ENV TEST_BASE_URL=http://local.dev.rvvuptech.com:89 npx playwright test --ui -else - ENV TEST_BASE_URL=http://local.dev.rvvuptech.com:89 npx playwright test -fi diff --git a/scripts/helpers/wait-for-server-startup.sh b/scripts/helpers/wait-for-server-startup.sh new file mode 100755 index 0000000..6d40b5e --- /dev/null +++ b/scripts/helpers/wait-for-server-startup.sh @@ -0,0 +1,36 @@ +#!/bin/bash +start=$(date +%s) +attempt=1 +spinner="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏" + +print_red() { + echo -e "\033[31m$1\033[0m" # Red text +} + +print_green() { + echo -e "\033[32m$1\033[0m" # Green text +} + +pretty_loader() { + local spinner_index=$((attempt % ${#spinner})) + printf "\033[33m%s\033[0m" "${spinner:$spinner_index:1}" +} + +while true; do + http_status=$(curl -o /dev/null -s -w "%{http_code}\n" -I "http://local.dev.rvvuptech.com:89/magento_version") + + if [ "$http_status" -eq 200 ]; then + print_green "\r✔ Server Ready. Time taken: $(($(date +%s) - start)) seconds." + break + fi + + if [ "$http_status" -gt 299 ]; then + print_red "\r✖ ERROR! Server responded with $http_status. Time taken: $(($(date +%s) - start)) seconds." + break; + else + echo -ne "\r$(pretty_loader) $(pretty_loader) \033[90mWaiting for server to be up (Might take a couple of minutes). Current Status: $http_status / Time taken: $(($(date +%s) - start)) seconds.\033[0m" + fi + + attempt=$((attempt + 1)) + sleep 1 +done diff --git a/scripts/local-bash.sh b/scripts/local-bash.sh new file mode 100755 index 0000000..c955fe3 --- /dev/null +++ b/scripts/local-bash.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -x +CURRENT_DIR_NAME=$(basename "$PWD") +docker exec -it -w "/bitnami/magento" "${CURRENT_DIR_NAME}-magento-1" /bin/bash diff --git a/scripts/local-cmd.sh b/scripts/local-cmd.sh new file mode 100755 index 0000000..7a43b92 --- /dev/null +++ b/scripts/local-cmd.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -x +CURRENT_DIR_NAME=$(basename "$PWD") +docker exec -it -w "/bitnami/magento" "${CURRENT_DIR_NAME}-magento-1" /bin/sh -c "$1" diff --git a/scripts/local-rebuild.sh b/scripts/local-rebuild.sh new file mode 100755 index 0000000..9d73f08 --- /dev/null +++ b/scripts/local-rebuild.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -x +BASE_DIR=$(dirname "$(realpath "$0")") + +$BASE_DIR/local-cmd.sh "/rvvup/scripts/rebuild-magento.sh" diff --git a/scripts/local-run.sh b/scripts/local-run.sh new file mode 100755 index 0000000..d892e2f --- /dev/null +++ b/scripts/local-run.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -x +set -e +BASE_DIR=$(dirname "$(realpath "$0")") +HOST="local.dev.rvvuptech.com:89" +CURRENT_DIR_NAME=$(basename "$PWD") +RVVUP_HYVA_CHECKOUT_VERSION='local' +# Ideally, this commit is pushed to docker hub and we don't rebuild everytime, but for now we rebuild temporarily. +docker compose down -v +docker image rm $CURRENT_DIR_NAME-magento:latest +docker compose up -d +$BASE_DIR/helpers/wait-for-server-startup.sh + +echo "Commiting base image" +docker commit $CURRENT_DIR_NAME-magento-1 magento-hyva-store:latest +echo "Restarting server with volume attached" +docker compose -f docker-compose.local.yml up -d + +$BASE_DIR/helpers/wait-for-server-startup.sh +echo -e "\033[32mSuccessfully started up server on http://$HOST\033[0m" +open http://$HOST diff --git a/scripts/run-e2e-tests.sh b/scripts/run-e2e-tests.sh new file mode 100755 index 0000000..4dd870c --- /dev/null +++ b/scripts/run-e2e-tests.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +BASE_DIR=$(dirname "$(realpath "$0")") +docker compose up -d --build +$BASE_DIR/helpers/wait-for-server-startup.sh + +if [ "$1" == "--ui" ]; then + ENV TEST_BASE_URL=http://local.dev.rvvuptech.com:89 npx playwright test --ui +else + ENV TEST_BASE_URL=http://local.dev.rvvuptech.com:89 npx playwright test +fi