-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo
executable file
·84 lines (68 loc) · 2.06 KB
/
go
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
#!/usr/bin/env bash
set -eo pipefail
help() {
echo "Usage: go <command>"
echo
echo " help Print this help"
echo
echo "Common commands: "
echo " dev Start development using dev env files"
echo " test Run all unit tests"
echo " start Start with prod env files"
exit 0
}
dev () {
echo -e "Starting dev"
# locally expand the configuration in the dev.env into process.env
export $(cat config/dev.env | xargs)
NODE_ENV=development node index.js
}
build () {
echo -e "Building the docker image to be deployed"
docker build -t nodeapp .
}
start () {
echo -e "Starting start"
# in a prod environment, we expect the envs to be
# provided by config-maps not by export $(cat config/prod.env | xargs)
NODE_ENV=production node index.js
}
create-config-map () {
env_file="config/$1.env"
echo "Generating config map from ---- > $env_file"
kubectl create configmap nodeapp-config --from-env-file $env_file \
--dry-run -o yaml |\
kubectl apply -f -
}
# deploy to cluster
deploy () {
echo -e "Starting deployment"
build
# generate the config map for prod environment
# the config must be generated before deploying the app
create-config-map "prod"
# deploy the app using the new created/updated config map
kubectl apply -f k8-config.yml
# wait to see that all deployment has succeded
kubectl rollout status deployment/nodeapp
}
# local kubernettes deployment token
local-k8-admin () {
# generate a token for the local k8-dashboard app
# see https://github.com/kubernetes/dashboard/wiki/Creating-sample-user
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | \
grep admin-user | \
awk '{print $1}')
}
# forward the local port into the cluster
port-forward () {
kubectl port-forward deployment/nodeapp 8080:8080
}
if [[ $1 =~ ^(dev|start|test|deploy|local-k8-admin|port-forward)$ ]]; then
COMMAND=$1
shift
$COMMAND "$@"
else
help
exit 1
fi