Mercurial > public > ssdt-docker
annotate scripts/.functions.sh @ 350:5ed8e2ba0d91 release/2.8.1
flow: Closed <release> '2.8.1'.
author | aldrich@ssdt-ohio.org |
---|---|
date | Wed, 20 May 2020 15:58:46 +0100 |
parents | d6d8468441b1 |
children |
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 getScriptDir() { |
3 SOURCE="${BASH_SOURCE[0]}" | |
4 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done | |
5 echo $( cd $( dirname $SOURCE) && pwd ) | |
6 } | |
7 | |
8 if [ "$SSDT_HOME" == "" ] | |
9 then | |
10 export SSDT_SCRIPTS=$(getScriptDir) | |
11 export SSDT_HOME=$(dirname $SSDT_SCRIPTS) | |
12 fi | |
61 | 13 |
190 | 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 | 21 # deletes psql data from specified service |
22 resetDbVolume() { | |
23 # Works for named and unnamed volumes and custom $PGDATA. | |
24 # Container must be stopped | |
25 service=${1?Must supply db service to reset} | |
26 container=$(composeGetContainer $service) | |
27 if [ "$container" != "" ] | |
28 then | |
29 echo "deleting db data from $container" | |
30 docker-compose run --no-deps --rm $service bash -c "rm -rf \${PGDATA?Missing PGDATA env}" | |
31 fi | |
32 } | |
33 | |
34 # finds docker container for specified compose service | |
35 composeGetContainer() { | |
36 service=${1?"Must supply service from current project"} | |
279
d6d8468441b1
use container id's and inspect to derive projet and container names
smith@nwoca.org
parents:
266
diff
changeset
|
37 container=$( docker-compose ps -q $service | xargs docker inspect -f '{{.Name}}' | cut -d "/" -f 2 ) |
73 | 38 echo $container |
39 } | |
79
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
40 |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
41 executeSQL() { |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
42 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
|
43 container=$(composeGetContainer $service) |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
44 |
85957628f4c0
add script to clear liquibase lock on existing db container
smith@nwoca.org
parents:
73
diff
changeset
|
45 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
|
46 } |
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 composeGetProject() { |
279
d6d8468441b1
use container id's and inspect to derive projet and container names
smith@nwoca.org
parents:
266
diff
changeset
|
49 project=$(docker-compose ps -q | tail -n1 | xargs docker inspect -f "{{ index .Config.Labels \"com.docker.compose.project\"}}" ) |
266 | 50 echo $project |
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
|
51 } |