Skip to content

Commit 33dfc80

Browse files
Merge pull request #51 from ByteInternet/v3
2 parents 8894771 + 8862a9d commit 33dfc80

21 files changed

+2237
-434
lines changed

.github/workflows/test.yaml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@ jobs:
77
strategy:
88
matrix:
99
php_version: [7.4, 8.1]
10+
testsuite: [general, ephemeral]
1011
runs-on: ubuntu-latest
1112
steps:
12-
- name: Checkout hypernode-deploy
13-
uses: actions/checkout@v3
14-
- name: Run test script
15-
run: MAGENTO_REPO=./magento2 ./runtests.sh
16-
shell: bash
17-
env:
18-
PHP_VERSION: ${{ matrix.php_version }}
13+
- name: Checkout hypernode-deploy
14+
uses: actions/checkout@v3
15+
- name: Run general testsuite
16+
if: ${{ matrix.testsuite == 'general' }}
17+
run: MAGENTO_REPO=./magento2 ./runtests.sh general
18+
shell: bash
19+
env:
20+
PHP_VERSION: ${{ matrix.php_version }}
21+
- name: Start SSH agent for ephemeral testsuite
22+
if: ${{ matrix.testsuite == 'ephemeral' && matrix.php_version == '8.1' }}
23+
uses: webfactory/[email protected]
24+
with:
25+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
26+
- name: Run ephemeral testsuite
27+
if: ${{ matrix.testsuite == 'ephemeral' && matrix.php_version == '8.1' }}
28+
run: ./runtests.sh ephemeral
29+
shell: bash
30+
env:
31+
PHP_VERSION: ${{ matrix.php_version }}
32+
HYPERNODE_API_TOKEN: ${{ secrets.HYPERNODE_API_TOKEN }}
33+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
1934
code_quality:
2035
strategy:
2136
matrix:

ci/build/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN apt-get update && \
3737
git \
3838
patch \
3939
bash \
40+
jq \
4041
ca-certificates \
4142
wget \
4243
curl \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDqf5tGbhjIbRQJ40bTvw69z0kUHQEeDtGkX5DTzXJ1IPHcFpbq+nxc3f++45V8FA3fq31xTjCR3+TWy/AGCVmuntVwJVCEaC/U3X0YDscmzAA4LEOfmMHIGnrJdeTJS4+N6L5uIlZqyBIeJXyEEgFpcHm4i1HGm13DR/XG7lTaXSkRI9IVb0i3S0VdrRjtqkg4M3ZjgNfAwmoDE3dGNwIBH5EVy8t/YNj/RH0TNdhTDL3AGwne6h2bTWb5SNLHNXvu2Wc5aiJlvn2E2W7mcpnPxEkVs1AeDEaPHcLaGE2+Bt/I4ntyjOy9pFDcf28sPKj76S3Sq0Wwdb8rYmT+lerIPfjwj1VPXTU1dhvDJ1ffTufp3Sn67qi7NfBMYayYxLJWh9q84RHgYhog2SNXM+autsTU40GDZUtDtORRZ+Rg5i1cGxUCRT+Fpcx3aFCM/yTLvU80qZkmfgkQwKnGCCFygDsXPuFbyRXRz9MI1+lYGg17ufW5HSHrAw34Rw2yd8k= hypernode-deploy-ci
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Hypernode\DeployConfiguration;
4+
5+
/**
6+
* Start by setting up the configuration
7+
*
8+
* The magento 2 configuration contains some default configuration for shared folders / files and running installers
9+
* @see ApplicationTemplate\Magento2::initializeDefaultConfiguration
10+
*/
11+
12+
$configuration = new ApplicationTemplate\Magento2(['en_US', 'nl_NL']);
13+
14+
$productionStage = $configuration->addStage('test', 'banaan.store');
15+
$productionStage->addEphemeralServer('hndeployintegr8');
16+
17+
return $configuration;

ci/test/run-ephemeral.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -x
5+
6+
# Handy aliases
7+
HN="ssh [email protected] -o StrictHostKeyChecking=no"
8+
DP="docker run --rm -v /tmp/m2build:/web -e HYPERNODE_API_TOKEN -e SSH_PRIVATE_KEY -w /web hndeploy"
9+
10+
# Build Docker image
11+
docker build \
12+
-f ci/build/Dockerfile \
13+
--build-arg NODE_VERSION=16 \
14+
--build-arg PHP_VERSION="${PHP_VERSION:-8.1}" \
15+
-t hndeploy \
16+
.
17+
18+
# Copy application from remote to local
19+
$HN /data/web/magento2/bin/magento app:config:dump scopes themes
20+
mkdir /tmp/m2build
21+
mkdir -p "$HOME/.ssh"
22+
cp ci/test/magento/deploy_ephemeral.php /tmp/m2build/deploy.php
23+
rsync -a -e "ssh -o StrictHostKeyChecking=no" [email protected]:magento2/ /tmp/m2build
24+
rm /tmp/m2build/app/etc/env.php
25+
26+
# Build application
27+
$DP hypernode-deploy build -f /web/deploy.php -vvv
28+
29+
##########################################
30+
# DEPLOY WITHOUT PLATFORM CONFIGURATIONS #
31+
# This should pass, but not generate any #
32+
# Nginx/Supervisor/etc configs #
33+
##########################################
34+
# SSH from deploy container to hypernode container
35+
$DP hypernode-deploy deploy test -f /web/deploy.php -vvv
36+
37+
# Run some tests
38+
39+
$DP ls -l
40+
$DP test -f deployment-report.json
41+
$DP jq . deployment-report.json
42+
$DP jq .version deployment-report.json -r
43+
$DP jq .stage deployment-report.json -r
44+
$DP jq .hostnames[0] deployment-report.json -r
45+
$DP jq .ephemeral_hypernodes[0] deployment-report.json -r
46+
47+
$DP hypernode-deploy cleanup -vvv

ci/test/run-general.sh

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"composer-runtime-api": "^2",
1414
"deployer/deployer": "dev-master#e374a8e as v7.0.0",
1515
"doctrine/annotations": "^1.6",
16-
"hypernode/deploy-configuration": "^2.0",
16+
"guzzlehttp/guzzle": "^7.5",
17+
"hypernode/api-client": "dev-master",
18+
"hypernode/deploy-configuration": "v3.x-dev",
1719
"php-di/php-di": "^6.0",
1820
"psr/log": "^1.0",
1921
"symfony/console": "^5.4",

0 commit comments

Comments
 (0)