-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-dev
More file actions
executable file
·96 lines (80 loc) · 2.51 KB
/
docker-dev
File metadata and controls
executable file
·96 lines (80 loc) · 2.51 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
#!/bin/bash
##############################################################################
#
# Copyright (c) 2017, 2degrees Limited.
# All Rights Reserved.
#
# This file is part of docker-dev
# <https://github.com/2degrees/docker-dev>, which is subject
# to the provisions of the BSD at
# <http://dev.2degreesnetwork.com/p/2degrees-license.html>. A copy of the
# license should accompany this distribution. THIS SOFTWARE IS PROVIDED "AS IS"
# AND ANY AND ALL EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST
# INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
#
##############################################################################
. "$(dirname $BASH_SOURCE)/_bootstrap.sh"
# ===== Constants and functions
PREBUILD_HOOK_FILE_NAME='./.dockerdev-prebuild'
function usage {
error_out 1 "Usage: ${0##*/} run|up|up2|down|build [EXTRA_ARGS...]"
}
function get_dependent_services_for_services {
local services="$@"
# The only way to calculate the dependent services is by starting the
# required services!
docker-compose rm --force -v >>/dev/null
local container_names="$(
docker-compose create ${services} 3>&2 2>&1 1>&3- | \
egrep '^Creating' | \
awk '{ print $2 }' | \
sort | \
uniq
)"
if [[ ${container_names} ]]; then
echo "${container_names}" |
xargs \
--no-run-if-empty \
docker \
inspect \
--format '{{ index .Config.Labels "com.docker.compose.service" }}'
docker rm --volumes ${container_names} >> /dev/null
else
error_out 2 'Could not find dependent services'
fi
}
# ===== Main
if [[ "$#" == "0" ]]; then
usage
fi
SUBCOMMAND="$1"
shift
case "${SUBCOMMAND}" in
run)
exec docker-compose run --rm "$@"
;;
up)
exec docker-compose up \
--force-recreate \
--abort-on-container-exit \
--remove-orphans \
"$@"
;;
up2)
all_services="$(get_dependent_services_for_services "$@")"
exec "${BASH_SOURCE}" up ${all_services}
;;
down)
exec docker-compose down --rmi local --volumes --remove-orphans "$@"
;;
build)
if [[ -x "${PREBUILD_HOOK_FILE_NAME}" ]]; then
"${PREBUILD_HOOK_FILE_NAME}"
fi
exec docker-compose build --force-rm --pull "$@"
;;
*)
usage
;;
esac