-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
99 lines (84 loc) · 2.3 KB
/
entrypoint.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
#!/bin/sh
NOMAD_VERSION="1.8.4"
if [ -z "$NOMAD_JOB" ];
then
if [ -z "$NOMAD_JOB_NAME" ];
then
echo "NOMAD_JOB or NOMAD_JOB_NAME variable requiered."
exit 2
else
NOMAD_JOB=$NOMAD_JOB_NAME
fi
fi
if [ -z "$NOMAD_ADDR" ];
then
echo -e "NOMAD_ADDR variable not set.\nUsing default value: http://127.0.0.1"
NOMAD_ADDR="http://127.0.0.1"
fi
if [ -z "$NOMAD_PORT" ];
then
echo -e "NOMAD_PORT variable not set.\nUsing default value: 4646"
NOMAD_PORT="4646"
fi
# if no nomad action is set use run as default
if [ -z "$NOMAD_ACTION" ];
then
echo -e "NOMAD_ACTION variable not set.\nUsing default value: run"
NOMAD_ACTION="run"
fi
# If the action is set to run replace the nomad job with the path + the job name
if [ "$NOMAD_ACTION" == "run" ];
then
NOMAD_JOB="${GITHUB_WORKSPACE}/${NOMAD_JOB}"
fi
if [ ${purge} ];
then
FLAGS="${FLAGS} -purge"
fi
if [ -z $namespace ];
then
FLAGS="${FLAGS} -namespace=${namespace}"
fi
if [ -z $region];
then
FLAGS="${FLAGS} -region=${region}"
fi
if [ -z $token];
then
FLAGS="${FLAGS} -token=${token}"
fi
if [ ${detach} ];
then
FLAGS="${FLAGS} -detach"
fi
if ! command -v nomad &> /dev/null
then
echo -e "Installing nomad..."
curl -sS https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip -o nomad.zip && \
unzip -qq nomad.zip && \
mv nomad /usr/local/bin/ && \
rm nomad.zip
echo -e "Installed:" $(nomad version)
fi
echo -e "NOMAD_ADDR:" $NOMAD_ADDR "\nNOMAD_PORT:" $NOMAD_PORT "\nNOMAD_JOB:" $NOMAD_JOB"\nNOMAD_ACTION:" $NOMAD_ACTION
NOMAD_ADDR=${NOMAD_ADDR}:${NOMAD_PORT} nomad job ${NOMAD_ACTION} $FLAGS $NOMAD_JOB
RESULT="$?"
# check if job was rolled back
if [ "$RESULT" == "0" ]; then
NOMAD_ROLLBACK=$(echo "${NOMAD_RESULT}" | sed '/rolling back to job/h; ${p;x;/./Q3;Q0}')
RESULT="$?"
fi
# check result of nomad job $NOMAD_ACTION
if [ "$RESULT" == "1" ]; then
echo -e "nomad exit Code:" $RESULT "\n[ERROR] FAILED to deploy job"
exit 1
elif [ "$RESULT" == "3" ]; then
echo -e "nomad exit Code:" $RESULT "\n[ERROR] Job rolled back after failed deployment"
exit 1
elif [ "$RESULT" == "2" ]; then
echo -e "nomad exit Code:" $RESULT "\n[WARN] RESOURCE EXHAUSTION detected.\n[WARN] Please verify your job in the nomad UI"
exit 0
else
echo "SUCCESSFULL deploy nomad job"
exit 0
fi