Skip to content
This repository was archived by the owner on Mar 15, 2019. It is now read-only.

Commit ee6d057

Browse files
author
Julien Neuhart
committed
refactoring scripts
1 parent eea2772 commit ee6d057

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+363
-202
lines changed

.env.template

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
## CONTAINER NAME PATTERN: ^[a-zA-Z0-9._-]+$
33
## NETWORK PATTERN: ^[a-zA-Z0-9._-]+$
44

5-
# common
5+
# [common]
66
PROJECT_NAME=yourproject
77
ENV=dev
88

9-
# apache
9+
# [apache]
1010
APACHE_SERVICE_NAME=apache
1111
APACHE_CONTAINER_NAME=${PROJECT_NAME}_${APACHE_SERVICE_NAME}_${ENV}
1212
APACHE_VIRTUAL_HOST=dev.yourproject.com
1313
APACHE_ENABLE_XDEBUG=1
1414

15-
# mysql
15+
# [mysql]
1616
MYSQL_SERVICE_NAME=mysql
1717
MYSQL_CONTAINER_NAME=${PROJECT_NAME}_${MYSQL_SERVICE_NAME}_${ENV}
1818
MYSQL_ROOT_PASSWORD=admin
1919
MYSQL_DATABASE=database_name
2020
MYSQL_HOST_PORT_TO_MAP=3307
21-
MYSQL_ENABLE_PORTS_MAPPING=1
21+
MYSQL_ENABLE_PORTS_MAPPING=0
2222

23-
# nginx
24-
NGINX_SERVICE_NAME=nginx
25-
NGINX_PROXY_NAME=nginx
26-
NGINX_CONTAINER_NAME=${NGINX_PROXY_NAME}_proxy
27-
NGINX_CERTS_PATH=/the/path/to/certs
28-
NGINX_ENABLE_SSL=0
23+
# [reverse-proxy]
24+
REVERSE_PROXY_SERVICE_NAME=nginx
25+
REVERSE_PROXY_NAME=nginx
26+
REVERSE_PROXY_CONTAINER_NAME=${REVERSE_PROXY_NAME}_reverse_proxy
27+
REVERSE_PROXY_CERTS_PATH=/the/path/to/certs
28+
REVERSE_PROXY_ENABLE_SSL=0
2929

30-
# networks
30+
# [networks]
3131
BASE_NETWORK=scope_${ENV}
32-
PROXY_NETWORK=scope_proxy
32+
REVERSE_PROXY_NETWORK=scope_reverse_proxy

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
/mysql/volume
88
.env
99
docker-compose.yml
10-
docker-compose-nginx.yml
10+
docker-compose-reverse-proxy.yml

Makefile

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,57 @@ include ./.env
77
# BUILDING
88
#------------------------------------------------------
99
prepare:
10-
./bin/_prepare;
11-
./bin/_whalesay --say "Your docker-compose files are ready!";
10+
./_bin/_prepare;
1211

1312
build:
14-
docker-compose -f docker-compose.yml build;
15-
./bin/_whalesay --say "Apache container (${APACHE_CONTAINER_NAME}) has been built!";
13+
./_bin/_build;
1614

1715
down:
18-
./bin/_down;
19-
./bin/_whalesay --say "Apache (${APACHE_CONTAINER_NAME}) and MySQL (${MYSQL_CONTAINER_NAME}) containers have been stopped!";
16+
./_bin/_down;
2017

2118
up:
22-
docker-compose -f docker-compose.yml up -d;
23-
./bin/_whalesay --say "Apache (${APACHE_CONTAINER_NAME}) and MySQL (${MYSQL_CONTAINER_NAME}) containers are running!";
19+
./_bin/_up;
2420

25-
nginx-down:
26-
docker-compose -p ${NGINX_PROXY_NAME} -f docker-compose-nginx.yml down;
27-
./bin/_whalesay --say "NGINX (${NGINX_CONTAINER_NAME}) container has been stopped!";
21+
proxy-down:
22+
./_bin/_reverse_proxy_down;
2823

29-
nginx-up:
30-
./bin/_nginx_up;
31-
./bin/_whalesay --say "NGINX (${NGINX_CONTAINER_NAME}) container is running!";
24+
proxy-up:
25+
./_bin/_reverse_proxy_up;
3226

33-
kickoff: down prepare build nginx-up up;
34-
./bin/_whalesay --say "You're ready to go!";
27+
kickoff:
28+
./_bin/_kickoff;
3529

3630
# UTILS
3731
#------------------------------------------------------
3832
shell:
39-
./bin/_shell --container_name ${APACHE_CONTAINER_NAME} --service_name "Apache";
33+
./_bin/_shell --container_name ${APACHE_CONTAINER_NAME} --service_name "Apache";
4034

41-
shell-nginx:
42-
./bin/_shell --container_name ${NGINX_CONTAINER_NAME} --service_name "NGINX";
35+
shell-proxy:
36+
./_bin/_shell --container_name ${REVERSE_PROXY_CONTAINER_NAME} --service_name "Reverse proxy";
4337

4438
shell-mysql:
45-
./bin/_shell --container_name ${MYSQL_CONTAINER_NAME} --service_name "MySQL";
39+
./_bin/_shell --container_name ${MYSQL_CONTAINER_NAME} --service_name "MySQL";
4640

4741
mysql-cli:
48-
./bin/_mysql_cli;
42+
./_bin/_mysql_cli;
4943

5044
tail:
51-
./bin/_tail --container_name ${APACHE_CONTAINER_NAME} --service_name "Apache";
45+
./_bin/_tail --container_name ${APACHE_CONTAINER_NAME} --service_name "Apache";
5246

53-
tail-nginx:
54-
./bin/_tail --container_name ${NGINX_CONTAINER_NAME} --service_name "NGINX";
47+
tail-proxy:
48+
./_bin/_tail --container_name ${REVERSE_PROXY_CONTAINER_NAME} --service_name "Reverse proxy";
5549

5650
tail-mysql:
57-
./bin/_tail --container_name ${MYSQL_CONTAINER_NAME} --service_name "MySQL";
51+
./_bin/_tail --container_name ${MYSQL_CONTAINER_NAME} --service_name "MySQL";
5852

5953
export:
60-
./bin/_export;
54+
./_bin/_export;
6155

6256
import:
63-
./bin/_import;
57+
./_bin/_import;
6458

6559
composer:
66-
./bin/_composer --command $(cmd);
60+
./_bin/_composer --command $(cmd);
6761

6862
npm:
69-
./bin/_npm --command $(cmd);
63+
./_bin/_npm --command $(cmd);

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,23 @@ Once everything has been installed, open your favorite web browser and copy / pa
6565

6666
| Command | Description |
6767
| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
68-
| prepare | Creates the `docker-compose.yml` and `docker-compose-nginx.yml` files using the variables's values specified in the `.env` file. |
68+
| prepare | Creates the `docker-compose.yml` and `docker-compose-reverse-proxy.yml` files using the variables's values specified in the `.env` file. |
6969
| build | Builds the Apache container. |
7070
| down | Stops the Apache and MySQL containers, deletes their network and cleans the docker cache. |
7171
| up | Ups the Apache and MySQL containers. |
72-
| nginx-down | Stops the NGINX container and deletes its network. |
73-
| nginx-up | Ups the NGINX container. |
74-
| kickoff | Combo of down, prepare, build, nginx-up and up commands. |
72+
| proxy-down | Stops the reverse proxy container and deletes its network. |
73+
| proxy-up | Ups the reverse proxy container. |
74+
| kickoff | Combo of down, prepare, build, proxy-up and up commands. |
7575
| composer cmd=*yourcommand* | Allows you to run a composer command. Ex: `make composer cmd=install`, `make composer cmd=update`, ... |
7676
| npm cmd=*yourcommand* | Allows you to run a npm command. Ex: `make npm cmd=install`, `make npm cmd="install --save-dev gulp"`, ... |
7777
| export | This command will dump the database into two SQL files located at `mysql/dumps`. The files will be named as `yourdatabasename.sql` and `yourdatabasename.Y-m-d:H:M:S.sql`. |
7878
| import | This command will drop the database, recreate it and then run the `yourdatabasename.sql` file. |
7979
| shell | Connects through bash to the Apache container. |
80-
| shell-nginx | Connects through bash to the NGINX container. |
80+
| shell-proxy | Connects through bash to the reverse proxy container. |
8181
| shell-mysql | Connects through bash to the MySQL container. |
8282
| mysql-cli | Opens the MySQL cli. |
8383
| tail | Displays the Docker's logs of the Apache container. |
84-
| tail-nginx | Displays the Docker's logs of the NGINX container. |
84+
| tail-proxy | Displays the Docker's logs of the reverse proxy container. |
8585
| tail-mysql | Displays the Docker's logs of the MySQL container. |
8686

8787
## Dive in
@@ -92,12 +92,12 @@ There are three important files:
9292

9393
* `.env.template` which contains variables with default values.
9494
* `docker-compose.yml.template` which contains the run configuration of the Apache and MySQL containers plus some of the variables defined in `.env.template`.
95-
* `docker-compose-nginx.yml.template` which contains the run configuration of the NGINX container plus some of the variables defined in `.env.template`.
95+
* `docker-compose-reverse-proxy.yml.template` which contains the run configuration of the reverse proxy container plus some of the variables defined in `.env.template`.
9696

9797
As these files are templates, they are not used directly. That's why you have to:
9898

9999
* run `cp .env.template .env` and update the variables' values in the `.env` file at your convenience.
100-
* run `make kickoff` which runs `make prepare`: this command creates the `docker-compose.yml` and `docker-compose-nginx.yml` files using the variables' values defined in the `.env` file.
100+
* run `make kickoff` which runs `make prepare`: this command creates the `docker-compose.yml` and `docker-compose-reverse-proxy.yml` files using the variables' values defined in the `.env` file.
101101

102102
For security concern, these three files have been added in the `.gitignore` file as they contain sensible data like the MySQL database password and so on.
103103

@@ -146,13 +146,13 @@ If you're using SSL Certificate Chains, we advise you to read the official NGINX
146146

147147
### Multiple environments/projects on the same host
148148

149-
As you long as each `NGINX_PROXY_NAME` and `PROXY_NETWORK` variables in your `.env` files have the same values, you are able to run as many environments/projects as you need.
149+
As you long as each `REVERSE_PROXY_NAME` and `REVERSE_PROXY_NETWORK` variables in your `.env` files have the same values, you are able to run as many environments/projects as you need.
150150

151151
Make sure that you have defined a different `APACHE_VIRTUAL_HOST` value for each of your Apache containers.
152152

153153
### Install more PHP extensions
154154

155-
Open the `Dockerfile` located in the `apache/volume` folder and [follow the official instructions](https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions).
155+
Open the `Dockerfile` located in the `apache` folder and [follow the official instructions](https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions).
156156

157157
Once done, run `make kickoff` to rebuild your Apache container.
158158

_bin/_build

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
4+
ROOT=${DIR}/..;
5+
6+
# environment variables
7+
source ${ROOT}/.env;
8+
9+
build()
10+
{
11+
if [ -f ${ROOT}/docker-compose.yml ]; then
12+
if docker-compose -f ${ROOT}/docker-compose.yml build; then
13+
/bin/bash ${DIR}/misc/_whalesay --say "Apache container (${APACHE_CONTAINER_NAME}) has been built!";
14+
else
15+
/bin/bash ${DIR}/misc/_whalesay --say "Failed to build the Apache container (${APACHE_CONTAINER_NAME}).";
16+
exit 1;
17+
fi;
18+
else
19+
/bin/bash ${DIR}/misc/_whalesay --say "No docker-compose.yml found. Did you run make prepare?";
20+
exit 1;
21+
fi;
22+
}
23+
24+
25+
build;
26+
27+
exit 0;

bin/_composer renamed to _bin/_composer

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ missing_arg()
2121

2222
composer()
2323
{
24-
/bin/bash ${DIR}/_health_check --container_name ${APACHE_CONTAINER_NAME};
24+
/bin/bash ${DIR}/utils/_health_check --container_name ${APACHE_CONTAINER_NAME};
2525

2626
if [ $? -eq 1 ]; then
27-
/bin/bash ${DIR}/_whalesay --say "Apache container (${APACHE_CONTAINER_NAME}) is not running.";
27+
/bin/bash ${DIR}/misc/_whalesay --say "Apache container (${APACHE_CONTAINER_NAME}) is not running.";
2828
exit 1;
2929
fi;
3030

_bin/_down

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
4+
ROOT=${DIR}/..;
5+
6+
# environment variables
7+
source ${ROOT}/.env;
8+
9+
down()
10+
{
11+
if [ -f ${ROOT}/docker-compose.yml ]; then
12+
if docker-compose -f ${ROOT}/docker-compose.yml down; then
13+
/bin/bash ${DIR}/misc/_whalesay --say "Apache (${APACHE_CONTAINER_NAME}) and MySQL (${MYSQL_CONTAINER_NAME}) containers have been stopped!";
14+
else
15+
/bin/bash ${DIR}/misc/_whalesay --say "Failed to stop the Apache (${APACHE_CONTAINER_NAME}) and MySQL (${MYSQL_CONTAINER_NAME}) containers.";
16+
fi;
17+
fi;
18+
}
19+
20+
cache()
21+
{
22+
docker rm $(docker ps -q -f status=exited) >/dev/null;
23+
docker rmi $(docker images -q -f dangling=true) >/dev/null
24+
docker volume rm $(docker volume ls -qf dangling=true) >/dev/null;
25+
}
26+
27+
down;
28+
cache;
29+
30+
exit 0;

bin/_export renamed to _bin/_export

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ source ${ROOT}/.env;
88

99
exportDatabase()
1010
{
11-
/bin/bash ${DIR}/_health_check --container_name ${MYSQL_CONTAINER_NAME};
11+
/bin/bash ${DIR}/utils/_health_check --container_name ${MYSQL_CONTAINER_NAME};
1212

1313
if [ $? -eq 1 ]; then
14-
/bin/bash ${DIR}/_whalesay --say "MySQL container (${MYSQL_CONTAINER_NAME}) is not running.";
14+
/bin/bash ${DIR}/misc/_whalesay --say "MySQL container (${MYSQL_CONTAINER_NAME}) is not running.";
1515
exit 1;
1616
fi;
1717

@@ -22,7 +22,7 @@ exportDatabase()
2222
docker exec ${MYSQL_CONTAINER_NAME} mysqldump --opt -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} > ${ROOT}/mysql/dumps/${MYSQL_DATABASE}.sql;
2323
cp ${ROOT}/mysql/dumps/${MYSQL_DATABASE}.sql ${ROOT}/mysql/dumps/${MYSQL_DATABASE}.$(date +%Y-%m-%d:%H:%M:%S).sql;
2424

25-
/bin/bash ${DIR}/_whalesay --say "Export task complete!";
25+
/bin/bash ${DIR}/misc/_whalesay --say "Export task complete!";
2626
}
2727

2828
exportDatabase;

bin/_import renamed to _bin/_import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ source ${ROOT}/.env;
88

99
importDatabase()
1010
{
11-
/bin/bash ${DIR}/_health_check --container_name ${MYSQL_CONTAINER_NAME};
11+
/bin/bash ${DIR}/utils/_health_check --container_name ${MYSQL_CONTAINER_NAME};
1212

1313
if [ $? -eq 1 ]; then
14-
/bin/bash ${DIR}/_whalesay --say "MySQL container (${MYSQL_CONTAINER_NAME}) is not running.";
14+
/bin/bash ${DIR}/misc/_whalesay --say "MySQL container (${MYSQL_CONTAINER_NAME}) is not running.";
1515
exit 1;
1616
fi;
1717

@@ -21,7 +21,7 @@ importDatabase()
2121

2222
cat ${ROOT}/mysql/dumps/${MYSQL_DATABASE}.sql | docker exec -i ${MYSQL_CONTAINER_NAME} mysql --verbose -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE};
2323

24-
/bin/bash ${DIR}/_whalesay --say "Import task complete!";
24+
/bin/bash ${DIR}/misc/_whalesay --say "Import task complete!";
2525
}
2626

2727
importDatabase;

_bin/_kickoff

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
4+
ROOT=${DIR}/..;
5+
6+
kickoff()
7+
{
8+
/bin/bash ${DIR}/_down;
9+
10+
if ! /bin/bash ${DIR}/_prepare; then
11+
exit 1;
12+
fi;
13+
14+
if ! /bin/bash ${DIR}/_build; then
15+
exit 1;
16+
fi;
17+
18+
if ! /bin/bash ${DIR}/_reverse_proxy_up; then
19+
exit 1;
20+
fi;
21+
22+
if ! /bin/bash ${DIR}/_up; then
23+
exit 1;
24+
fi;
25+
26+
/bin/bash ${DIR}/misc/_whalesay --say "You're ready to go!";
27+
}
28+
29+
30+
kickoff;
31+
32+
exit 0;

0 commit comments

Comments
 (0)