view scripts/.functions.sh @ 120:2e25338c847e

DEP-12: update integration vars
author smith@nwoca.org
date Fri, 05 May 2017 20:33:26 +0100
parents 8f45c43ea7a4
children c029be781d13
line wrap: on
line source
#!/bin/bash
export SSDT_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")
export SSDT_HOME=$(dirname $SSDT_SCRIPTS)

# 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)
}