-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocesses
More file actions
305 lines (255 loc) · 9.4 KB
/
processes
File metadata and controls
305 lines (255 loc) · 9.4 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Include common processes
source $(_decompose-project-root)/.decompose/environment/lib/web/processes
source $(_decompose-project-root)/.decompose/environment/lib/common/processes
source $(_decompose-project-root)/.decompose/environment/lib/backup/processes
source $(_decompose-project-root)/.decompose/environment/lib/docker/processes
# Declare processes
DECOMPOSE_PROCESSES+=( 'build' 'up' 'import_db' 'explore_db' 'import_files'
'tail-dev-email' 'drush' 'backup-db' 'explore-php-container'
'export_db' 'export_files' 'check_drupal' 'cron' 'update-composer-lock'
"${DECOMPOSE_WEB_PROCESSES[@]}" "${DECOMPOSE_COMMON_PROCESSES[@]}"
"${DECOMPOSE_BACKUP_PROCESSES[@]}" "${DECOMPOSE_DOCKER_PROCESSES[@]}" )
_decompose-process-update-composer-lock() {
echo "Updating composer.lock..."
# Run 'composer update' command
cid=$(docker-compose run -d \
source bash -c "cd /app/build/docker_build_context/source && composer update")
docker wait "$cid"
docker logs "$cid"
# Copy 'composer.lock' out of container
docker cp "$cid:/app/build/docker_build_context/source/composer.lock" \
"$(_decompose-project-root)/containers/source/source"
# Remove container
docker rm "$cid"
}
_decompose-process-update-composer-lock_help() {
echo " Update composer.lock"
}
_decompose-process-explore_db() {
# Get the name of the database container
local cid=$(docker-compose ps -q db)
# Enter mysql
local password_param=""
if [ "$PROJECT_DB_PASSWORD" ]; then
local password_param="-p$PROJECT_DB_PASSWORD"
fi
docker exec -it $cid bash -c "mysql -u $PROJECT_DB_USER $password_param -D $PROJECT_DB_DATABASE"
}
_decompose-process-explore_db_help() {
echo " Explore database"
}
_decompose-process-explore-php-container() {
# Get container id
local cid=$(docker-compose ps -q php)
# Enter php
docker exec -u hostuser -it $cid bash
}
_decompose-process-explore-php-container_help() {
echo " Explore the php container"
}
_decompose-process-backup-db() {
# Get the name of the database container
local cid=$(docker-compose ps -q backup)
# Run backup
docker exec $cid duply site_data backup
}
_decompose-process-backup-db_help() {
echo " Manually start backup process"
}
_decompose-process-tail-dev-email() {
# Get the name of the php container
local db_container_name=$(docker-compose ps -q php)
# Tail mail.out
docker exec -it $db_container_name bash -c "tail -f /tmp/mail.out"
}
_decompose-process-tail-dev-email_help() {
echo " Tail the dev email messages being sent"
}
_decompose-process-build() {
local return_code=0
_decompose-process-common-build
return_code=$((return_code + $?))
_decompose-process_nginx_proxy_build
return_code=$((return_code + $?))
_decompose-process-build_version_file
return_code=$((return_code + $?))
_decompose-process-docker-build
return_code=$((return_code + $?))
# If there was an error, then just return now before creating release
if [ $return_code -ne 0 ]; then
echo "Return code of '$return_code' detected. Returning."
return $return_code
fi
if [ "$PRODUCTION" = "true" ]; then
echo "Making permissions on build, config and release volumes 777 ..."
docker-compose run -u root --rm source bash -c "chmod 777 ${PROJECT_BUILD_PATH}/build && \
chmod 777 ${PROJECT_RELEASES_PATH} && mkdir -p ${PROJECT_BUILD_PATH}/build/config && \
chmod 777 ${PROJECT_BUILD_PATH}/build/config"
return_code=$((return_code + $?))
fi
echo "Making composer cache writable..."
docker-compose run -u root --rm source bash -c "chmod 777 /home/hostuser/.composer"
return_code=$((return_code + $?))
echo "Running update_source.bash ..."
docker-compose run --rm source ${PROJECT_BUILD_PATH}/docker_build_context/update_source.bash
return_code=$((return_code + $?))
# Add custom build steps to your processes file in the function:
# _decompose-process-custom-build-steps
if [ -n "$(type -t _decompose-process-custom-build-steps)" ] &&
[ "$(type -t _decompose-process-custom-build-steps)" = function ]; then
echo "Running custom build steps ..."
_decompose-process-custom-build-steps
return_code=$((return_code + $?))
fi
echo "Running create_release.bash ..."
docker-compose run -u root --rm source ${PROJECT_BUILD_PATH}/docker_build_context/create_release.bash
return_code=$((return_code + $?))
echo "Making 'files' volume writable ..."
docker-compose run --rm files sh -c "chmod 777 /app/files/*"
return_code=$((return_code + $?))
return $return_code
}
_decompose-process-build_help() {
echo " Build the project"
}
_decompose-process-up() {
# Set current release to latest
docker-compose run --rm -u root source ${PROJECT_BUILD_PATH}/docker_build_context/set_current_release.bash
_decompose-process-docker-up
_decompose-process_nginx_proxy_up
# Clean up old releases
docker-compose run --rm -u root source ${PROJECT_BUILD_PATH}/docker_build_context/cleanup_releases.bash
}
_decompose-process-up_help() {
echo " Start project locally"
}
_decompose-process-drush() {
# Get the name of the php container
local cid=$(docker-compose ps -q php)
docker exec -u hostuser -it $cid drush "$@"
}
_decompose-process-drush_help() {
echo " Run drush with parameters"
}
_decompose-process-import_db() {
# Verify the the first parameter is a file
local sql_file=$1
if [ ! -e "$sql_file" ]; then
echo "File '$sql_file' does not exist"
exit 1
fi
# Get the name of the database container
local cid=$(docker-compose ps -q php)
# Copy file to container /tmp
docker cp $sql_file $cid:/tmp
# Import file
docker exec $cid bash -c "drush sql-drop -y && gzip -d < /tmp/${sql_file##*/} | drush sqlc"
# Delete /tmp file
docker exec $cid rm /tmp/${sql_file##*/}
}
_decompose-process-import_db_help() {
echo " Import DB passed in as a parameter 1"
echo " Warning: This will drop current database."
}
_decompose-process-export_db() {
# Verify the the first parameter is a file
local filename="$1"
if [ -z "$filename" ]; then
echo "Please specify name of export"
exit 1
fi
# Get the name of the database container
local cid=$(docker-compose ps -q php)
# Export file
docker exec $cid bash -c "drush sql-dump --gzip > /tmp/${filename##*/}.sql.gz"
# Copy file to container /tmp
docker cp $cid:/tmp/${filename##*/}.sql.gz $filename.sql.gz
# Delete /tmp file
docker exec $cid rm /tmp/${filename##*/}.sql.gz
}
_decompose-process-export_db_help() {
echo " Export DB to the specified filename"
echo " Export will append '.sql.gz' to filename."
}
_decompose-process-export_files() {
# Verify the the first parameter is a directory
local directory="$1"
if [ -z "$directory" ]; then
echo "Please specify directory to export in to."
exit 1
fi
if [ -d "$directory" ]; then
echo "Please specifiy a directory which doesn't exist"
exit 1
fi
# Get the name of the php container
local cid=$(docker-compose ps -q php)
# Copy files to containers current release
docker cp $cid:$PROJECT_RELEASES_PATH/current/drupal/sites/default/files/ $directory
}
_decompose-process-export_files_help() {
echo " Export public files to the specified directory"
echo " PARAM 1: Directory name to export files to."
echo " Directory will be created."
}
_decompose-process-import_files() {
# Verify the the first parameter is a file
local directory=$1
if [ ! -d "$directory" ]; then
echo "Directory '$directory' does not exist"
exit 1
fi
# Get the name of the database container
local cid=$(docker-compose ps -q php)
local files_dir="$PROJECT_CURRENT_RELEASE_PATH/drupal/sites/default/files"
# Copy directory to container
docker cp $directory/. $cid:$files_dir
# Set correct owner for 'files'
# Allow other containers to see files
docker exec $cid bash -c "chown -R www-data: $files_dir/ && \
find $files_dir/. -type d -print0 | xargs -0 chmod 0755 && \
find $files_dir/. -type f -print0 | xargs -0 chmod 0644"
}
_decompose-process-import_files_help() {
echo " Copies 'files' directory to the php container"
}
_decompose-process-check_drupal() {
docker-compose exec --user www-data -T php bash -c '/opt/check_drupal/bin/check_drupal -d /app/releases/current/drupal/ -n "$(drush vget --exact site_name)" -s e -u w -e e -w w -m e'
return $?
}
_decompose-process-check_drupal_help() {
echo " Call check_drupal nagios monitoring script from within PHP container"
}
_decompose-process-cron() {
echo "Rebuilding the project ..."
decompose build
return_code=$((return_code + $?))
if [ $return_code -ne 0 ]; then
echo "Return code of '$return_code' detected. Stopping Cron process."
return $return_code
fi
echo "Restarting services ..."
decompose up
return_code=$((return_code + $?))
if [ $return_code -ne 0 ]; then
echo "Return code of '$return_code' detected. Stopping Cron process."
return $return_code
fi
echo "Updating Drupal database ..."
decompose drush -y updb
# Return is sometimes 129 if there are no updates. Not useful.
#return_code=$((return_code + $?))
echo "Removing dangling Docker images ..."
decompose remove-dangling-docker-images
return_code=$((return_code + $?))
echo "Backing up config ..."
decompose backup_config
return_code=$((return_code + $?))
return $return_code
}
_decompose-process-cron_help() {
echo " Run cron tasks"
}
# Source project processes last to allow the project to override any environment process
source $(_decompose-project-root)/processes
# vim:syntax=sh tabstop=2 shiftwidth=2 expandtab