forked from charbonnierg/lxx-iac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
143 lines (126 loc) · 3.81 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
---
version: "3"
dotenv: [".env", "{{.HOME}}/.env"]
vars:
DO_PAT: '{{.DO_PAT | default ""}}'
DO_SSH_KEY_NAME: '{{.DO_SSH_KEY_NAME | default "" }}'
DO_DOMAIN_NAME: '{{.DO_DOMAIN_NAME | default "lxx.quest"}}'
DOMAIN_NAME: "{{.DOMAIN_NAME | default .DO_DOMAIN_NAME}}"
ACCOUNT_EMAIL: '{{.ACCOUNT_EMAIL | default "[email protected]" }}'
DROPLET_SIZE: '{{.DROPLET_SIZE | default "s-1vcpu-1gb"}}'
DROPLET_NAME: '{{.DROPLET_NAME | default "lxx-01"}}'
DB_NAME: '{{.DB_NAME | default "gnt" }}'
DO_REGION: '{{.DO_REGION | default "fra1"}}'
DB_CLUSTER_NAME: '{{.DB_CLUSTER_NAME | default "lxx-cluster"}}'
DB_CLUSTER_SIZE: '{{.DB_CLUSTER_SIZE | default "db-s-1vcpu-1gb" }}'
GIT_REPO: '{{.GIT_REPO | default "https://github.com/SphRbtHyk/lxx-iac.git" }}'
PRIVATE_KEY_FILE:
sh: echo "$HOME/.ssh/id_rsa"
tasks:
debug:
cmds:
- echo {{.DOMAIN_NAME}}
- echo {{.DO_DOMAIN_NAME}}
init:
dir: tf/
cmds:
- terraform init
plan:
dir: tf/
cmds:
- mkdir -p .plans/
- |
terraform plan \
-var "do_token={{.DO_TOKEN}}" \
-var "domain_name={{.DO_DOMAIN_NAME}}" \
-var "domain={{.DOMAIN_NAME}}" \
-var "account_email={{.ACCOUNT_EMAIL}}" \
-var "ssh_key_name={{.DO_SSH_KEY_NAME}}" \
-var "ssh_private_key={{.PRIVATE_KEY_FILE}} " \
-var "droplet_size={{.DROPLET_SIZE}}" \
-var "droplet_name={{.DROPLET_NAME}}" \
-var "db_name={{.DB_NAME}}" \
-var "db_cluster_size={{.DB_CLUSTER_SIZE}}" \
-var "db_cluster_name={{.DB_CLUSTER_NAME}}" \
-var "region={{.DO_REGION}}" \
-var "git_repo={{.GIT_REPO}}" \
-out .plans/deploy
destroy:
dir: tf/
cmds:
- |
terraform apply -destroy \
-auto-approve \
-var "do_token={{.DO_TOKEN}}" \
-var "domain_name={{.DO_DOMAIN_NAME}}" \
-var "domain={{.DOMAIN_NAME}}" \
-var "account_email={{.ACCOUNT_EMAIL}}" \
-var "ssh_key_name={{.DO_SSH_KEY_NAME}}" \
-var "ssh_private_key={{.PRIVATE_KEY_FILE}} " \
-var "droplet_size={{.DROPLET_SIZE}}" \
-var "droplet_name={{.DROPLET_NAME}}" \
-var "db_cluster_size={{.DB_CLUSTER_SIZE}}" \
-var "db_name={{.DB_NAME}}" \
-var "db_cluster_name={{.DB_CLUSTER_NAME}}" \
-var "region={{.DO_REGION}}" \
-var "git_repo={{.GIT_REPO}}"
apply:
dir: tf/
cmds:
- terraform apply .plans/deploy
show-droplet:
dir: tf/
cmds:
- terraform state show 'digitalocean_droplet.lxx-droplet'
show-ip:
cmds:
- echo "{{.ipv4}}"
vars:
ipv4:
sh: task show-droplet | grep ipv4 | cut -d '"' -f2 | head -n 1
clean:
dir: tf/
cmds:
- rm -Rf .plans/
- rm -Rf .terraform/
- rm -f terraform.tfstate terraform.tfstate.backup
doc:
cmds:
- terraform-docs markdown tf > tf/README.md
reset:
cmds:
- task: destroy
- task: plan
- task: apply
ssh:
cmds:
- ssh lxx@{{.target}}
vars:
target:
sh: task show-ip
interactive: true
watch-cloud-init:
cmds:
- ssh root@{{.target}} tail -f /var/log/cloud-init-output.log
vars:
target:
sh: task show-ip
interactive: true
check-cert:
cmds:
- curl --resolve traefik.{{.DOMAIN_NAME}}:443:{{.target}} -iIv https://traefik.{{.DOMAIN_NAME}}/dashboard/#/ 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }'
vars:
target:
sh: task show-ip
tunnel-jupyter:
cmds:
- ssh -N -L 8888:localhost:10080 lxx@{{.target}}
vars:
target:
sh: task show-ip
code:
cmds:
- code --folder-uri vscode-remote://ssh-remote+lxx@{{.target}}/home/lxx
vars:
target:
sh: task show-ip