-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.sh
executable file
·88 lines (70 loc) · 2.64 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
#!/bin/bash -e
REGISTRY=registry.31337.ooo:5000
only_service=""
do_push=false
restart_pods=false
if [[ $# -ne 0 ]]; then
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--push)
do_push=true
;;
-s|--service)
shift
only_service+=" ${1}"
;;
-r|--restart-pods)
restart_pods=true
;;
-h|--help)
printf $' This script builds frontends, builds dockers, and deploys\n'
printf $' -p, --push \tpushes to production\n -s, --service <service_name> \tproviding this arg limits built services'
printf $'to base and provided service names\n\t--service may be provided multiple times \n'
printf $' -r, --restart-pods \trestarts the k8s pods running this service \n'
printf $'example: ./deploy.sh --frontend --push --service team-interface \n\tBuilds frontend, pushes to production but only for team-interface'
exit 0
;;
*)
echo -e "${key} is unknown parameter"
;;
esac
shift # past argument or value
done
fi
echo "First build base"
docker build -f "dockerfiles/Dockerfile.game-infrastructure-base" -t "game-infrastructure-base" .
docker tag game-infrastructure-base:latest $REGISTRY/game-infrastructure-base:latest
if [[ ${do_push} = true ]]; then
docker push $REGISTRY/game-infrastructure-base:latest
fi
for DOCKERFILE in dockerfiles/Dockerfile.*
do
SERVICE_NAME="${DOCKERFILE##*.}"
if [ "$SERVICE_NAME" = "game-infrastructure-base" ]; then
continue
fi
if [[ -z "${only_service}" ]] || [[ ${only_service} =~ (^| )"${SERVICE_NAME}"($| ) ]]; then
echo "Building and deploying ${DOCKERFILE} for ${SERVICE_NAME}"
else
continue
fi
docker build -f "$DOCKERFILE" -t "$SERVICE_NAME" .
docker tag $SERVICE_NAME:latest $REGISTRY/$SERVICE_NAME:latest
if [[ ${do_push} = true ]]; then
docker push $REGISTRY/$SERVICE_NAME:latest
if [[ ${restart_pods} = true ]]; then
echo "Restarting ${SERVICE_NAME} pod"
pod_names=$(kubectl get pod -n default -o=custom-columns=NAME:.metadata.name | egrep ${SERVICE_NAME})
for pod_nm in ${pod_names}; do
echo kubectl delete pod -n default ${pod_nm}
kubectl delete pod -n default ${pod_nm}
done
fi
fi
done
sleep 2
if [[ ${restart_pods} = true ]]; then
kubectl get pod -n default -o=custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,IP:.status.podIP,STATUS:.status.phase
fi