Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startup and utility scripts #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions bin/services
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

SCRIPT_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source $SCRIPT_DIR/utilities

main() {
case "$1" in
u | up)
up $2
;;
d | down)
down $2
;;
-h | --help)
help
;;
*)
printMsg "Invalid service collection: $1"
help
;;
esac
}

up() {
local label='all'
up-msg $label $1
docker-compose up $1 nginx-proxy lambda db
}

down() {
local label='all'
printMsg "-- Bringing down $label services..."
docker-compose down
}

compose-services() {
local label=$1
local detached=""
local services=""

# The "detached" flag and the list of services sort of
# get lumped together as arguments, so this is a
# "best bad attempt" at solving it for now
if [[ $2 == '-d' ]]; then
detached=$2
services="${@:3}"
else
services="${@:2}"
fi

up-msg "$label" $detached
docker-compose up $detached $services
}

up-msg() {
local insertion=""
if [[ $2 == '-d' ]]; then
insertion=" in detached mode"
fi
printMsg "-- Starting up $1 services$insertion..."
}

help() {
cat <<TEXT

SYNOPSIS
services [collection] [-d]

OPTIONS
-d
Detached mode, run containers in the background

COLLECTIONS
u, up
Brings up all containers

d, down
Brings down all containers

EXAMPLES
bin/services down
Brings down all containers

bin/services up
Brings up all containers

bin/services up -d
Brings up all containers in detached mode

TEXT
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
9 changes: 9 additions & 0 deletions bin/utilities
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

printMsg() {
local RED='\033[0;31m'
local CLEAR='\033[0m'
echo -e "\n${RED}$1${CLEAR}\n"
}

export -f printMsg