annotate scripts/updates-apply.sh @ 408:e49038cbb14c

Add scripts for ITC Management application
author Marc Davis <marc.davis@mcoecn.org>
date Mon, 10 Oct 2022 14:32:06 -0400
parents 6aecbb32c587
children
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
260
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
15 # /ssdt/apply-updates.sh /data/preview uspsapp
51
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
260
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
37 if [[ $eol =~ "Up" ]]
51
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
38 then
260
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
39 t=(${container//_/ })
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
40 service=${t[1]}
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
41 if [[ $service == $SERVICE ]]
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
42 then
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
43 echo -e "\n$project: Updating $service"
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
44 docker-compose up -d $service
6aecbb32c587 fix script to not start stopped containers
aldrich@nwoca.org
parents: 191
diff changeset
45 fi
51
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
46 fi
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
47 fi
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
48 done < <(docker-compose ps)
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
49
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
50 done
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
51
40e10b1d32f7 add script to apply image updates to compose projects
Dave smith <smith@nwoca.org>
parents:
diff changeset
52 cd $ORIGINALDIR