generated from kameshsampath/gke-tf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yaml
139 lines (122 loc) · 3.79 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
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
# https://taskfile.dev
version: "3"
vars:
TFVARS_FILE: .local.tfvars
# The default namespace where application gets deployed
APP_NAMESPACE: demo-apps
# https://en.wikipedia.org/wiki/IETF_language_tag
LANG: ta
dotenv:
- .env
tasks:
default:
desc: Creates GKE cluster and Deploys the lingua-greeter application
cmds:
- task: create_cluster
- task: deploy_app
silent: true
clean:
desc: Clean all terraform artifacts/assets
silent: true
cmds:
- rm -rf .terraform .terraform.lock.hcl
format:
desc: Format terraform files
silent: true
cmds:
- terraform fmt --recursive {{.ROOT_DIR}} {{.CLI_ARGS}}
init:
desc: Init terraform working directory
silent: true
cmds:
- mkdir -p {{.ROOT_DIR}}/.kube
- terraform init {{.CLI_ARGS}}
validate:
silent: true
deps:
- format
desc: Validate the terraform resources
cmds:
- terraform validate {{.CLI_ARGS}}
create_cluster:
silent: true
deps:
- validate
desc: Create the GKE cluster
cmds:
- terraform apply -var app_use_workload_identity=false -var-file={{.TFVARS_FILE}} {{.CLI_ARGS}}
deploy_app:
silent: true
aliases:
- "deploy"
desc: Deploy the application without workload identity
sources:
- app/config/*.yaml
status:
- |
kubectl rollout status -n demo-apps deployment/lingua-greeter --timeout=60s | grep -q 'deployment "lingua-greeter" successfully rolled out'
cmds:
- kubectl get ns --no-headers | grep -q {{.APP_NAMESPACE}} || kubectl create ns {{.APP_NAMESPACE}}
- kubectl apply -n {{.APP_NAMESPACE}} -k $DEMO_HOME/app/config
- kubectl rollout status -n {{.APP_NAMESPACE}} deployment/lingua-greeter --timeout=60s
- while [ -z $(kubectl get svc -n {{.APP_NAMESPACE}} lingua-greeter -ojsonpath="{.status.loadBalancer.ingress[*].ip}") ]; do sleep .3; done;
use_workload_identity:
silent: true
deps:
- validate
- deploy_app
desc: Make application use Workload Identity
sources:
- rbac.tf
generates:
- k8s/sa.yaml
status:
- |
grep -q 'iam.gke.io/gcp-service-account: "translator@{{.GOOGLE_PROJECT_ID}}.iam.gserviceaccount.com"' k8s/sa.yaml
cmds:
- terraform apply -var-file={{.TFVARS_FILE}} -var app_use_workload_identity=true {{.CLI_ARGS}}
- kubectl apply -n {{.APP_NAMESPACE}} -f k8s/sa.yaml
vars:
GOOGLE_PROJECT_ID:
sh: terraform output -raw project_id
show_service_ip:
desc: Display the lingua-greeter service's LoadBalancer IP
silent: true
deps:
- deploy_app
cmds:
- |
echo "Service IP: {{.SERVICE_IP}}"
echo "Application URL: http://{{.SERVICE_IP}}"
vars:
SERVICE_IP:
sh: kubectl get svc -n {{.APP_NAMESPACE}} lingua-greeter -ojsonpath="{.status.loadBalancer.ingress[*].ip}"
call_service:
desc: Calls the lingua-greeter service
silent: true
cmds:
- curl -s "http://{{.SERVICE_IP}}/{{.LANG}}"
vars:
SERVICE_IP:
sh: kubectl get svc -n demo-apps lingua-greeter -ojsonpath="{.status.loadBalancer.ingress[*].ip}"
app_logs:
desc: Shows the application logs
silent: true
cmds:
- kubectl logs -n {{.APP_NAMESPACE}} -lapp=lingua-greeter
restart_app:
desc: Restarts the kubernetes deployment
silent: true
cmds:
- kubectl rollout restart -n {{.APP_NAMESPACE}} deployment/lingua-greeter
- kubectl rollout status -n {{.APP_NAMESPACE}} deployment/lingua-greeter --timeout=60s
destroy:
silent: true
desc: Destroys terraform resources
cmds:
- terraform destroy -var-file={{.TFVARS_FILE}} {{.CLI_ARGS}}
readme:
desc: Build the README.md
silent: true
cmds:
- terraform-docs {{.ROOT_DIR}} > {{.ROOT_DIR}}/README.md