-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
139 lines (124 loc) · 3.53 KB
/
deploy.sh
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
OPTIONS=d:bls
LONGOPTIONS=dev:,build,local,staging
skip=true # Skip build by default unless changed in args
registry=nexusstats # push to dockerhub by default
# -temporarily store output to be able to check for errors
# -e.g. use “--options” parameter by name to activate quoting/enhanced mode
# -pass arguments only via -- "$@" to separate them correctly
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
# e.g. $? == 1
# then getopt has complained about wrong arguments to stdout
exit 2
fi
# Read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"
while true; do
case "$1" in
-d|--dev)
dev=true
dev_path="$2"
shift 2
;;
-l|--local)
local=true
skip=false
registry=127.0.0.1:5000
shift
;;
-b|--build)
skip=false
shift
;;
-s|--staging)
staging=true
shift
;;
--)
shift
break
;;
esac
done
# Init swarm
docker swarm init
# Create private image registry on our swarm
if [[ $local == true ]] && [ ! "$(docker service ls | grep registry)" ]; then
docker service create -d \
--name registry \
-p 5000:5000 \
--mount type=volume,source=registry,destination=/var/lib/registry,volume-driver=local \
registry:latest
fi
# Use docker-compose pointing to local registry when --local flag is passed
if [[ $local == true ]]; then
compose_base=compose/local/app-base.yml
compose_dev=compose/local/app-dev.yml
compose_prod=compose/local/app-prod.yml
compose_staging=compose/local/app-staging.yml
compose_merged=compose/local/app.yml
else
compose_base=compose/app-base.yml
compose_dev=compose/app-dev.yml
compose_prod=compose/app-prod.yml
compose_staging=compose/app-staging.yml
compose_merged=compose/app.yml
fi
# Development
if [[ $dev == true ]]; then
if [[ $skip == false ]]; then
make dev registry=$registry
else
make dev-deps
fi
docker-compose \
-f $compose_base \
-f $compose_dev \
config > $compose_merged
# Allow attaching bind mount of the nexus repo to our dev container for easy
# file editing on the host machine
sed -i "/VOLUME PLACEHOLDER/c\ - $dev_path:/app/nexus-stats" $compose_merged
# Staging server
elif [[ $staging == true ]]; then
if [[ $skip == false ]]; then
make staging registry=$registry
else
make prod-deps
fi
cp ./app/prod/prelaunch.js /opt/debug/prelaunch.js
docker-compose \
-f $compose_base \
-f $compose_prod \
-f $compose_staging \
config > $compose_merged
# Production
else
if [[ $skip == false ]]; then
make prod registry=$registry
else
make prod-deps
fi
docker-compose \
-f $compose_base \
-f $compose_prod \
config > $compose_merged
fi
# Delete old containers (Docker sometimes just doesn't delete them)
docker system prune --force
# Create overlay networks
#if [ ! "$(docker network ls | grep nexus_app)" ]; then
# docker network create --driver overlay nexus_app
#fi
# Deploy new Stack and remove old containers
docker stack deploy --prune --compose-file $compose_merged nexus
# Automatically log dev container
if [[ $dev == true ]]; then
# Run watchdog to propagate file changes from the repo to our container.
# Only necessary on windows due to the nature of the filesystem.
if [[ $dev == true && ${DOCKER_OS} == 'Windows' && ! $(ps -ef) =~ 'docker-volume-watcher' ]]; then
docker-volume-watcher nexus_dev* /ui &
fi
# Just logging
docker service logs nexus_dev -f --raw
fi