annotate scripts/updates-apply.sh @ 191:fea886ba7279

DEP-12: add source for .functions.sh to all scripts using compose
author smith@nwoca.org
date Wed, 20 Sep 2017 17:56:23 +0100
parents 334d65dac778
children 6aecbb32c587
rev   line source
54
334d65dac778 add hash bangs to specify bash shell
smith@nwoca.org
parents: 52
diff changeset
1 #!/bin/bash
51
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
2 # Scans for docker projects in specified parent path and
52
Dave smith <smith@nwoca.org>
parents: 51
diff changeset
3 # updates images, if applicable.
51
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
4 #
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
5 # The parent directory to search for docker-compose.yml
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
6 # files must be specified. An optional service to update
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
7 # may be specified in the second argument. The default is
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
8 # to update services matching "*app".
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
9 #
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
10 # Only services which are currently running will be updated.
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
11 # The script will not automatically start stopped services.
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
12 #
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
13 # examples:
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
14 # /ssdt/apply-updates.sh /data/preview
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
15 # /ssdt/apply-updates.sh /data/preview usps
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
16 #
191
fea886ba7279 DEP-12: add source for .functions.sh to all scripts using compose
smith@nwoca.org
parents: 54
diff changeset
17
fea886ba7279 DEP-12: add source for .functions.sh to all scripts using compose
smith@nwoca.org
parents: 54
diff changeset
18 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
fea886ba7279 DEP-12: add source for .functions.sh to all scripts using compose
smith@nwoca.org
parents: 54
diff changeset
19
51
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
20 : ${1?"Usage: {parent path} [service]"}
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
21 SERVICE=${2:-*app}
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
22
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
23 ORIGINALDIR=$PWD
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
24 PARENTDIR=$1
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
25
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
26 for f in $(find $PARENTDIR -name docker-compose.yml)
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
27 do
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
28 projectdir=`dirname $f`
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
29 project=`basename $projectdir`
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
30 cd $projectdir
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
31 echo -e "----\n$project: checking services"
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
32 while read line
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
33 do
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
34 read container eol <<< $line
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
35 if [[ $container == *_1 ]]
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
36 then
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
37 t=(${container//_/ })
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
38 service=${t[1]}
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
39 if [[ $service == $SERVICE ]]
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
40 then
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
41 echo -e "\n$project: Updating $service"
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
42 docker-compose up -d $service
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
43 fi
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
44 fi
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
45 done < <(docker-compose ps)
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
46
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
47 done
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
48
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
49 cd $ORIGINALDIR