-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
63 lines (50 loc) · 1.61 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
#!/bin/sh
set -e
if [ -z "$INPUT_KUBECONFIG" ]; then
echo "INPUT_KUBECONFIG is not set. EKS will not be called."
else
if [ -z "$INPUT_AWS_ACCESS_KEY_ID" ]; then
echo "INPUT_AWS_ACCESS_KEY_ID is not set. Quitting."
exit 1
else
INPUT_AWS_ACCESS_KEY_ID=$(echo "${INPUT_AWS_ACCESS_KEY_ID}" | xargs)
fi
if [ -z "$INPUT_AWS_SECRET_ACCESS_KEY" ]; then
echo "INPUT_AWS_SECRET_ACCESS_KEY is not set. Quitting."
exit 1
else
INPUT_AWS_SECRET_ACCESS_KEY=$(echo "${INPUT_AWS_SECRET_ACCESS_KEY}" | xargs)
fi
# Default to us-east-1 if AWS_REGION not set.
if [ -z "$INPUT_AWS_REGION" ]; then
AWS_REGION="us-east-2"
fi
# Create a dedicated profile for this action to avoid conflicts
# with past/future actions.
aws configure --profile github_user <<-EOF > /dev/null 2>&1
${INPUT_AWS_ACCESS_KEY_ID}
${INPUT_AWS_SECRET_ACCESS_KEY}
${INPUT_AWS_REGION}
text
EOF
echo -e "\033[36mSetting up kubectl configuration\033[0m"
mkdir -p ~/.kube/
echo "${INPUT_KUBECONFIG}" > ~/.kube/config
fi
echo -e "\033[36mPreparing kubectl execution\033[0m"
echo "${INPUT_EXEC}" > run.sh
chmod +x ./run.sh
echo -e "\033[36mExecuting kubectl\033[0m"
kubectl_output=$(./run.sh)
echo "$kubectl_output"
mkdir -p _temp
printf "# Kubectl Results\n\n\`\`\`bash\n$kubectl_output\n\`\`\`" > ./_temp/kubectl_output
kubectl_output="${kubectl_output//'%'/'%25'}"
kubectl_output="${kubectl_output//$'\n'/'%0A'}"
kubectl_output="${kubectl_output//$'\r'/'%0D'}"
echo "::set-output name=kubectl_output::$kubectl_output"
echo -e "\033[36mCleaning up: \033[0m"
rm ./run.sh -Rf
echo -e "\033[36m - exec ✅ \033[0m"
rm ~/.kube/config -Rf
echo -e "\033[36m - kubeconfig ✅ \033[0m"