Skip to content

Commit 0f090bd

Browse files
author
sd-lueckel
authored
Merge pull request #1 from solutionDrive/first-test-environment
Added a first draft of the sdTestEnvironmentShopware
2 parents 96e0df5 + a99badb commit 0f090bd

File tree

12 files changed

+1071
-2
lines changed

12 files changed

+1071
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Exclude files that are created during test runs
2+
/README.TESTING.md
3+
/etc/test/*

README.md

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# sdTestEnvironmentShopware
2-
Docker containers with php and defined extensions
1+
Docker based Shopware Testing Environment
2+
=========================================
3+
4+
For easier testing with different shopware- and/or php-versions we use a docker based environment.
5+
There are some docker containers providing MySQL, PHP and so on.
6+
The local filesystem is mapped into the containers that need them.
7+
8+
**NOTE on this README**
9+
This file assumes that bin-scripts are installed to ```vendor/bin``` (as composer does by default).
10+
If your changed this behaviour in your ```composer.json```
11+
you have to adjust the commands written in this file accordingly.
12+
13+
Installation
14+
------------
15+
16+
To use the testing environment in a project,
17+
add the following dependency to your project's composer.json's require-dev section:
18+
19+
"require-dev": {
20+
"solutiondrive/sd-test-environment-shopware": "*"
21+
}
22+
23+
Then do a `composer update` or use `composer require --dev` instead.
24+
25+
To initialize the testing environment simply run the following:
26+
27+
vendor/bin/sdTest.sh init
28+
29+
This will create some files:
30+
31+
/README.TESTING.md # This README.md in your project for other developers
32+
/etc/test/docker-compose.yml # A docker-compose file which can be modified for special needs
33+
34+
Usage / First steps
35+
-------------------
36+
37+
First you should start the testing docker containers (see also next section of this README):
38+
39+
vendor/bin/sdTest.sh start
40+
41+
Controlling the testing environment
42+
-----------------------------------
43+
44+
To start the containers and get back your local shell just run:
45+
46+
vendor/bin/sdTest.sh start
47+
48+
To stop the containers run:
49+
50+
vendor/bin/sdTest.sh stop
51+
52+
In stopped state the containers data is saved.
53+
54+
To destroy your containers you can run:
55+
56+
vendor/bin/sdTest.sh remove
57+
58+
To restart your containers without loosing data you can run:
59+
60+
vendor/bin/sdTest.sh restart
61+
62+
63+
Can can also run the containers in foreground to monitor the log output of the containers:
64+
65+
vendor/bin/sdTest.sh run
66+
67+
Then you can stop the execution by pressing CTRL+C. The containers will exit cleanly.
68+
69+
70+
If you started the container in background using ```start```, you can view the logs by running:
71+
72+
vendor/bin/sdTest.sh logs
73+
74+
You can follow the logs (as known from ```tail -f``` or ```tailf```):
75+
76+
vendor/bin/sdTest.sh logs -f
77+
78+
To connect to the mysql server use ```127.0.0.1``` as host with port (default: 10331) configured in ```etc/test/docker-compose.yml```.
79+
80+
81+
Less frequently needed
82+
----------------------
83+
84+
To force a rebuild of the containers you can run:
85+
86+
vendor/bin/sdTest.sh build --no-cache
87+
88+
To be sure that you have the latest version of the (base) containers you can force pulling newer images:
89+
90+
vendor/bin/sdTest.sh build --no-cache --pull
91+
92+
To destroy and restart your containers in one step without rebuilding images run:
93+
94+
vendor/bin/sdTest.sh reset
95+
96+
Executing a command in the testing environment
97+
----------------------------------------------
98+
99+
Commands (for example to clear the cache or to run the setup) can be executed inside the container.
100+
You must give a version to execute command on, for example 7.1 for PHP 7.1 container:
101+
102+
vendor/bin/runInSdTest.sh 71 ./app/install.sh
103+
104+
If you want to you can even get a shell inside the PHP container:
105+
106+
vendor/bin/runInSdTest.sh 71 /bin/bash

bin/runInSdTest.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
VERSION=$1
4+
5+
if [ -z "${VERSION}" ]; then
6+
echo "You must give a version to execute command on, for example 71 for PHP 7.1 container."
7+
exit 1
8+
fi
9+
10+
# directory of this script
11+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12+
13+
if [ -d ${DIR}/../vendor/solutiondrive/sd-test-environment-shopware ]; then
14+
PACKAGE_DIR="$( dirname "${DIR}" )"/vendor/solutiondrive/sd-test-environment-shopware
15+
elif [ -d ${DIR}/../solutiondrive/sd-test-environment-shopware ]; then
16+
PACKAGE_DIR="$( cd "$( dirname "${DIR}" )"/solutiondrive/sd-test-environment-shopware && pwd )"
17+
elif [ -d ${DIR}/../../../solutiondrive/sd-test-environment-shopware ]; then
18+
PACKAGE_DIR="$( dirname "${DIR}" )"
19+
fi
20+
21+
if [ ! -d ${PACKAGE_DIR} ]; then
22+
echo "Could not find package directory of sd-test-environment-shopware. Did you move the bin directory?"
23+
exit 1
24+
fi
25+
26+
PROJECT_DIR="$( dirname $( dirname $( dirname "${PACKAGE_DIR}") ) )"
27+
PROJECT_NAME="$( basename ${PROJECT_DIR} | tr '[:upper:]' '[:lower:]' )"
28+
# TODO: Think about a good solution for a different shopware version
29+
PHP_CONTAINER_NAME="${PROJECT_NAME}_shopware546_php${VERSION}_1"
30+
31+
docker exec --workdir ${WORKDIR:-"/var/www/project${VERSION}"} -it ${PHP_CONTAINER_NAME} $@
32+

bin/sdTest.sh

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/env bash
2+
3+
# directory of this script
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
if [ -d ${DIR}/../vendor/solutiondrive/sd-test-environment-shopware ]; then
7+
PACKAGE_DIR="$( dirname "${DIR}" )"/vendor/solutiondrive/sd-test-environment-shopware
8+
elif [ -d ${DIR}/../solutiondrive/sd-test-environment-shopware ]; then
9+
PACKAGE_DIR="$( cd "$( dirname "${DIR}" )"/solutiondrive/sd-test-environment-shopware && pwd )"
10+
elif [ -d ${DIR}/../../../solutiondrive/sd-test-environment-shopware ]; then
11+
PACKAGE_DIR="$( dirname "${DIR}" )"
12+
fi
13+
14+
if [ "$PACKAGE_DIR" == "" ]; then
15+
echo "Could not find package directory! For testing purposes we will use '.'"
16+
PACKAGE_DIR=.
17+
fi
18+
19+
if [ ! -d ${PACKAGE_DIR} ]; then
20+
echo "Could not find package directory of sd-test-environment-shopware. Did you move the bin directory?"
21+
exit 1
22+
fi
23+
24+
export PROJECT_DIR="$( dirname $( dirname $( dirname "${PACKAGE_DIR}") ) )"
25+
export PACKAGE_DIR="${PACKAGE_DIR}"
26+
export PROJECT_NAME="$( basename ${PROJECT_DIR} | tr '[:upper:]' '[:lower:]' )"
27+
export DOCKER_COMPOSE_YAML=${PROJECT_DIR}"/etc/test/docker-compose.yml"
28+
29+
if [ "$1" != "init" ]; then
30+
source ${PACKAGE_DIR}/etc/scripts/checkSdTestEnvironment.sh
31+
fi
32+
33+
34+
function prepare {
35+
if [ "$PROJECT_NAME" == "." ]; then
36+
echo "PROJECT_NAME cannot be '.' only. Setting it to 'testenvironmentshopware'"
37+
export PROJECT_NAME=testenvironmentshopware
38+
fi
39+
}
40+
41+
function echo_configuration {
42+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
43+
echo "Running (web)server on ports:"
44+
echo "PHP 7.2: 10872"
45+
echo "PHP 7.1: 10871"
46+
echo "PHP 7.0: 10870"
47+
echo "PHP 5.6: 10856"
48+
echo "MySQL: 10331"
49+
echo ""
50+
echo "PROJECT_DIR: ${PROJECT_DIR}"
51+
echo "PROJECT_NAME: ${PROJECT_NAME}"
52+
echo "PACKAGE_DIR: ${PACKAGE_DIR}"
53+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
54+
}
55+
56+
function init_environment {
57+
echo "Prepare directories"
58+
mkdir -p ${PROJECT_DIR}/etc/test
59+
mkdir -p ${PROJECT_DIR}/etc/test/nginx
60+
mkdir -p ${PROJECT_DIR}/etc/test/nginx/conf.d
61+
mkdir -p ${PROJECT_DIR}/etc/test/php
62+
63+
echo "Copying testing README"
64+
cp ${PACKAGE_DIR}/README.md ${PROJECT_DIR}/README.TESTING.md
65+
66+
echo "Copying docker-compose.yml to be able to easily modify it for special needs"
67+
cp ${PACKAGE_DIR}/docker-compose.yml ${PROJECT_DIR}/etc/test/docker-compose.yml
68+
69+
echo "Copying config files to be able to easily modify it for special needs"
70+
cp ${PACKAGE_DIR}/php/* ${PROJECT_DIR}/etc/test/php
71+
cp -R ${PACKAGE_DIR}/nginx/* ${PROJECT_DIR}/etc/test/nginx
72+
73+
echo "You can find additional information in the testing README, see 'README.TESTING.md'"
74+
}
75+
76+
function build_container {
77+
prepare
78+
docker_compose_cmd build $@
79+
}
80+
81+
function run_container {
82+
prepare
83+
echo_configuration
84+
docker_compose_cmd up $@
85+
}
86+
87+
function start_container {
88+
prepare
89+
echo_configuration
90+
docker_compose_cmd up --no-start $@
91+
docker_compose_cmd start $@
92+
}
93+
94+
function stop_container {
95+
docker_compose_cmd stop $@
96+
}
97+
98+
function restart_container {
99+
stop_container $@
100+
start_container $@
101+
}
102+
103+
104+
function remove_container {
105+
docker_compose_cmd down -v
106+
docker_compose_cmd rm -v $@
107+
}
108+
109+
function get_logs {
110+
docker_compose_cmd logs $@
111+
}
112+
113+
function reset_container {
114+
remove_container -s -f $@
115+
start_container $@
116+
}
117+
118+
function docker_compose_cmd {
119+
docker-compose \
120+
-f ${DOCKER_COMPOSE_YAML} \
121+
-p ${PROJECT_NAME} \
122+
$@
123+
}
124+
125+
126+
## start of the real program
127+
128+
export PROJECT_DIR
129+
export PROJECT_NAME
130+
131+
case "$1" in
132+
init)
133+
shift
134+
init_environment $@
135+
;;
136+
build)
137+
shift
138+
build_container $@
139+
;;
140+
run)
141+
shift
142+
run_container $@
143+
;;
144+
start)
145+
shift
146+
start_container $@
147+
;;
148+
stop)
149+
shift
150+
stop_container $@
151+
;;
152+
restart)
153+
shift
154+
restart_container $@
155+
;;
156+
reset)
157+
shift
158+
reset_container $@
159+
;;
160+
remove|rm)
161+
shift
162+
remove_container $@
163+
;;
164+
log|logs)
165+
shift
166+
get_logs $@
167+
;;
168+
*)
169+
echo "usage: init/start/stop/run/restart/build/reset/remove/logs"
170+
;;
171+
esac

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "solutiondrive/sd-test-environment-shopware",
3+
"description": "Docker based testing environment for shopware projects.",
4+
"keywords": ["testing", "docker"],
5+
"homepage": "https://solutiondrive.de",
6+
"type": "library",
7+
"license": [
8+
"proprietary"
9+
],
10+
"bin": [
11+
"bin/sdTest.sh",
12+
"bin/runInSdTest.sh"
13+
]
14+
}

0 commit comments

Comments
 (0)