-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_env.sh
executable file
·106 lines (94 loc) · 2.3 KB
/
encode_env.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
#!/bin/bash
source .env
# Create the charts directory
mkdir -p charts
# Create the Kubernetes Secret YAML file
cat <<EOF > charts/${PWD##*/}-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: ${PWD##*/}-secret
type: Opaque
data:
EOF
while read -r line || [ -n "$line" ]; do
if [ -n "$line" ]; then
key=$(echo $line | cut -d'=' -f1)
value=$(echo $line | cut -d'=' -f2)
encoded=$(echo -n $value | base64)
echo " $key: $encoded" >> charts/${PWD##*/}-secret.yaml
fi
done < .env
# Create the Kubernetes ConfigMap YAML file
cat <<EOF > charts/${PWD##*/}-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: ${PWD##*/}-configmap
data:
EOF
while read -r line || [ -n "$line" ]; do
if [ -n "$line" ]; then
key=$(echo $line | cut -d'=' -f1)
value=$(echo $line | cut -d'=' -f2)
echo " $key: $value" >> charts/${PWD##*/}-configmap.yaml
fi
done < .env
# Create the Kubernetes Service YAML file
cat <<EOF > charts/${PWD##*/}-service.yaml
apiVersion: v1
kind: Service
metadata:
name: ${PWD##*/}
spec:
selector:
app: ${PWD##*/}
ports:
EOF
while read -r line || [ -n "$line" ]; do
if [[ "$line" == *"EXPOSE"* ]]; then
port=$(echo $line | awk '{print $2}' | cut -d'/' -f1)
protocol=$(echo $line | awk '{print $2}' | cut -d'/' -f2)
cat <<EOF >> charts/${PWD##*/}-service.yaml
- protocol: $protocol
port: $port
targetPort: $port
EOF
fi
done < Dockerfile
# Create the Kubernetes Deployment YAML file
cat <<EOF > charts/${PWD##*/}-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${PWD##*/}-deployment
spec:
replicas: 1
selector:
matchLabels:
app: ${PWD##*/}
template:
metadata:
labels:
app: ${PWD##*/}
spec:
containers:
- name: ${PWD##*/}
image: ssenchyna/${PWD##*/}:latest
ports:
EOF
while read -r line || [ -n "$line" ]; do
if [[ "$line" == *"EXPOSE"* ]]; then
port=$(echo $line | awk '{print $2}' | cut -d'/' -f1)
cat <<EOF >> charts/${PWD##*/}-deployment.yaml
- containerPort: $port
EOF
fi
done < Dockerfile
cat <<EOF >> charts/${PWD##*/}-deployment.yaml
envFrom:
- configMapRef:
name: ${PWD##*/}-configmap
- secretRef:
name: ${PWD##*/}-secret
EOF