#!/bin/sh set -e DB_USER="test" DB_PASS="test" DB_DSN_DEV="postgres://$DB_USER:$DB_PASS@127.0.0.1:5432/dev?sslmode=disable" CONFIG_FILE=config.yml MIGRATION_SCHEMA=./migrations DOCKER_COMPOSE_FILE=./docker/docker-compose.yml _usage() { echo "Usage:" echo "$0 [back|front]" exit 1 } _check_command() { command -v "$1" >/dev/null 2>/dev/null } _ensure_command() { _check_command "$1" && return 0 echo "Please install $1 first" exit 1 } _migrate() { migrate -database "$DB_DSN_DEV" "$@" } _ensure_command go _ensure_command docker _ensure_command docker-compose _ensure_command yarn _check_command migrate || { echo "Installing migrate" GO111MODULE=off \ go get -tags 'postgres' \ -u -v github.com/golang-migrate/migrate/cmd/migrate } _check_command fresh || { echo "Installing fresh" GO111MODULE=off \ go get -u -v github.com/pilu/fresh } [ -f "$CONFIG_FILE" ] || { echo "Please setup the canape configuration in $CONFIG_FILE" exit 1 } case $1 in back) docker-compose -f "$DOCKER_COMPOSE_FILE" up -d # Wait for the container to be up _migrate -path "$MIGRATION_SCHEMA" up CONFIG_FILE="./config.yml" fresh -c fresh.conf ;; front) yarn install yarn start ;; *) _usage ;; esac