|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | +set -x |
| 5 | + |
| 6 | +export PHP_VERSION_SHORT=$(echo "${PHP_VERSION:-8.1}" | sed 's/\.//') |
| 7 | + |
| 8 | +# Handy aliases |
| 9 | +HN="docker-compose exec -T hypernode" |
| 10 | +DP="docker-compose exec -T deploy" |
| 11 | +DP1="docker-compose exec --workdir=/web1 -T deploy" |
| 12 | +DP2="docker-compose exec --workdir=/web2 -T deploy" |
| 13 | + |
| 14 | +function install_magento() { |
| 15 | + $HN mysql -e "DROP DATABASE IF EXISTS dummytag_preinstalled_magento" |
| 16 | + $HN mysql -e "CREATE DATABASE dummytag_preinstalled_magento" |
| 17 | + local pw=$($HN bash -c "grep password /data/web/.my.cnf | cut -d' ' -f3") |
| 18 | + |
| 19 | + # Strip carriage return of pw and saves it in a new variable |
| 20 | + pw=$(echo $pw | tr -d '\r') |
| 21 | + |
| 22 | + $HN bash -c "/data/web/magento2/bin/magento setup:install \ |
| 23 | + --base-url=http://banaan1.store \ |
| 24 | + --db-host=mysqlmaster.dummytag.hypernode.io \ |
| 25 | + --db-name=dummytag_preinstalled_magento --db-user=app \ |
| 26 | + --db-password=$pw \ |
| 27 | + --admin-firstname=admin --admin-lastname=admin \ |
| 28 | + [email protected] --admin-user=admin \ |
| 29 | + --admin-password=admin123 --language=en_US --currency=USD \ |
| 30 | + --timezone=America/Chicago --elasticsearch-host=localhost" |
| 31 | +} |
| 32 | + |
| 33 | +# Install docker-compose if it's not installed |
| 34 | +if ! [ -x "$(command -v docker-compose)" ]; then |
| 35 | + pip install docker-compose |
| 36 | +fi |
| 37 | + |
| 38 | +# Clear up env |
| 39 | +trap "docker-compose down -v" EXIT |
| 40 | + |
| 41 | +docker-compose up -d |
| 42 | + |
| 43 | +# Create working initial Magento install on the Hypernode container |
| 44 | +$HN composer create-project --repository=https://mage-os.hypernode.com/mirror/ magento/project-community-edition /data/web/magento2 |
| 45 | +echo "Waiting for MySQL to be available on the Hypernode container" |
| 46 | +$HN bash -c "until mysql -e 'select 1' ; do sleep 1; done" |
| 47 | +install_magento |
| 48 | + |
| 49 | +# Copy env to the deploy container |
| 50 | +$HN /data/web/magento2/bin/magento app:config:dump scopes themes |
| 51 | +echo "Waiting for SSH to be available on the Hypernode container" |
| 52 | +chmod 0600 ci/test/.ssh/id_rsa |
| 53 | +chmod 0600 ci/test/.ssh/authorized_keys |
| 54 | +$DP rsync -a app@hypernode:/data/web/magento2/ /web |
| 55 | +$DP rsync -v -a /config/ /web |
| 56 | +$DP rm /web/app/etc/env.php |
| 57 | + |
| 58 | +# Create second app |
| 59 | +$DP cp -ra /web /web1 |
| 60 | +$DP cp -ra /web /web2 |
| 61 | + |
| 62 | +# Build both apps |
| 63 | +$DP1 hypernode-deploy build -v -f /web1/deploy1.php |
| 64 | +$DP2 hypernode-deploy build -v -f /web2/deploy2.php |
| 65 | + |
| 66 | +# Prepare env |
| 67 | +$HN mkdir -p /data/web/apps/banaan1.store/shared/app/etc/ |
| 68 | +$HN cp /data/web/magento2/app/etc/env.php /data/web/apps/banaan1.store/shared/app/etc/env.php |
| 69 | +$HN mkdir -p /data/web/apps/banaan2.store/shared/app/etc/ |
| 70 | +$HN cp /data/web/magento2/app/etc/env.php /data/web/apps/banaan2.store/shared/app/etc/env.php |
| 71 | +$HN chown -R app:app /data/web/apps |
| 72 | + |
| 73 | +########################################## |
| 74 | +# DEPLOY WITHOUT PLATFORM CONFIGURATIONS # |
| 75 | +# This should pass, but not generate any # |
| 76 | +# Nginx/Supervisor/etc configs # |
| 77 | +########################################## |
| 78 | +# SSH from deploy container to hypernode container |
| 79 | +$DP1 hypernode-deploy deploy production -f /web1/deploy1_without_platformconfig.php -v |
| 80 | + |
| 81 | +# Check if deployment made only one release for store1 |
| 82 | +test $($HN ls /data/web/apps/banaan1.store/releases/ | wc -l) = 1 |
| 83 | + |
| 84 | +# Platform configs shouldn't be present yet |
| 85 | +$HN test ! -d /data/web/nginx/banaan1.store |
| 86 | +$HN test ! -d /data/web/supervisor/banaan1.store |
| 87 | +$HN crontab -l -u app | grep "### BEGIN banaan1.store ###" && exit 1 |
| 88 | +$HN test ! -d /data/web/varnish/banaan1.store |
| 89 | + |
| 90 | +################## |
| 91 | +# DEPLOY STORE 2 # |
| 92 | +################## |
| 93 | +# Store 2 |
| 94 | +$DP2 hypernode-deploy deploy production -f /web2/deploy2.php -v |
| 95 | + |
| 96 | +# Check if deployment made only one release for store2 |
| 97 | +test $($HN ls /data/web/apps/banaan2.store/releases/ | wc -l) = 1 |
| 98 | +$HN ls -al /data/web/nginx/banaan2.store/ |
| 99 | +$HN ls -al /data/web/apps/banaan2.store/current/ |
| 100 | +$HN ls -al /data/web/apps/banaan2.store/current/.hypernode/nginx/ |
| 101 | +$HN test -f /data/web/nginx/banaan2.store/server.example.conf || ($HN ls -al /data/web/nginx && $HN ls -al /data/web/nginx/banaan2.store && exit 1) |
| 102 | +$HN test $($HN readlink -f /data/web/nginx/banaan2.store) = /data/web/apps/banaan2.store/releases/1/.hypernode/nginx |
| 103 | + |
| 104 | +################################## |
| 105 | +# DEPLOY PLATFORM CONFIGURATIONS # |
| 106 | +# Now we should get revisions of # |
| 107 | +# all platform configs. # |
| 108 | +################################## |
| 109 | +$DP1 hypernode-deploy deploy production -v -f /web1/deploy1.php |
| 110 | + |
| 111 | +# Check if example location block was placed |
| 112 | +$HN ls -al /data/web/nginx/banaan1.store/ |
| 113 | +$HN ls -al /data/web/apps/banaan1.store/current/ |
| 114 | +$HN ls -al /data/web/apps/banaan1.store/current/.hypernode/nginx/ |
| 115 | +$HN test -f /data/web/nginx/banaan1.store/server.example.conf || ($HN ls -al /data/web/nginx && $HN ls -al /data/web/nginx/banaan1.store && exit 1) |
| 116 | +$HN test $($HN readlink -f /data/web/nginx/banaan1.store) = /data/web/apps/banaan1.store/releases/2/.hypernode/nginx |
| 117 | + |
| 118 | +$HN test -f /data/web/supervisor/banaan1.store/example.conf || ($HN ls -al /data/web/supervisor/ && exit 1) |
| 119 | +$HN test $($HN readlink -f /data/web/supervisor/banaan1.store) = /data/web/apps/banaan1.store/releases/2/.hypernode/supervisor |
| 120 | + |
| 121 | +# Test this once we enable supervisor in the hypernode docker image |
| 122 | +# $HN supervisorctl status | grep example | grep -v FATAL || ($HN supervisorctl status && exit 1) |
| 123 | + |
| 124 | +# Test if varnish dirs exists and vcl has been placed |
| 125 | +$HN ls -al /data/web/varnish/banaan1.store/ |
| 126 | +$HN ls -al /data/web/apps/banaan1.store/current/.hypernode/varnish/ |
| 127 | + |
| 128 | +$HN test -f /data/web/varnish/banaan1.store/varnish.vcl || ($HN ls -al /data/web/varnish/ && exit 1) |
| 129 | +$HN test $($HN readlink -f /data/web/varnish/banaan1.store/varnish.vcl) = /data/web/apps/banaan1.store/releases/2/.hypernode/varnish/varnish.vcl |
| 130 | + |
| 131 | +# Check the content of the crontab block |
| 132 | +$HN crontab -l -u app | grep "### BEGIN banaan1.store ###" |
| 133 | +$HN crontab -l -u app | grep "### END banaan1.store ###" |
| 134 | +$HN crontab -l -u app | sed -n -e '/### BEGIN banaan1.store ###/,/### END banaan1.store ###/ p' | grep "banaan" |
| 135 | + |
| 136 | +###################################### |
| 137 | +# REMOVE A NGINX LOCATION # |
| 138 | +# Create a new release but make sure # |
| 139 | +# that the file is removed in the # |
| 140 | +# new release. # |
| 141 | +###################################### |
| 142 | +# Remove example location |
| 143 | +$DP rm /web1/etc/nginx/server.example.conf |
| 144 | + |
| 145 | +# Deploy again |
| 146 | +$DP1 hypernode-deploy deploy production -f /web1/deploy1.php |
| 147 | + |
| 148 | +# Check if another deployment was made |
| 149 | +test $($HN ls /data/web/apps/banaan1.store/releases/ | wc -l) = 3 |
| 150 | +$HN test $($HN readlink -f /data/web/nginx/banaan1.store) = /data/web/apps/banaan1.store/releases/3/.hypernode/nginx |
| 151 | +$HN test $($HN readlink -f /data/web/supervisor/banaan1.store) = /data/web/apps/banaan1.store/releases/3/.hypernode/supervisor |
| 152 | +$HN test $($HN readlink -f /data/web/varnish/banaan1.store/varnish.vcl) = /data/web/apps/banaan1.store/releases/3/.hypernode/varnish/varnish.vcl |
| 153 | + |
| 154 | +# Verify example location block is removed |
| 155 | +$HN test ! -f /data/web/nginx/banaan1.store/server.example.conf || ($HN ls -al /data/web/nginx/banaan1.store && exit 1) |
| 156 | + |
| 157 | +# Check if the second application is still working as intended |
| 158 | +test $($HN ls /data/web/apps/banaan2.store/releases/ | wc -l) = 1 |
| 159 | +$HN ls -al /data/web/nginx/banaan2.store/ |
| 160 | +$HN ls -al /data/web/apps/banaan2.store/current/ |
| 161 | +$HN ls -al /data/web/apps/banaan2.store/current/.hypernode/nginx/ |
| 162 | +$HN test -f /data/web/nginx/banaan2.store/server.example.conf || ($HN ls -al /data/web/nginx && $HN ls -al /data/web/nginx/banaan2.store && exit 1) |
| 163 | +$HN test $($HN readlink -f /data/web/nginx/banaan2.store) = /data/web/apps/banaan2.store/releases/1/.hypernode/nginx |
0 commit comments