diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..663c54b --- /dev/null +++ b/.env.sample @@ -0,0 +1,9 @@ +#RVVUP_PLUGIN_VERSION=dev-main +RVVUP_HYVA_CHECKOUT_VERSION=dev-main +RVVUP_API_KEY=replace.this.jwt +# Access to Magento Repository: https://experienceleague.adobe.com/en/docs/commerce-operations/installation-guide/prerequisites/authentication-keys +MAGENTO_REPO_PUBLIC_KEY=replacethis +MAGENTO_REPO_PRIVATE_KEY=replacethis +# Remove Magento Version line if you want to use the latest version +MAGENTO_VERSION=2.4.5 +HYVA_SSH_PRIVATE_KEY=replacethis diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fe0c779 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +ARG MAGENTO_VERSION=2 +FROM docker.io/bitnami/magento:${MAGENTO_VERSION} +COPY ./docker/scripts /rvvup/scripts +RUN apt-get update && apt-get install -y \ + unzip \ + git \ + vim \ + curl \ + && rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs + +ENTRYPOINT ["/rvvup/scripts/entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..72cf2ba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,53 @@ +services: + mariadb: + image: docker.io/bitnami/mariadb:10.4 + environment: + # ALLOW_EMPTY_PASSWORD is recommended only for development. + - ALLOW_EMPTY_PASSWORD=yes + - MARIADB_USER=bn_magento + - MARIADB_DATABASE=bitnami_magento + volumes: + - 'data_mariadb:/bitnami/mariadb' + magento: + ports: + - '80:8080' + - '443:8443' + environment: + - BITNAMI_DEBUG=true + - MAGENTO_HOST=localhost + - MAGENTO_DATABASE_HOST=mariadb + - MAGENTO_DATABASE_PORT_NUMBER=3306 + - MAGENTO_DATABASE_USER=bn_magento + - MAGENTO_DATABASE_NAME=bitnami_magento + - ELASTICSEARCH_HOST=elasticsearch + - ELASTICSEARCH_PORT_NUMBER=9200 + # ALLOW_EMPTY_PASSWORD is recommended only for development. + - ALLOW_EMPTY_PASSWORD=yes + - MAGENTO_USERNAME=admin + - MAGENTO_PASSWORD=password1 + - MAGENTO_EMAIL=admin@test.com + - RVVUP_API_KEY=$RVVUP_API_KEY + - RVVUP_PLUGIN_VERSION=$RVVUP_PLUGIN_VERSION + - RVVUP_HYVA_CHECKOUT_VERSION=$RVVUP_HYVA_CHECKOUT_VERSION + - MAGENTO_REPO_PUBLIC_KEY=$MAGENTO_REPO_PUBLIC_KEY + - MAGENTO_REPO_PRIVATE_KEY=$MAGENTO_REPO_PRIVATE_KEY + - HYVA_SSH_PRIVATE_KEY=$HYVA_SSH_PRIVATE_KEY + build: + context: . + dockerfile: Dockerfile + args: + MAGENTO_VERSION: $MAGENTO_VERSION + depends_on: + - mariadb + - elasticsearch + elasticsearch: + image: docker.io/bitnami/elasticsearch:7 + volumes: + - 'elasticsearch_data:/bitnami/elasticsearch/data' +volumes: + data_mariadb: + driver: local + magento_data: + driver: local + elasticsearch_data: + driver: local diff --git a/docker/scripts/configure-base-store.sh b/docker/scripts/configure-base-store.sh new file mode 100755 index 0000000..7de31e9 --- /dev/null +++ b/docker/scripts/configure-base-store.sh @@ -0,0 +1,11 @@ +echo "Running configure-base-store.sh" + +cd /bitnami/magento +composer config repositories.magento composer https://repo.magento.com/ +composer config http-basic.repo.magento.com $MAGENTO_REPO_PUBLIC_KEY $MAGENTO_REPO_PRIVATE_KEY +bin/magento config:set currency/options/allow GBP,USD +bin/magento config:set currency/options/base GBP +bin/magento config:set currency/options/default GBP +bin/magento config:set general/locale/timezone Europe/London +bin/magento config:set general/locale/code en_GB +bin/magento sampledata:deploy diff --git a/docker/scripts/configure-hyva.sh b/docker/scripts/configure-hyva.sh new file mode 100755 index 0000000..6e79299 --- /dev/null +++ b/docker/scripts/configure-hyva.sh @@ -0,0 +1,20 @@ +echo "Running configure-hyva.sh" + +mkdir -p /root/.ssh/ && echo "$HYVA_SSH_PRIVATE_KEY" > /root/.ssh/id_ed25519 +chmod 700 /root/.ssh && chmod 600 /root/.ssh/id_ed25519 +ssh-keyscan -t rsa gitlab.hyva.io >> /root/.ssh/known_hosts +cd /bitnami/magento + +composer config repositories.hyva-themes/magento2-theme-module git git@gitlab.hyva.io:hyva-themes/magento2-theme-module.git +composer config repositories.hyva-themes/magento2-reset-theme git git@gitlab.hyva.io:hyva-themes/magento2-reset-theme.git +composer config repositories.hyva-themes/magento2-email-module git git@gitlab.hyva.io:hyva-themes/magento2-email-module.git +composer config repositories.hyva-themes/magento2-default-theme git git@gitlab.hyva.io:hyva-themes/magento2-default-theme.git +composer config repositories.hyva-themes/magento2-compat-module-fallback git git@gitlab.hyva.io:hyva-themes/magento2-compat-module-fallback.git +composer config repositories.hyva-themes/magento2-order-cancellation-webapi git git@gitlab.hyva.io: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 +#bin/magento config:set design/theme/theme_id 5 --scope=stores +bin/magento config:set hyva_themes_checkout/general/checkout default diff --git a/docker/scripts/configure-rvvup.sh b/docker/scripts/configure-rvvup.sh new file mode 100755 index 0000000..a9b3595 --- /dev/null +++ b/docker/scripts/configure-rvvup.sh @@ -0,0 +1,14 @@ +echo "Running configure-rvvup.sh" + +cd /bitnami/magento +#composer require rvvup/module-magento-payments:$RVVUP_PLUGIN_VERSION +composer require rvvup/module-magento-payments-hyva-checkout:$RVVUP_HYVA_CHECKOUT_VERSION + +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 diff --git a/docker/scripts/entrypoint.sh b/docker/scripts/entrypoint.sh new file mode 100755 index 0000000..b8758b0 --- /dev/null +++ b/docker/scripts/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash +echo "Running entrypoint.sh" +#Start of Bitnami's Entrypoint script +set -o errexit +set -o nounset +set -o pipefail +# set -o xtrace # Uncomment this line for debugging purposes + +# Load Magento environment +. /opt/bitnami/scripts/magento-env.sh + +# Load libraries +. /opt/bitnami/scripts/libbitnami.sh +. /opt/bitnami/scripts/liblog.sh +. /opt/bitnami/scripts/libwebserver.sh + +print_welcome_page + +info "** Starting Magento setup **" +/opt/bitnami/scripts/"$(web_server_type)"/setup.sh +/opt/bitnami/scripts/php/setup.sh +/opt/bitnami/scripts/mysql-client/setup.sh +/opt/bitnami/scripts/magento/setup.sh +/post-init.sh +info "** Magento setup finished! **" +# End of Bitnami's Entrypoint script, now we can add rvvup's setup +/rvvup/scripts/setup.sh; diff --git a/docker/scripts/fix-perms.sh b/docker/scripts/fix-perms.sh new file mode 100755 index 0000000..24a40a1 --- /dev/null +++ b/docker/scripts/fix-perms.sh @@ -0,0 +1,5 @@ +cd /bitnami/magento +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 ./ diff --git a/docker/scripts/setup.sh b/docker/scripts/setup.sh new file mode 100755 index 0000000..b795d70 --- /dev/null +++ b/docker/scripts/setup.sh @@ -0,0 +1,6 @@ +echo "Running setup.sh" +/rvvup/scripts/configure-base-store.sh; +/rvvup/scripts/configure-hyva.sh; +/rvvup/scripts/configure-rvvup.sh; +/rvvup/scripts/fix-perms.sh; +/opt/bitnami/scripts/magento/run.sh; diff --git a/run-e2e-tests.sh b/run-e2e-tests.sh new file mode 100755 index 0000000..1c8b134 --- /dev/null +++ b/run-e2e-tests.sh @@ -0,0 +1,22 @@ +#!/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://localhost/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://localhost npx playwright test --ui +else + ENV TEST_BASE_URL=http://localhost npx playwright test +fi