Mercurial > public > ssdt-docker
view scripts/.functions.sh @ 157:018f62da1931
DEP-12: add docker version. prevent pulling updates for dangling images
author | smith@nwoca.org |
---|---|
date | Mon, 31 Jul 2017 20:49:53 +0100 |
parents | 249ec634da33 |
children | 1a8087653f2a |
line wrap: on
line source
#!/bin/bash getScriptDir() { SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done echo $( cd $( dirname $SOURCE) && pwd ) } if [ "$SSDT_HOME" == "" ] then export SSDT_SCRIPTS=$(getScriptDir) export SSDT_HOME=$(dirname $SSDT_SCRIPTS) fi export SSDT_DOCKER_VERSION=$(docker version --format '{{.Server.Version}}') # deletes psql data from specified service resetDbVolume() { # Works for named and unnamed volumes and custom $PGDATA. # Container must be stopped service=${1?Must supply db service to reset} container=$(composeGetContainer $service) if [ "$container" != "" ] then echo "deleting db data from $container" docker-compose run --no-deps --rm $service bash -c "rm -rf \${PGDATA?Missing PGDATA env}" fi } # finds docker container for specified compose service composeGetContainer() { service=${1?"Must supply service from current project"} container=$( docker-compose ps | cut -d " " -f 1 -s | grep _${service}_ ) echo $container } executeSQL() { service=${1?Must supply db service to execute against} container=$(composeGetContainer $service) echo "$2" | docker exec -i $container sh -c "gosu postgres psql \$DB_NAME" } composeGetProject() { service=${1?"Must supply service from current project"} container=$(composeGetContainer $service) echo $(docker inspect -f '{{index .Config.Labels "com.docker.compose.project" }}' $container) }