-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
147 lines (131 loc) · 5.48 KB
/
Taskfile.yml
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
version: '3'
# Global Variables
vars:
CLUSTER_NAME: 'apps-demo-cluster'
REMOVE_APPS: 'metrics-server,traefik2-nodeport'
RESULT_FILE: '/tmp/'
KUBE_VERSION: '' # Empty means the default version will be used
APP_LIST_PATH: './app_list.txt' # Path to your app list file
KUBECONFIG_PATH: '/tmp/kubeconfig_{{.CLUSTER_NAME}}'
tasks:
setup-tools:
desc: 'Ensure Civo CLI and kubectl are installed and set up.'
cmds:
- cmd: |
# Install Civo CLI
if ! command -v civo &> /dev/null; then
echo "Civo CLI not found, installing..."
curl -sL https://civo.com/get | sh
else
echo "Civo CLI is already installed."
fi
# Set up Civo API Key
civo apikey add mykey "${CIVO_API_KEY}"
# Install kubectl
if ! command -v kubectl &> /dev/null; then
echo "kubectl not found, installing..."
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mv ./kubectl /usr/local/bin/kubectl
else
echo "kubectl is already installed."
fi
silent: false
deploy-and-test-apps:
desc: 'Read apps from app_list.txt and deploy/test each one.'
cmds:
- cmd: |
APPS=$(cat "{{.APP_LIST_PATH}}")
for APP_NAME in $APPS; do
echo $APP_NAME
task deploy-app APP_NAME="$APP_NAME"
task get-kubeconfig
task check-app-status APP_NAME="$APP_NAME"
task delete-cluster
done
silent: false
deploy-app:
desc: 'Deploy an app by creating a Civo Kubernetes cluster and installing the app.'
cmds:
- cmd: |
echo "hello"
echo {{.APP_NAME}}
version_cmd=""
if [ -n "{{.KUBE_VERSION}}" ]; then
version_cmd="--version {{.KUBE_VERSION}}"
fi
civo kubernetes create "{{.CLUSTER_NAME}}" --region=FRA1 --nodes=3 --applications="{{.APP_NAME}}" --remove-applications="{{.REMOVE_APPS}}" $version_cmd --wait
vars:
APP_NAME: '{{.APP_NAME}}'
get-kubeconfig:
desc: 'Retrieve kubeconfig for the created cluster, retrying for up to 3 minutes if necessary.'
cmds:
- cmd: |
sleep 30
end=$(date +%s)
end=$((end + 180)) # 3 minutes from now
while true; do
echo "Attempting to retrieve kubeconfig..."
if civo --region FRA1 kubernetes config "{{.CLUSTER_NAME}}" > "{{.KUBECONFIG_PATH}}"; then
echo "Kubeconfig retrieved successfully and saved to "{{.KUBECONFIG_PATH}}"."
break
else
echo "Failed to retrieve kubeconfig, retrying in 10 seconds..."
sleep 10
fi
now=$(date +%s)
if [ "$now" -ge "$end" ]; then
echo "Failed to retrieve kubeconfig within the time limit."
exit 1
fi
done
silent: false
check-app-status:
desc: 'Check the status of the app deployment job and include Kubernetes version in the results.'
cmds:
- cmd: |
echo "{{.RESULT_FILE}} result file"
echo " {{.APP_NAME}} saiyam"
start_time=$(date +%s)
job_found=false
while true; do
echo $(kubectl --kubeconfig "{{.KUBECONFIG_PATH}}" get jobs -n default -o name)
job_name=$(kubectl --kubeconfig "{{.KUBECONFIG_PATH}}" get jobs -n default -o name | grep "{{.APP_NAME}}" | sed 's|job.batch/||')
if [ -n "$job_name" ]; then
job_found=true
echo "Job found for {{.APP_NAME}}: $job_name, checking status..."
echo "hello {{.APP_NAME}}"
echo "hello $job_name"
succeeded=$(kubectl --kubeconfig "{{.KUBECONFIG_PATH}}" get job $job_name -n default -o jsonpath='{.status.succeeded}')
failed=$(kubectl --kubeconfig "{{.KUBECONFIG_PATH}}" get job $job_name -n default -o jsonpath='{.status.failed}')
if [[ "$succeeded" == "1" ]]; then
echo "{{.APP_NAME}} on Kubernetes Version {{.KUBE_VERSION}}: SUCCESS" >> "{{.RESULT_FILE}}/{{.APP_NAME}}.txt"
break
elif [[ "$failed" == "1" ]]; then
echo "{{.APP_NAME}} on Kubernetes Version {{.KUBE_VERSION}}: FAILED" >> "{{.RESULT_FILE}}/{{.APP_NAME}}.txt"
pod_name=$(kubectl --kubeconfig "{{.KUBECONFIG_PATH}}" get pod -l job-name="$job_name" -n default -o jsonpath='{.items[0].metadata.name}')
if [ -n "$pod_name" ]; then
echo "Fetching logs from failed pod: $pod_name"
kubectl --kubeconfig "{{.KUBECONFIG_PATH}}" logs "$pod_name" -n default >> "{{.RESULT_FILE}}/{{.APP_NAME}}.txt"
fi
break
fi
else
echo "Checking for job creation..."
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ $elapsed_time -ge 300 ]; then
echo "{{.APP_NAME}} on Kubernetes Version {{.KUBE_VERSION}}: Job not found or did not complete within 5 minutes" >> "{{.RESULT_FILE}}/{{.APP_NAME}}"
break
fi
sleep 10
done
silent: false
vars:
APP_NAME: '{{.APP_NAME}}'
delete-cluster:
desc: 'Delete the Civo Kubernetes cluster.'
cmds:
- civo --region FRA1 kubernetes delete "{{.CLUSTER_NAME}}" -y
silent: false