-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·94 lines (81 loc) · 2.23 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
#!/bin/bash
readonly CLI_VERSION="${1:?Error: Please set CLI version}"
readonly REGION="${2:?Error: Please set region}"
readonly AUTH="${3:?Error: Please set your API token}"
readonly APP="${4:?Error: Please set your application name}"
readonly CONTAINER="${5:?Error: Please set your container name}"
readonly IMAGE="${6:?Error: Please set your image like this = image:tag}"
if [ "$7" != "default" ]; then
readonly NS="-n $7"
else
readonly NS=""
fi
print_header() {
printf "%s\n" "* * * * * * * * * * * * * * * * * * * * *"
printf "%s\n" "* *"
printf "%s\n" "* ArvanCloud PaaS/CaaS Action *"
printf "%s\n" "* *"
printf "%s\n" "* * * * * * * * * * * * * * * * * * * * *"
printf "%s\n\n" ""
}
print_error() {
printf " -----> Error: %s\n" "$1"
}
validate_arguments() {
local errors=0
for arg in "$@"; do
if [ -z "$arg" ]; then
print_error "Empty argument"
((errors++))
fi
done
return "$errors"
}
get_data() {
printf " -----> Get data\n"
printf "CLI version: %s\n" "$CLI_VERSION"
printf "API token: %s\n" "$AUTH"
printf "Namespace: %s\n" "$6"
printf "Application name: %s\n" "$APP"
printf "Container name: %s\n" "$CONTAINER"
printf "Image: %s\n" "$IMAGE"
}
create_directory() {
printf " -----> Create service directory\n"
mkdir -p /service
}
download_cli_tool() {
printf " -----> Download ArvanCloud CLI tool version: %s\n" "$CLI_VERSION"
wget -q "https://github.com/arvancloud/cli/releases/download/v${CLI_VERSION}/arvan_${CLI_VERSION}_linux_amd64.tar.gz" -O - | tar -xz -C /service/
}
login() {
printf " -----> Login\n"
printf "$AUTH\n"
{
sleep 2
echo -e "1\n"
sleep 2
echo "$AUTH"
sleep 0.1
} | /service/arvan login
}
deploy() {
printf " -----> Deploy\n"
/service/arvan paas ${NS} set image deployment ${APP} ${CONTAINER}=${IMAGE}
}
cleanup() {
printf " -----> Cleanup\n"
rm -rf /root/.arvan /service
}
main() {
set -e
print_header
validate_arguments "$@" || exit
get_data
create_directory
download_cli_tool
login
deploy
cleanup
}
main "$@"