-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-cmd.sh
More file actions
executable file
·104 lines (79 loc) · 2.51 KB
/
Copy pathstack-cmd.sh
File metadata and controls
executable file
·104 lines (79 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# Commands to bring the sciforge stack up
# Reads in env vars that need to be in linux env before docker-compose commands run, and brings stack up, down, etc
# Available Commands
# up: bring all services up
# down: bring all services down
#Import Yaml parser
. yamlparse.sh
shopt -s nocasematch
# exit when any command fails
set -e
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
read_var() {
#Bug fix note -- Line 29 will fail if the param $2(.env file) contains a line that both contains param $1 and has a ' or " in it.
#Recommended fix VAR=$(grep $1 $2 | xargs -0)
VAR=$(grep $1 $2 | xargs)
IFS="=" read -ra VAR <<< "$VAR"
echo $(trim ${VAR[1]})
}
doDockerStuff() {
if [ "$#" -lt "3" ]; then
echo "inadequate parameters for doDockerStuff. Expect args of action(up, down), primary service name, and path to docker-compose.yml."
exit 1
fi
local lclACTION=$1
local lclINSTANCE=$2
local lclCOMPOSE_PATH=$3
local lclMAIN_SERVICE=$4
echo "working on docker stuff"
export lclCOMPOSE_FILE="${lclCOMPOSE_PATH}/docker-compose.yml"
echo $lclCOMPOSE_FILE
if [ "$lclACTION" == "down" ]; then
echo "Bring it down"
docker stack rm $lclMAIN_SERVICE
fi
if true ; then
if [ "$lclACTION" == "up" ]; then
# Use YamlParser to get volumes
build_volumes "$SITE"
# Setup docker registry
if [ -z "$(docker service ls -q -f name=registry)" ]; then
echo "Creating registry service"
docker service create --name registry --publish published=5000,target=5000 registry:2
fi
docker compose build
docker compose push
# Create Docker registry
env $(cat .env | grep ^[A-Z] | xargs) docker stack deploy --compose-file docker-compose.yml $lclMAIN_SERVICE
fi
else
if [ "$lclACTION" != "down" ]; then
echo "$lclMAIN_SERVICE needs to be brought down in order to pull updates or bring dockers up"
fi
fi
}
# STARTUP CHECKS
if [ ! -f ".env" ]; then
echo "Environment file not present, exiting"
exit 1
fi
if [ "$#" -eq "0" ]; then
echo "A command line argument is required. Valid commands are up, down."
exit 1
fi
# VAR INITIATION
ACTION="$1"
# Export all variables from .env
set -a
source .env
set +a
SANITIZED_SITE=$(echo "$SITE" | tr '.' '-')
doDockerStuff "$ACTION" "$SITE" "." "$SANITIZED_SITE"