Created
March 9, 2018 19:53
-
-
Save StevenWarren/02f4b75e47314f0e67615a1af25e9aa3 to your computer and use it in GitHub Desktop.
Shell script to alias Sqitch running in a Docker container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Dockerized Sqitch made easier | |
# | |
# References: | |
# Sqitch - https://metacpan.org/pod/sqitchtutorial | |
# Docker Image - https://hub.docker.com/r/jmabey/sqitch/ | |
# Configuration: | |
# Add a .env file in same directory and configure it. | |
# | |
# # Names to identify images and containers of this app | |
# IMAGE_NAME='jmabey/sqitch:postgres' | |
# CONTAINER_NAME="sqitch" | |
# | |
# # PG Container Info | |
# PGHOST="postgres_container_name" | |
# PGUSER="postgres_user" | |
# PGPASSWORD="postgres_password" | |
# PGDATABASE="postgres_database" | |
# | |
# # Sqitch specific | |
# PROJECT_NAME="projects_name" | |
# PROJECT_DIR="/path/to/sqitch/project" | |
# PROJECT_REPO="http://myprojectrepo/" | |
# | |
# Usage: | |
# | |
# ./sqitch.sh add poject_schema -n "Initial schema for project" | |
# ./sqitch.sh status | |
# | |
# export vars from .env file | |
set -a | |
source .env | |
set +a | |
# Verify all vars set in .env file | |
if [ -z ${IMAGE_NAME+x} ]; then echo "IMAGE_NAME is not configured in the .env file."; exit 1; fi | |
if [ -z ${CONTAINER_NAME+x} ]; then echo "CONTAINER_NAME is not configured in the .env file."; exit 1; fi | |
if [ -z ${PGHOST+x} ]; then echo "PGHOST is not configured in the .env file."; exit 1; fi | |
if [ -z ${PGUSER+x} ]; then echo "PGUSER is not configured in the .env file."; exit 1; fi | |
if [ -z ${PGPASSWORD+x} ]; then echo "PGPASSWORD is not configured in the .env file."; exit 1; fi | |
if [ -z ${PGDATABASE+x} ]; then echo "PGDATABASE is not configured in the .env file."; exit 1; fi | |
if [ -z ${PROJECT_NAME+x} ]; then echo "PROJECT_NAME is not configured in the .env file."; exit 1; fi | |
if [ -z ${PROJECT_DIR+x} ]; then echo "PROJECT_DIR is not configured in the .env file."; exit 1; fi | |
if [ -z ${PROJECT_REPO+x} ]; then echo "PROJECT_REPO is not configured in the .env file."; exit 1; fi | |
# default docker run command | |
docker run -it --rm \ | |
-v $PROJECT_DIR:/src \ | |
--env PGHOST=$PGHOST \ | |
--env PGUSER=$PGUSER \ | |
--env PGPASSWORD=$PGPASSWORD \ | |
--env PGDATABASE=$PGDATABASE \ | |
--network container:$PGHOST \ | |
$IMAGE_NAME "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment