Skip to content

Commit d700b0a

Browse files
committed
Update to Traefik V2 / DIR traefik_stack6 / squashed
1 parent 570f36e commit d700b0a

30 files changed

+5348
-281
lines changed

traefik_stack6/dynamic_conf.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

traefik_stack6/htdocs/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

traefik_stack6/rundown.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
3+
# A best practices Bash script template with many useful functions. This file
4+
# sources in the bulk of the functions from the source.sh file which it expects
5+
# to be in the same directory. Only those functions which are likely to need
6+
# modification are present in this file. This is a great combination if you're
7+
# writing several scripts! By pulling in the common functions you'll minimise
8+
# code duplication, as well as ease any potential updates to shared functions.
9+
10+
# A better class of script
11+
set -o errexit # Exit on most errors (see the manual)
12+
set -o errtrace # Make sure any error trap is inherited
13+
set -o nounset # Disallow expansion of unset variables
14+
set -o pipefail # Use last non-zero exit code in a pipeline
15+
#set -o xtrace # Trace the execution of the script (debug)
16+
17+
# DESC: Usage help
18+
# ARGS: None
19+
# OUTS: None
20+
function script_usage() {
21+
cat << EOF
22+
Usage:
23+
-h|--help Displays this help
24+
-v|--verbose Displays verbose output
25+
-nc|--no-colour Disables colour output
26+
-cr|--cron Run silently unless we encounter an error
27+
EOF
28+
}
29+
30+
# DESC: Parameter parser
31+
# ARGS: $@ (optional): Arguments provided to the script
32+
# OUTS: Variables indicating command-line parameters and options
33+
function parse_params() {
34+
local param
35+
while [[ $# -gt 0 ]]; do
36+
param="$1"
37+
shift
38+
case $param in
39+
-h|--help)
40+
script_usage
41+
exit 0
42+
;;
43+
-v|--verbose)
44+
verbose=true
45+
;;
46+
-nc|--no-colour)
47+
no_colour=true
48+
;;
49+
-cr|--cron)
50+
cron=true
51+
;;
52+
*)
53+
esac
54+
done
55+
}
56+
57+
58+
# DESC: Main control flow
59+
# ARGS: $@ (optional): Arguments provided to the script
60+
# OUTS: None
61+
function main() {
62+
# load config and variables for this project
63+
source "$(dirname "${BASH_SOURCE[0]}")/shellcheck.sh"
64+
65+
trap script_trap_err ERR
66+
trap script_trap_exit EXIT
67+
68+
script_init "$@"
69+
parse_params "$@"
70+
cron_init
71+
colour_init
72+
#lock_init system
73+
74+
clear; echo;
75+
goto_myscript;
76+
echo;
77+
}
78+
79+
# --- edit YOUR SCRIPT HERE
80+
function goto_myscript() {
81+
82+
docker stack rm stkproxy || true; sleep 1;
83+
84+
docker stack rm stkwebapp || true; sleep 1;
85+
86+
docker stack rm stkgui || true; sleep 1;
87+
88+
#echo; echo "Remove network ..."
89+
#docker network rm ntw_front
90+
91+
#echo; echo "Clean up ..."
92+
#docker system prune -f
93+
94+
}
95+
96+
# --- Entrypoint
97+
main "$@"
98+
99+
# by Pascal Andy | https://pascalandy.com/
100+
# https://github.com/pascalandy/bash-script-template

traefik_stack6/runup.sh

Lines changed: 67 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function parse_params() {
6060
# OUTS: None
6161
function main() {
6262
# load config and variables for this project
63-
source "$(dirname "${BASH_SOURCE[0]}")/config_and_vars.sh"
6463
source "$(dirname "${BASH_SOURCE[0]}")/shellcheck.sh"
6564

6665
trap script_trap_err ERR
@@ -83,101 +82,96 @@ function goto_myscript() {
8382
docker pull devmtl/figlet:1.0
8483

8584
clear;
86-
message_is="docker-stack-this"
87-
docker run --rm devmtl/figlet:1.0 ${message_is} && sleep 2 && echo;
88-
89-
clear;
90-
message_is="If existing, remove stacks: "
91-
docker run --rm devmtl/figlet:1.0 ${message_is} && sleep 2 && echo;
92-
./rundown.sh
93-
94-
clear;
95-
message_is="If not existing, create networks"
96-
docker run --rm devmtl/figlet:1.0 ${message_is} && echo;
97-
98-
this_net="ntw_front"
99-
if [ ! "$(docker network ls --filter name=${this_net} -q)" ]; then
100-
docker network create --driver overlay --attachable --opt encrypted "${this_net}"
101-
echo "Network: ${this_net} was created."
102-
else
103-
echo "Network: ${this_net} already exist."
104-
fi
105-
106-
this_net="ntw_proxy"
107-
if [ ! "$(docker network ls --filter name=${this_net} -q)" ]; then
108-
docker network create --driver overlay --attachable --opt encrypted "${this_net}"
109-
echo "Network: ${this_net} was created."
110-
else
111-
echo "Network: ${this_net} already exist."
112-
fi
113-
echo;
114-
115-
message_is="Show networks"
116-
docker run --rm devmtl/figlet:1.0 ${message_is} && echo;
117-
118-
docker network ls | grep "ntw_" && echo && sleep 2;
85+
message_is="docker"
86+
docker run --rm devmtl/figlet:1.0 ${message_is} && \
87+
message_is="stack-this"
88+
docker run --rm devmtl/figlet:1.0 ${message_is} && sleep 2 && echo && \
89+
90+
# If existing, remove stacks: "
91+
./rundown.sh && \
92+
93+
# If not existing, create networks"
94+
# create an overlay networks on docker swarm
95+
arr=( "ntw_front" "ntw_proxy" )
96+
97+
for i in "${arr[@]}"; do
98+
if [ ! "$(docker network ls --filter name=${i} -q)" ]; then
99+
docker network create --driver overlay --attachable --opt encrypted "${i}"
100+
echo "Network: ${i} was created."
101+
else
102+
echo "Network: ${i} already exist."
103+
fi
104+
done
119105

106+
message_is="Show networks" && docker run --rm devmtl/figlet:1.0 ${message_is} && echo && \
107+
docker network ls | grep "ntw_" && echo && sleep 2 && \
120108
clear;
121-
message_is="Launch stacks"
122-
docker run --rm devmtl/figlet:1.0 ${message_is} && echo;
123109

110+
message_is="Launch stacks" && docker run --rm devmtl/figlet:1.0 ${message_is} && echo && \
124111

125112
# Set ACME file
126-
mkdir -pv ./configs && \
127-
touch ./configs/acme.json && \
128-
chmod 600 acme.json && \
129-
130-
cp dynamic_conf.yml ./configs/dynamic_conf.yml && \
131-
cp traefik.yml ./configs/traefik.yml.yml && \
132-
133-
# traefik
134-
docker stack deploy stkproxy -c stack-proxy.yml && echo; sleep 1 && \
135-
136-
# webapps
137-
docker stack deploy stkwhoami1 -c stack-whoami1.yml && echo; sleep 1 && \
138-
139-
# gui
140-
#docker stack deploy stkgui -c stack-portainer.yml && echo; sleep 1;
141-
142-
# swarmpit / constraint the db
113+
#mkdir -pv ~/./configs && \
114+
#touch ~/./configs/acme.json && \
115+
#cp dynamic_conf.yml ~/./configs/dynamic_conf.yml && \
116+
#cp traefik.yml ~/./configs/traefik.yml && \
117+
#chmod 600 ~/./configs/acme.json && \
118+
#chmod 600 ~/./configs/dynamic_conf.yml && \
119+
#chmod 600 ~/./configs/traefik.yml && \
120+
121+
# deploy apps
122+
docker stack deploy stkproxy -c stk_traefik.yml && \
123+
docker stack deploy stkwebapp -c stk_web.yml && \
124+
docker stack deploy stkgui -c stk_portainer.yml && echo && \
125+
126+
# deploy swarmpit / constraint the db
143127
#export NODE_ID=$(docker info -f '{{.Swarm.NodeID}}')
144128
#docker node update --label-add swarmpit.db-data=true $NODE_ID && echo;
145129
#docker stack deploy toolswarmpit -c stack-swarmpit.yml && echo; sleep 1;
146130

147-
# wordpress
131+
# deploy wordpress
148132
# the system is path is at ./docker-stack5
149133
#_MYSQL_DIR="$(pwd)/html/db/mysql"
150134
#mkdir -p "$_MYSQL_DIR"
151135

152136
#docker stack deploy toolwp -c toolwp.yml
153137
#echo; sleep 1;
154138

155-
clear;
156-
message_is="Check services"
157-
docker run --rm devmtl/figlet:1.0 ${message_is} && echo;
158-
159-
MIN="1"
160-
MAX="8"
161-
for ACTION in $(seq ${MIN} ${MAX}); do
162-
echo && echo "docker service ls | Check ${ACTION}" of ${MAX}; echo;
163-
docker service ls && echo && sleep 2;
164-
done
165-
echo;
139+
FLAG_WAIT="true"
140+
while [[ ${FLAG_WAIT} == "true" ]]; do
141+
142+
# check if apps are running on K8s (or are in progress)
143+
IN_PROGRESS=$(docker service ls | awk '{print $4}' | grep "0/" | wc -l)
144+
145+
if [[ ${IN_PROGRESS} -ne 0 ]]; then
146+
docker service ls ;
147+
echo "===> Deployment in progress..." && echo && \
148+
sleep 2 ;
149+
elif [[ ${IN_PROGRESS} -eq 0 ]]; then
150+
echo "App deployed!" && echo && \
151+
FLAG_WAIT="false" && sleep 2 && \
152+
docker service ls ;
153+
else
154+
echo "Unexpected error (err45)" ;
155+
fi
156+
done && \
157+
echo && \
158+
166159

167-
docker stack ls && echo;
160+
message_is="Check services" && docker run --rm devmtl/figlet:1.0 ${message_is} && echo && \
161+
docker service ls && echo && \
168162

169-
message_is="Your turn"
170-
docker run --rm devmtl/figlet:1.0 ${message_is} && echo;
163+
message_is="Your turn" &&docker run --rm devmtl/figlet:1.0 ${message_is} && echo && \
171164

172165
# See Traefik logs
173166
echo "If you enjoy this project, Give it a Star or Fork it :)";
174-
echo " https://github.com/pascalandy/docker-stack-this/" && echo;
167+
echo " https://github.com/pascalandy/docker-stack-this/" && echo && \
175168

176169
# See Traefik logs
177-
echo "Command ideas: ";
178-
echo " docker service logs -f stkproxy_traefik";
179-
echo " docker service ls";
180-
echo " docker stack ls"; echo;
170+
echo "Command ideas: " && \
171+
echo " docker service logs -f stkproxy_traefik" && \
172+
echo " docker service ls" && \
173+
echo " docker ps" && \
174+
echo " docker stack ls" && echo;
181175
}
182176

183177
# --- Entrypoint

0 commit comments

Comments
 (0)