Skip to content

Commit

Permalink
Add docker containers to run magento store for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aashwin-rvvup committed May 8, 2024
1 parent dbcc057 commit 713f8db
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
53 changes: 53 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
- [email protected]
- 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
11 changes: 11 additions & 0 deletions docker/scripts/configure-base-store.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions docker/scripts/configure-hyva.sh
Original file line number Diff line number Diff line change
@@ -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 [email protected]:hyva-themes/magento2-theme-module.git
composer config repositories.hyva-themes/magento2-reset-theme git [email protected]:hyva-themes/magento2-reset-theme.git
composer config repositories.hyva-themes/magento2-email-module git [email protected]:hyva-themes/magento2-email-module.git
composer config repositories.hyva-themes/magento2-default-theme git [email protected]:hyva-themes/magento2-default-theme.git
composer config repositories.hyva-themes/magento2-compat-module-fallback git [email protected]:hyva-themes/magento2-compat-module-fallback.git
composer config repositories.hyva-themes/magento2-order-cancellation-webapi git [email protected]:hyva-themes/magento2-order-cancellation-webapi.git
composer config repositories.hyva-themes/hyva-checkout git [email protected]: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
14 changes: 14 additions & 0 deletions docker/scripts/configure-rvvup.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docker/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions docker/scripts/fix-perms.sh
Original file line number Diff line number Diff line change
@@ -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 ./
6 changes: 6 additions & 0 deletions docker/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 713f8db

Please sign in to comment.