Mercurial > public > ssdt-docker
annotate scripts/.functions.sh @ 143:c029be781d13
DEP-12: handle symlinks in home discovery
author | smith@nwoca.org |
---|---|
date | Wed, 05 Jul 2017 22:12:06 +0100 |
parents | 8f45c43ea7a4 |
children | 249ec634da33 |
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 | 2 |
3 getScriptDir() { | |
4 SOURCE="${BASH_SOURCE[0]}" | |
5 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done | |
6 echo $( cd $( dirname $SOURCE) && pwd ) | |
7 } | |
8 | |
9 if [ "$SSDT_HOME" == "" ] | |
10 then | |
11 export SSDT_SCRIPTS=$(getScriptDir) | |
12 export SSDT_HOME=$(dirname $SSDT_SCRIPTS) | |
13 fi | |
61 | 14 |
73 | 15 # deletes psql data from specified service |
16 resetDbVolume() { | |
17 # Works for named and unnamed volumes and custom $PGDATA. | |
18 # Container must be stopped | |
19 service=${1?Must supply db service to reset} | |
20 container=$(composeGetContainer $service) | |
21 if [ "$container" != "" ] | |
22 then | |
23 echo "deleting db data from $container" | |
24 docker-compose run --no-deps --rm $service bash -c "rm -rf \${PGDATA?Missing PGDATA env}" | |
25 fi | |
26 } | |
27 | |
28 # finds docker container for specified compose service | |
29 composeGetContainer() { | |
30 service=${1?"Must supply service from current project"} | |
31 | |
32 container=$( docker-compose ps | cut -d " " -f 1 -s | grep _${service}_ ) | |
33 echo $container | |
34 } | |
79
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
35 |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
36 executeSQL() { |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
37 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
|
38 container=$(composeGetContainer $service) |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
39 |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
40 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
|
41 } |
8f45c43ea7a4
DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents:
79
diff
changeset
|
42 |
8f45c43ea7a4
DEP-12: start upgrading scripts and compose files for RC and docker 1.12
Dave Smith <smith@nwoca.org>
parents:
79
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 } |