-
Notifications
You must be signed in to change notification settings - Fork 0
/
traefik-gen-dynconf
executable file
·71 lines (55 loc) · 2.06 KB
/
traefik-gen-dynconf
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
#!/bin/bash
# Auhtor: Julian Lamprecht
# V1.0
# Script to generate a valid dynamic yaml config for traefik
if [ $# -ne 1 ]; then
>&2 echo "Not enough arguments"
echo "Usage: $(basename "$0") [file]"
echo "The file must have the followig format with one service per line. Each element must be separated by spaces"
echo "[service name] [hostname / ip] [port] [domain]"
exit 1
fi
SERVICES_FILE=$1
TRAEFIK_FILE=traefik.yaml
############################################################################################################################
# Read the file line by line into the arrary; One service per line
readarray -t services < $SERVICES_FILE
############################################################################################################################
# TODO: add option to enable tcp requests
# Start the file with "http" to enable http requests
echo "http:" >> $TRAEFIK_FILE
############################################################################################################################
# Generate routers for each service
echo " routers:" >> $TRAEFIK_FILE
for service in "${services[@]}"
do
# Split string into array, split by spaces
IFS=" " read -ra serviceArray <<< $service
#for x in "${serviceArray[@]}"
#do
# echo $x
#done
{
echo " ${serviceArray[0]}:"
echo " rule: \"Host(\`${serviceArray[3]}\`)\""
echo " service: ${serviceArray[0]}"
} >> $TRAEFIK_FILE
done
############################################################################################################################
# Generate each service
echo " services:" >> $TRAEFIK_FILE
for service in "${services[@]}"
do
# Split string into array, split by spaces
IFS=" " read -ra serviceArray <<< $service
#for x in "${serviceArray[@]}"
#do
# echo $x
#done
{
echo " ${serviceArray[0]}:"
echo " loadbalancer:"
echo " servers:"
echo " - url: http://${serviceArray[1]}:${serviceArray[2]}"
} >> $TRAEFIK_FILE
done