annotate scripts/.functions.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 c3587159637f
children b72855a930f1
rev   line source
55
77ff739c078d add script to provide shortened docker ps with ssdt labels
smith@nwoca.org
parents:
diff changeset
1 #!/bin/bash
143
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
2 getScriptDir() {
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
3 SOURCE="${BASH_SOURCE[0]}"
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
4 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
5 echo $( cd $( dirname $SOURCE) && pwd )
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
6 }
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
7
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
8 if [ "$SSDT_HOME" == "" ]
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
9 then
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
10 export SSDT_SCRIPTS=$(getScriptDir)
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
11 export SSDT_HOME=$(dirname $SSDT_SCRIPTS)
c029be781d13 DEP-12: handle symlinks in home discovery
smith@nwoca.org
parents: 85
diff changeset
12 fi
61
cc997ae758c6 add process summary and list
smith@nwoca.org
parents: 59
diff changeset
13
190
c3587159637f DEP-12: fix if expression
smith@nwoca.org
parents: 189
diff changeset
14 if [ "$(which docker-compose)" == "" ]
189
1a8087653f2a DEP-12: add docker-compse path if compose not found
smith@nwoca.org
parents: 157
diff changeset
15 then
1a8087653f2a DEP-12: add docker-compse path if compose not found
smith@nwoca.org
parents: 157
diff changeset
16 PATH="${PATH}:/usr/local/bin"
1a8087653f2a DEP-12: add docker-compse path if compose not found
smith@nwoca.org
parents: 157
diff changeset
17 fi
1a8087653f2a DEP-12: add docker-compse path if compose not found
smith@nwoca.org
parents: 157
diff changeset
18
157
018f62da1931 DEP-12: add docker version. prevent pulling updates for dangling images
smith@nwoca.org
parents: 144
diff changeset
19 export SSDT_DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
018f62da1931 DEP-12: add docker version. prevent pulling updates for dangling images
smith@nwoca.org
parents: 144
diff changeset
20
73
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
21 # deletes psql data from specified service
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
22 resetDbVolume() {
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
23 # Works for named and unnamed volumes and custom $PGDATA.
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
24 # Container must be stopped
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
25 service=${1?Must supply db service to reset}
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
26 container=$(composeGetContainer $service)
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
27 if [ "$container" != "" ]
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
28 then
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
29 echo "deleting db data from $container"
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
30 docker-compose run --no-deps --rm $service bash -c "rm -rf \${PGDATA?Missing PGDATA env}"
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
31 fi
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
32 }
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
33
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
34 # finds docker container for specified compose service
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
35 composeGetContainer() {
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
36 service=${1?"Must supply service from current project"}
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
37
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
38 container=$( docker-compose ps | cut -d " " -f 1 -s | grep _${service}_ )
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
39 echo $container
d2c44193fbaa explictly remove db's before import
smith@nwoca.org
parents: 66
diff changeset
40 }
79
85957628f4c0 add script to clear liquibase lock on existing db container
smith@nwoca.org
parents: 73
diff changeset
41
85957628f4c0 add script to clear liquibase lock on existing db container
smith@nwoca.org
parents: 73
diff changeset
42 executeSQL() {
85957628f4c0 add script to clear liquibase lock on existing db container
smith@nwoca.org
parents: 73
diff changeset
43 service=${1?Must supply db service to execute against}
85957628f4c0 add script to clear liquibase lock on existing db container
smith@nwoca.org
parents: 73
diff changeset
44 container=$(composeGetContainer $service)
85957628f4c0 add script to clear liquibase lock on existing db container
smith@nwoca.org
parents: 73
diff changeset
45
85957628f4c0 add script to clear liquibase lock on existing db container
smith@nwoca.org
parents: 73
diff changeset
46 echo "$2" | docker exec -i $container sh -c "gosu postgres psql \$DB_NAME"
85
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
47 }
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
48
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
49 composeGetProject() {
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
50 service=${1?"Must supply service from current project"}
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
51 container=$(composeGetContainer $service)
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
52 echo $(docker inspect -f '{{index .Config.Labels "com.docker.compose.project" }}' $container)
8f45c43ea7a4 DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents: 79
diff changeset
53 }