-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentrypoint.sh
executable file
·187 lines (154 loc) · 4.45 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh -l
set -e o pipefail
# Validate input
[ -z "$INPUT_ACTION" ] && (echo "Missing action" && exit 1)
[ -z "$INPUT_CLUSTER" ] && (echo "Missing Cluster Name" && exit 1)
[ -z "$INPUT_TARGET" ] && (echo "Missing target" && exit 1)
TIMEOUT=${INPUT_TIMEOUT:-300}
CMD="ecs ${INPUT_ACTION} ${INPUT_CLUSTER} ${INPUT_TARGET}"
## Deploy function
deploy_action() {
if [ -n "$INPUT_TAG" ]; then # Deploying a specific tag
CMD="${CMD} -t ${INPUT_TAG}"
elif [ -n "$INPUT_IMAGE" ]; then # Deploying one or more images
rest=$INPUT_IMAGE
while [ -n "$rest" ] ; do
str=${rest%%,*} # Everything up to the first ','
# Trim up to the first ',' -- and handle final case, too.
[ "$rest" = "${rest/,/}" ] && rest= || rest=${rest#*,}
CMD="${CMD} -i $str"
done
elif [ -n "$INPUT_TASK" ]; then # Deploying a specific task definition
CMD="${CMD} --task ${INPUT_TASK}"
fi
}
## Cron function
cron_action() {
[ -z "$INPUT_RULE" ] && (echo "Missing rule" && exit 1)
CMD="${CMD} ${INPUT_RULE}"
if [ -n "$INPUT_TAG" ]; then # Deploying a specific tag
CMD="${CMD} -t ${INPUT_TAG}"
elif [ -n "$INPUT_IMAGE" ]; then # Deploying one or more images
rest=$INPUT_IMAGE
while [ -n "$rest" ] ; do
str=${rest%%,*} # Everything up to the first ','
# Trim up to the first ',' -- and handle final case, too.
[ "$rest" = "${rest/,/}" ] && rest= || rest=${rest#*,}
CMD="${CMD} -i $str"
done
fi
}
## Scale function
scale_action() {
[ -z "$INPUT_SCALE_VALUE" ] && (echo "Missing scale value" && exit 1)
CMD="${CMD} ${INPUT_SCALE_VALUE}"
}
## Run function
run_action() {
CMD="${CMD}"
}
## Update function
update_action() {
CMD="ecs update ${INPUT_TARGET}"
if [ -n "$INPUT_TAG" ]; then # Deploying a specific tag
CMD="${CMD} -t ${INPUT_TAG}"
elif [ -n "$INPUT_IMAGE" ]; then # Deploying one or more images
rest=$INPUT_IMAGE
while [ -n "$rest" ] ; do
str=${rest%%,*} # Everything up to the first ','
# Trim up to the first ',' -- and handle final case, too.
[ "$rest" = "${rest/,/}" ] && rest= || rest=${rest#*,}
CMD="${CMD} -i $str"
done
fi
}
append_common_vars() {
if [ -n "$INPUT_ENV_VARS" ]; then # Env vars
rest=$INPUT_ENV_VARS
while [ -n "$rest" ] ; do
str=${rest%%,*} # Everything up to the first ','
# Trim up to the first ',' -- and handle final case, too.
[ "$rest" = "${rest/,/}" ] && rest= || rest=${rest#*,}
CMD="${CMD} -e $str"
done
fi
if [ "$INPUT_EXCLUSIVE_ENV" = "true" ]; then
CMD="${CMD} --exclusive-env"
fi
if [ -n "$INPUT_SECRETS" ]; then # Secrets
rest=$INPUT_SECRETS
while [ -n "$rest" ] ; do
str=${rest%%,*} # Everything up to the first ','
# Trim up to the first ',' -- and handle final case, too.
[ "$rest" = "${rest/,/}" ] && rest= || rest=${rest#*,}
CMD="${CMD} -s $str"
done
fi
if [ "$INPUT_EXCLUSIVE_SECRETS" = "true" ]; then
CMD="${CMD} --exclusive-secrets"
fi
if [ -n "$INPUT_COMMAND" ]; then # Custom command
CMD="${CMD} --command ${INPUT_COMMAND}"
fi
}
append_deploy_vars() {
if [ -n "$INPUT_TASK_ROLE" ]; then # Task role
CMD="${CMD} -r ${INPUT_TASK_ROLE}"
fi
if [ "$INPUT_IGNORE_WARNINGS" = "true" ]; then
CMD="${CMD} --ignore-warnings"
fi
if [ "$INPUT_NO_DEREGISTER" = "true" ]; then
CMD="${CMD} --no-deregister"
fi
if [ "$INPUT_ROLLBACK" = "true" ]; then
CMD="${CMD} --rollback"
fi
if [ "$INPUT_ACTION" != "cron" ]; then
CMD="${CMD} --timeout ${TIMEOUT}"
fi
}
append_run_vars() {
if [ -n "$INPUT_LAUNCH_TYPE" ]; then # Launch Type
CMD="${CMD} --launchtype=${INPUT_LAUNCH_TYPE}"
fi
if [ -n "$INPUT_SECURITY_GROUP" ]; then # Security Group
CMD="${CMD} --securitygroup ${INPUT_SECURITY_GROUP}"
fi
if [ -n "$INPUT_SUBNET" ]; then # Subnet
CMD="${CMD} --subnet ${INPUT_SUBNET}"
fi
if [ "$INPUT_public_ip" = "true" ]; then
CMD="${CMD} --public-ip"
fi
}
case $INPUT_ACTION in
deploy) # Deployment action
echo "Performing deploy"
deploy_action
append_common_vars
append_deploy_vars
;;
cron) # Cron action
echo "Performing cron"
cron_action
append_common_vars
append_deploy_vars
;;
scale) # Scaling action
echo "Performing scaling"
scale_action
;;
run) # Run action
echo "Performing run"
run_action
append_common_vars
append_run_vars
;;
update) # Update action
echo "Performing update"
update_action
append_common_vars
esac
echo "Command run: ${CMD}"
eval "$CMD"