aboutsummaryrefslogtreecommitdiff
path: root/personal_infra/playbooks/roles/takahe/tasks/main.yaml
blob: ed0ab182e082c18823eaf806970dc098ba66f4a8 (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
---
# extra setup:
#
# - create the postgres database
#
#  weed shell
# - s3.configure -access_key=... -secret_key=... -buckets=takahe -user=... -actions=Read,Write,List,Tagging,Admin -apply
# - s3.configure -buckets=takahe -user=anonymous -actions=Read -apply
#
- name: create CNAMEs
  local_action:
    module: amazon.aws.route53
    zone: "{{ takahe.dns_zone }}"
    record: "{{ item }}"
    type: CNAME
    value: "{{ takahe.cnames.target }}"
    wait: true
    state: present
  tags: dns
  loop: "{{ takahe.cnames.domains }}"
- name: create main domain
  local_action:
    module: amazon.aws.route53
    zone: "{{ takahe.dns_zone }}"
    record: "{{ takahe.main_domain.name }}"
    type: "{{ takahe.main_domain.dns_record_type }}"
    value: "{{ takahe.main_domain.target }}"
    wait: true
    state: present
  tags: dns
- name: create namespace
  k8s:
    context: "{{ context }}"
    state: present
    name: "{{ takahe.namespace }}"
    kind: Namespace
  delegate_to: 127.0.0.1
- name: create secret
  k8s:
    context: "{{ context }}"
    state: present
    name: takahe-secrets
    kind: Secret
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
      data:
        TAKAHE_SECRET_KEY: "{{ takahe.secret_key | b64encode }}"
        TAKAHE_EMAIL_SERVER: "{{ ('smtp://' + mail.ses_username + ':' + mail.ses_password + '@' + mail.ses_endpoint + ':25?tls=true') | b64encode }}"
        TAKAHE_MEDIA_BACKEND: "{{ (takahe.s3_proto + '://' + takahe.s3_access_key + ':' + takahe.s3_secret_key + '@' + takahe.s3_endpoint + '/' + takahe.s3_bucket) | b64encode }}"
  delegate_to: 127.0.0.1
- name: create config map
  k8s:
    context: "{{ context }}"
    state: present
    name: takahe-config
    kind: ConfigMap
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
      data:
        PGHOST: "{{ takahe.database_host }}"
        PGUSER: "{{ takahe.database_user }}"
        PGDATABASE: "{{ takahe.database }}"
        TAKAHE_MAIN_DOMAIN: "{{ takahe.main_domain.name }}"
        TAKAHE_EMAIL_FROM: "{{ takahe.email_from }}"
        TAKAHE_USE_PROXY_HEADERS: "true"
        TAKAHE_AUTO_ADMIN_EMAIL: "{{ takahe.admin_email }}"
        TAKAHE_CSRF_HOSTS: "{{ ['https://femto.pub', 'https://alex.femto.pub'] | to_json }}"
        TAKAHE_ERROR_EMAILS: "{{ [takahe.admin_email] | to_json }}"
  delegate_to: 127.0.0.1
- name: create deployment
  k8s:
    context: "{{ context }}"
    state: present
    name: webserver
    kind: Deployment
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
      spec:
        selector:
          matchLabels:
            run: webserver
        template:
          metadata:
            labels:
              run: webserver
          spec:
            containers:
              - name: webserver
                image: "docker.io/avaraline/incarnator:{{ takahe.version }}"
                imagePullPolicy: Always
                args:
                  - "gunicorn"
                  - "takahe.wsgi:application"
                  - "-w"
                  - "6"
                  - "-b"
                  - "0.0.0.0:8000"
                ports:
                  - containerPort: 8000
                envFrom:
                  - configMapRef:
                      name: takahe-config
                  - secretRef:
                      name: takahe-secrets
                livenessProbe:
                  httpGet:
                    path: /
                    port: 8000
                readinessProbe:
                  httpGet:
                    path: /
                    port: 8000
                startupProbe:
                  httpGet:
                    path: /
                    port: 8000
  delegate_to: 127.0.0.1
- name: create service
  k8s:
    context: "{{ context }}"
    state: present
    name: webserver
    kind: Service
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
        labels:
          run: webserver
      spec:
        ports:
          - port: 80
            targetPort: 8000
            name: web
        selector:
          run: webserver
  delegate_to: 127.0.0.1
- name: create ingress
  k8s:
    context: "{{ context }}"
    state: present
    name: webserver
    kind: Ingress
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
      spec:
        rules:
          - host: "{{ takahe.main_domain.name }}"
            http:
              paths:
                - path: /
                  pathType: Prefix
                  backend:
                    service:
                      name: webserver
                      port:
                        name: web
          - host: "*.femto.pub"
            http:
              paths:
                - path: /
                  pathType: Prefix
                  backend:
                    service:
                      name: webserver
                      port:
                        name: web
  delegate_to: 127.0.0.1
- name: create stator deployment
  k8s:
    context: "{{ context }}"
    state: present
    name: stator
    kind: Deployment
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
      spec:
        selector:
          matchLabels:
            run: stator
        template:
          metadata:
            labels:
              run: stator
          spec:
            containers:
              - name: stator
                image: "docker.io/avaraline/incarnator:{{ takahe.version }}"
                imagePullPolicy: Always
                args:
                  - python3
                  - manage.py
                  - runstator
                envFrom:
                  - configMapRef:
                      name: takahe-config
                  - secretRef:
                      name: takahe-secrets
  delegate_to: 127.0.0.1
- name: create migrate job
  k8s:
    context: "{{ context }}"
    state: present
    name: migrate
    kind: Job
    definition:
      metadata:
        namespace: "{{ takahe.namespace }}"
      spec:
        template:
          spec:
            restartPolicy: Never
            containers:
              - name: webserver
                image: "docker.io/avaraline/incarnator:{{ takahe.version }}"
                args: ["python3", "manage.py", "migrate"]
                envFrom:
                  - configMapRef:
                      name: takahe-config
                  - secretRef:
                      name: takahe-secrets
  delegate_to: 127.0.0.1