-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yaml
93 lines (79 loc) · 3.06 KB
/
Taskfile.yaml
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
version: '3'
env:
BASE_DIR: ./config
RELEASES_DIR: ./charts
OUTPUT_DIR: "output"
VALUES_FILE: "vendir.ytt.yml"
TEMPLATE_FILE: "vendir.yml"
CUSTOM: no
tasks:
generate_and_sync:
desc: Generate and sync files using vendir and ytt
silent: true
cmds:
- "if ! command -v ytt &> /dev/null; then echo 'Error: ytt is not installed. Please install ytt before running this script.'; exit 1; fi"
- "if ! command -v vendir &> /dev/null; then echo 'Error: vendir is not installed. Please install vendir before running this script.'; exit 1; fi"
- "ytt -f \"$TEMPLATE_FILE\" -f \"$VALUES_FILE\" --output-files \"$OUTPUT_DIR\""
- "if [ ! -d \"$OUTPUT_DIR\" ]; then echo 'Error: Failed to generate the output file.'; exit 1; fi"
- "vendir sync -f \"$OUTPUT_DIR\"/vendir.yml"
- "rm -rf \"$OUTPUT_DIR\""
deploy:
desc: Deploy a Helm chart
silent: true
cmds:
- task: validate_chart
- task: deploy_chart
deploy_custom_k8s:
desc: Deploy a Helm chart
silent: true
cmds:
- task: deploy_custom
upgrade:
desc: upgrade a Helm chart
silent: true
cmds:
- task: validate_chart
- task: upgrade_chart
wait:
cmds:
- sleep 10
wait_k8s_custom:
cmds:
- sleep 60
uninstall:
desc: uninstall a Helm chart
silent: true
cmds:
- task: delete_chart
- task: wait
- task: remove_namespace
validate_chart:
desc: Validate a Helm chart
cmds:
- helm lint "${BASE_DIR}/${CHART_NAME}"
deploy_chart:
desc: Deploy a Helm chart
vars:
DEFAULT: ${CHART_NAME}/${CHART_NAME}
cmds:
- bash -c "vals eval -f ${RELEASES_DIR}/${CHART_NAME}/values.yaml > ${RELEASES_DIR}/${CHART_NAME}/${CHART_NAME}.yaml"
- helm install --create-namespace --namespace "$(basename ${BASE_DIR}/${CHART_NAME})" "$(basename ${BASE_DIR}/${CHART_NAME})" $DEFAULT -f "${BASE_DIR}/${CHART_NAME}/values.yaml" -f "${RELEASES_DIR}/${CHART_NAME}/${CHART_NAME}.yaml"
- rm "${RELEASES_DIR}/${CHART_NAME}/${CHART_NAME}.yaml"
deploy_custom:
desc: deploy custom k8s resources
cmds:
- "if [ -d \"${RELEASES_DIR}/${CHART_NAME}/k8s\" ]; then kubectl apply -f ${RELEASES_DIR}/${CHART_NAME}/k8s/. --namespace $(basename ${BASE_DIR}/${CHART_NAME}) ; fi"
upgrade_chart:
desc: upgrading an existing chart ${CHART_NAME}/${CHART_NAME}
cmds:
- bash -c "vals eval -f ${RELEASES_DIR}/${CHART_NAME}/values.yaml > ${RELEASES_DIR}/${CHART_NAME}/${CHART_NAME}.yaml"
- helm upgrade --force --namespace "$(basename ${BASE_DIR}/${CHART_NAME})" "$(basename ${BASE_DIR}/${CHART_NAME})" $DEFAULT -f "${BASE_DIR}/${CHART_NAME}/values.yaml" -f "${RELEASES_DIR}/${CHART_NAME}/${CHART_NAME}.yaml"
- rm "${RELEASES_DIR}/${CHART_NAME}/${CHART_NAME}.yaml"
delete_chart:
desc: Delete chart
cmds:
- helm uninstall "$(basename ${BASE_DIR}/${CHART_NAME})" --namespace "$(basename ${BASE_DIR}/${CHART_NAME})"
remove_namespace:
desc: remove namespace
cmds:
- kubectl delete ns "$(basename ${BASE_DIR}/${CHART_NAME})"