-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.sh
executable file
·90 lines (82 loc) · 3.08 KB
/
template.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
#!/bin/bash
set -eo pipefail
# Generates kubernetes YAML files off of the templates included in this project
usage() {
echo -e "\nUsage: ./template.sh -d mydeployment -n default -i myimage:v2 -p 1234 --hostname my.cname.record
Flags:
Required:
-d, --deployment: Deployment name
-n, --namespace: Deployment namespace
-i, --image: Deployment image
-p, --port: Port to use for the kuberenetes service
--hostname: Hostname to use for ingress
Optional:
-c, --container-port: Port that the container is listening on (default: 80)
--port-name: Name of the port (default: http)
-h, --help: Print usage"
exit ${1:-0}
}
CONTAINER_PORT=8080
PORT_NAME=http
while [ "$1" ]; do
case $1 in
-d | --deployment )
shift
DEPLOYMENT_NAME=$1
;;
-n | --namespace )
shift
NAMESPACE=$1
;;
-i | --image )
shift
IMAGE=$1
;;
-p | --port )
shift
PORT=$1
;;
-c | --container-port )
shift
CONTAINER_PORT=$1
;;
--port-name )
shift
PORT_NAME=$1
;;
--hostname )
shift
INGRESS_HOSTNAME=$1
;;
-h | --help )
usage
;;
* )
echo "Error: \"$1\" is not a valid option"
usage 1
;;
esac
shift
done
if [ ! "$DEPLOYMENT_NAME" ] || [ ! "$NAMESPACE" ] || [ ! "$IMAGE" ] || [ ! "$PORT" ] || [ ! "$INGRESS_HOSTNAME" ]; then
echo "Error: Missing required arguments"
usage 1
fi
template() {
cat $1 | \
sed s,{{deployment_name}},"$DEPLOYMENT_NAME",g | \
sed s,{{deployment_namespace}},"$NAMESPACE",g | \
sed s,{{deployment_image}},"$IMAGE",g | \
sed s,{{service_port}},"$PORT",g | \
sed s,{{container_port}},"$CONTAINER_PORT",g | \
sed s,{{port_name}},"$PORT_NAME",g | \
sed s,{{host_name}},"$INGRESS_HOSTNAME",g
}
mkdir ${DEPLOYMENT_NAME} &>/dev/null || true
DIRNAME=$(dirname $0)
template ${DIRNAME}/templates/role.yaml > ${DEPLOYMENT_NAME}/role.yaml
template ${DIRNAME}/templates/pod-security-policy.yaml > ${DEPLOYMENT_NAME}/pod-security-policy.yaml
template ${DIRNAME}/templates/deployment.yaml > ${DEPLOYMENT_NAME}/deployment.yaml
template ${DIRNAME}/templates/service.yaml > ${DEPLOYMENT_NAME}/service.yaml
template ${DIRNAME}/templates/ingress.yaml > ${DEPLOYMENT_NAME}/ingress.yaml
echo -e "K8s yaml created:\n ${DEPLOYMENT_NAME}/pod-security-policy.yaml\n ${DEPLOYMENT_NAME}/role.yaml\n ${DEPLOYMENT_NAME}/deployment.yaml\n ${DEPLOYMENT_NAME}/service.yaml\n ${DEPLOYMENT_NAME}/ingress.yaml"