-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
82 lines (72 loc) · 2.96 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
version: '3'
env:
TITLE: Azure Container Apps Job Demo with Azure SQL
DEFAULT_REGION: canadaeast
FIREWALL: true
tasks:
default:
cmds:
- task --list
up:
desc: Creates the {{.TITLE}} environment and deploys code
cmds:
- terraform -chdir=./infrastructure workspace new {{.REGION}} || true
- terraform -chdir=./infrastructure workspace select {{.REGION}}
- terraform -chdir=./infrastructure init
- task: apply
vars:
REGION: '{{default {{.DEFAULT_REGION}} .CLI_ARGS}}'
apply:
cmds:
- terraform -chdir=./infrastructure apply -auto-approve -var "region={{.REGION}}" -var "deploy_firewall={{.FIREWALL}}" -var "tags={{.TITLE}}"
vars:
REGION: '{{default {{.DEFAULT_REGION}} .CLI_ARGS}}'
build:
desc: Builds application code with Docker
cmds:
- az acr login -n {{.ACR_NAME}}
- az acr build -t sql-job:{{.COMMIT_HASH}} -r {{.ACR_NAME}} src/.
vars:
ACR_NAME:
sh: terraform -chdir=./infrastructure output -raw ACR_NAME
COMMIT_HASH:
sh: git rev-parse HEAD | head -c 8
deploy:
desc: Deploy SQL job app to Container Apps Environment
cmds:
- terraform -chdir=./app workspace new {{.APP_NAME}} || true
- terraform -chdir=./app workspace select {{.APP_NAME}}
- terraform -chdir=./app init
- terraform -chdir=./app apply -auto-approve -var "app_name={{.APP_NAME}}" -var "commit={{.COMMIT_HASH}}"
vars:
APP_NAME:
sh: terraform -chdir=./infrastructure output -raw APP_NAME
COMMIT_HASH:
sh: git rev-parse HEAD | head -c 8
sql:
desc: Setups SQL Server with correct access
cmds:
- bash ./scripts/setup-sql.sh
validate:
desc: Executes the job and displays the logs
cmds:
- az containerapp job start -g {{.RG}} --name {{.APP_NAME}}-sqljob -o table
- echo "Sleeping for 1 minute…"
- sleep 60s
- az containerapp job execution list -g {{.RG}} -n {{.APP_NAME}}-sqljob -o table
- echo "Sleeping for 5 minutes…"
- sleep 300s
- az monitor log-analytics query -w {{.LAW_ID}} --analytics-query "ContainerAppConsoleLogs | where ContainerGroupName startswith '{{.APP_NAME}}-sqljob' | project TimeGenerated, ContainerName, ContainerImage, Log" -o table
vars:
RG:
sh: terraform -chdir=./infrastructure output -raw RESOURCE_GROUP
APP_NAME:
sh: terraform -chdir=./infrastructure output -raw APP_NAME
LAW_ID:
sh: terraform -chdir=./infrastructure output -raw LAW_ID
down:
desc: Destroys all Azure resources and cleans up Terraform
cmds:
- az group list --tag Application={{.TITLE}} --query "[].name" -o tsv | xargs -ot -n 1 az group delete -y --no-wait -n
- cd ./app; rm -rf terraform.tfstate.d .terraform.lock.hcl .terraform terraform.tfstate terraform.tfstate.backup .terraform.tfstate.lock.info
- cd ./infrastructure; rm -rf terraform.tfstate.d .terraform.lock.hcl .terraform terraform.tfstate terraform.tfstate.backup .terraform.tfstate.lock.info