-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.bash
executable file
·241 lines (207 loc) · 7.81 KB
/
docker-compose.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
# Debug: Stop on Error
#set -e;
# Debug: Display Command Line
#set -x;
# In-Place sed Command
function sedi() {
if [ 'Darwin' = `uname` ]; then
# Mac OS X
sed -i '' -e "$1" $2;
else
sed -i -e $*;
fi;
}
# Docker/eZ: Parse Containers Options
## Default Options Values
cache='redis';
search='solr';
session='redis';
dynamic_session=0;
## Options Parsing
while [[ $# -gt 0 ]]; do
case "$1"
in
-h)
echo "Usage:";
echo "$0 [-c <filesystem|redis|memcached>] [-s <legacy|solr|elasticsearch|fallback>] [-u <filesystem|redis|memcached>] [-d]";
echo "-c|--cache: Cache Pool (default: redis)";
echo "-s|--search: Search Engine (default: solr)";
echo "-u|--session: PHP User Sessions (default: redis); Not yet implemented";
echo "-d|--dynamic-session: Dynamic Session Handler (default: false); Not yet implemented";
exit;
;;
-c|--cache)
cache="$2";
shift; shift;
;;
-s|--search)
search="$2";
shift; shift;
;;
-u|--session)
echo "Session Handler: Not yet implemented";
#session="$2";
shift; shift;
;;
-d|--dynamic-session)
echo "Dynamic Session Handler: Not yet implemented";
#dynamic_session=1;
shift;
;;
esac
done
## Options Interpretation
case "$cache"
in
'filesystem')
CACHE_POOL=cache.tagaware.filesystem;
CACHE_DSN=localhost;
cache_container='';
;;
'redis')
CACHE_POOL=cache.redis;
CACHE_DSN=redis;
cache_container='redis';
;;
'memcached')
CACHE_POOL=cache.memcached;
CACHE_DSN=memcached;
cache_container='memcached';
;;
esac
case "$search"
in
'legacy')
SEARCH_ENGINE=legacy;
search_container='';
;;
'solr')
SEARCH_ENGINE=solr;
search_container='solr';
;;
'elasticsearch')
SEARCH_ENGINE=elasticsearch;
search_container='elasticsearch';
;;
'fallback')
SEARCH_ENGINE=fallback;
search_container='solr elasticsearch';
;;
esac
case "$session"
in
'filesystem')
SESSION_HANDLER_ID=session.handler.native_file
SESSION_SAVE_PATH=%kernel.project_dir%/var/sessions/%kernel.environment%
session_container='';
;;
'redis')
SESSION_HANDLER_ID=ezplatform.core.session.handler.native_redis
SESSION_SAVE_PATH=tcp://redis:6379
session_container='redis';
;;
'memcached')
SESSION_HANDLER_ID=ad.session.handler.native_memcached
SESSION_SAVE_PATH=memcached:11211
session_container='memcached';
;;
esac
# Git: Untracked Files Removal
#git clean -df; # Help to switch between eZ Platform v2 and v3
# Apache: Composer Authentication
if [ ! -f auth.json ]; then
echo -n "eZ Platform Enterprise Edition Installation Key: "; read INSTALLATION_KEY;
echo -n "eZ Platform Enterprise Edition Token Password: "; read TOKEN_PASSWORD;
composer config http-basic.updates.ez.no ${INSTALLATION_KEY} ${TOKEN_PASSWORD};
composer config http-basic.updates.ibexa.co ${INSTALLATION_KEY} ${TOKEN_PASSWORD};
fi;
# Symfony/eZ/Composer: Install dependencies
composer config platform.php 7.3;
composer update --lock --no-install --no-scripts;
composer install --no-interaction --no-scripts;
# Solr: Copy config to build folder
cp -r ./vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr ./docker/solr/conf;
# Varnish: Copy config to build folder
sed 's/X-Forwarded-Port = "80"/X-Forwarded-Port = "8080"/' ./vendor/ezsystems/ezplatform-http-cache/docs/varnish/vcl/varnish5.vcl > ./docker/varnish/default.vcl;
## Fix "Cannot read file 'parameters.vcl' (No such file or directory)"
sedi 's/include "parameters.vcl";/#include "parameters.vcl";/' ./docker/varnish/default.vcl && sedi '/include "parameters.vcl";/ r ./docker/varnish/parameters.vcl' ./docker/varnish/default.vcl;
# Symfony: Logs Removal
rm -rf var/log/*.log;
touch var/log/dev.log;
# Symfony: Cache Removal
rm -rf var/cache/dev/;
mkdir -p var/cache/dev;
# Symfony: Remove bin/ symlinks
find bin/ -type l -exec unlink {} \; ; # Remove bin/ symlinks
# Encore: Remove generated config files
rm -f var/encore/*config*.js;
# Docker/eZ: Set Environment
if [[ ! -f .env.local ]]; then
cp -v .env.local.template .env.local;
fi
sedi "s/CACHE_POOL=.*/CACHE_POOL=$CACHE_POOL/" .env.local;
sedi "s/CACHE_DSN=.*/CACHE_DSN=$CACHE_DSN/" .env.local;
sedi "s/SEARCH_ENGINE=.*/SEARCH_ENGINE=$SEARCH_ENGINE/" .env.local;
if [[ 0 == $dynamic_session ]]; then
echo "Session Handler set in PHP";
sedi "s/^SESSION_HANDLER_ID=.*/#SESSION_HANDLER_ID=/" .env;
sedi "s/^SESSION_HANDLER_ID=.*/#SESSION_HANDLER_ID=/" .env.local;
sedi "s/#ezplatform.session.handler_id:/ezplatform.session.handler_id:/" config/packages/ezplatform.yaml;
sedi "s/ezplatform.session.handler_id: .*/ezplatform.session.handler_id: ~/" config/packages/ezplatform.yaml;
# TODO: PHP-FPM
elif [[ 1 == $dynamic_session ]]; then
echo "Session Handler set dynamically";
sedi "s/^#SESSION_HANDLER_ID=/SESSION_HANDLER_ID=/" .env.local;
sedi "s/^SESSION_HANDLER_ID=.*/SESSION_HANDLER_ID=$SESSION_HANDLER_ID/" .env.local;
sedi "s/^SESSION_SAVE_PATH=.*/SESSION_SAVE_PATH=$SESSION_SAVE_PATH/" .env.local;
sedi "s/ezplatform.session.save_path: .*/ezplatform.session.save_path: '$SESSION_SAVE_PATH'/" config/packages/ezplatform.yaml;
fi
# Docker: docker-compose settings
sedi "s/^COMPOSE_FILE=/#COMPOSE_FILE=/" .env;
sedi "s/^COMPOSE_PROJECT_NAME=/#COMPOSE_PROJECT_NAME=/" .env;
# Docker: Containers Cluster Build
available_containers='varnish apache mariadb redis memcached solr elasticsearch';
enabled_containers="varnish apache mariadb $cache_container $search_container $session_container";
available_containers=`echo "$available_containers" | xargs -n1 | sort -u | xargs`;
enabled_containers=`echo "$enabled_containers" | xargs -n1 | sort -u | xargs`;
disabled_containers=`comm -13 <(echo "$enabled_containers" | tr ' ' "\n") <(echo "$available_containers" | tr ' ' "\n") | tr "\n" ' '`;
if [[ -n "$disabled_containers" ]]; then
docker-compose stop $disabled_containers;
fi
docker-compose up --build --detach $enabled_containers;
# Solr: Clean-up build folder
rm -rf ./docker/solr/conf;
# Varnish: Clean-up build folder
rm -f ./docker/varnish/default.vcl;
# Apache: Add write rights to var folders
docker-compose exec apache chown www-data -R var/ public/var/;
docker-compose exec apache chmod g+w -R var/ public/var/;
# MariaDB: Server Wait & Version Fetch
GET_MARIADB_VERSION_CMD="docker-compose exec -T mariadb mysql -proot -BNe 'SELECT VERSION();' | cut -d '-' -f 1 | head -n 1;";
MARIADB_VERSION=`eval $GET_MARIADB_VERSION_CMD`;
while [ -n "`echo $MARIADB_VERSION | grep 'ERROR';`" ] || [ -z "$MARIADB_VERSION" ]; do
echo 'Waiting for server inside mariadb container...';
sleep 3;
MARIADB_VERSION=`eval $GET_MARIADB_VERSION_CMD`;
done;
echo "MariaDB version: $MARIADB_VERSION";
# Apache: Doctrine Configuration
sedi "s/DATABASE_VERSION=.*/DATABASE_VERSION=mariadb-$MARIADB_VERSION/" .env.local;
# Elasticsearch: Index Template
if [[ 'elasticsearch' == "$search" ]]; then
docker-compose exec apache bin/console ezplatform:elasticsearch:put-index-template --overwrite;
fi
# Apache: Composer Scripts' Timeout
docker-compose exec --user www-data apache composer config --global process-timeout 0;
# Content: eZ Platform Reset
docker-compose exec mariadb mysql -proot -e "DROP DATABASE IF EXISTS ezplatform;";
docker-compose exec --user www-data apache rm -rf public/var/*; # Clean storages (public/var/*/storage/) as the DB is reset.
git clean -dxf config/graphql; # Clean GraphQL schema (config/graphql/types/) as the DB is reset.
docker-compose exec redis redis-cli FLUSHALL;
# Apache: eZ Platform Install
docker-compose exec --user www-data apache composer install;
docker-compose exec --user www-data apache php bin/console ibexa:install ibexa-experience;
docker-compose exec --user www-data apache php bin/console ibexa:graphql:generate-schema;
# Logs Follow-up
#docker-compose logs --follow;