Skip to content

Commit fae3976

Browse files
committed
Provision GlitchTip configuration
Use the GlitchTip API to provision some default configuration based on the defined hosts in Ansible.
1 parent 6e01b69 commit fae3976

File tree

5 files changed

+179
-1
lines changed

5 files changed

+179
-1
lines changed

provision-contest/ansible/group_vars/onprem/secret.yml.example

+1
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ PRESCLIENT_CONTEST: nwerc18
7272

7373
# GlitchTip
7474
# GLITCHTIP_SECRET: {some-strong-glitchtip-password}
75+
# GLITCHTIP_PASSWORD: {some-strong-glitchtip-password}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
GLITCHTIP_PORT: 8000
2+
GLITCHTIP_TOKEN:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
- name: Fetch the project id
3+
ansible.builtin.uri:
4+
method: GET
5+
return_content: yes
6+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/teams/domjudge/DOMjudge/projects/"
7+
headers:
8+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
9+
register: glitchtip_proj
10+
- set_fact:
11+
TEMP_QUERY0: "[?name=='{{ item }}'].id"
12+
- ansible.builtin.uri:
13+
method: POST
14+
return_content: yes
15+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/monitors/"
16+
status_code: 201
17+
headers:
18+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
19+
body:
20+
expectedBody: ""
21+
expectedStatus: 200
22+
timeout: 5
23+
interval: 2
24+
monitorType: "GET"
25+
url: "https://{{ hostvars[item].ansible_host }}/public"
26+
name: "{{ item }}"
27+
project_id: "{{ glitchtip_proj.json | community.general.json_query(TEMP_QUERY0) | first }}"
28+
body_format: json

provision-contest/ansible/roles/glitchtip/tasks/main.yml

+148
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,151 @@
1515
project_src: /opt/glitchtip
1616
files:
1717
- docker-compose.yaml
18+
19+
- name: Assume we don't have an account if we didn't specify the token
20+
when: not GLITCHTIP_TOKEN
21+
block:
22+
- name: Wait for stable GlitchTip migrations
23+
ansible.builtin.wait_for:
24+
timeout: 10
25+
- name: Fetch CSRF from login page
26+
ansible.builtin.uri:
27+
method: GET
28+
return_content: yes
29+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/docs"
30+
register: glitchtip_csrf
31+
32+
- name: Register DOMjudge account
33+
ansible.builtin.uri:
34+
method: POST
35+
return_content: yes
36+
url: "http://localhost:{{ GLITCHTIP_PORT }}/_allauth/browser/v1/auth/signup"
37+
status_code: 200
38+
headers:
39+
Cookie: "{{ glitchtip_csrf.cookies_string }}"
40+
X-CSRFTOKEN: "{{ glitchtip_csrf.cookies_string | regex_search('csrftoken=([a-zA-Z0-9]+)', '\\1') | first }}"
41+
body:
42+
43+
password: "{{ GLITCHTIP_PASSWORD }}"
44+
body_format: json
45+
register: glitchtip_register
46+
47+
- name: Create API token
48+
ansible.builtin.uri:
49+
method: POST
50+
return_content: yes
51+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/api-tokens/"
52+
status_code: 201
53+
headers:
54+
Cookie: "{{ glitchtip_register.cookies_string }}"
55+
X-CSRFTOKEN: "{{ glitchtip_register.cookies_string | regex_search('csrftoken=([a-zA-Z0-9]+)', '\\1') | first }}"
56+
body:
57+
label: "ansible"
58+
scopes: [
59+
"project:read",
60+
"project:write",
61+
"project:admin",
62+
"project:releases",
63+
"team:read",
64+
"team:write",
65+
"team:admin",
66+
"event:read",
67+
"event:write",
68+
"event:admin",
69+
"org:read",
70+
"org:write",
71+
"org:admin",
72+
"member:read",
73+
"member:write",
74+
"member:admin"
75+
]
76+
body_format: json
77+
register: glitchtip_token
78+
79+
- name: Set API token
80+
ansible.builtin.set_fact:
81+
GLITCHTIP_TOKEN: "{{ glitchtip_token.json.token }}"
82+
83+
- name: Check for existing organizations
84+
ansible.builtin.uri:
85+
method: GET
86+
return_content: yes
87+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/"
88+
headers:
89+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
90+
register: glitchtip_org
91+
92+
- name: Create DOMjudge organization
93+
when: glitchtip_org.json | community.general.json_query("[?name=='DOMjudge']") == []
94+
ansible.builtin.uri:
95+
method: POST
96+
return_content: yes
97+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/"
98+
status_code: 201
99+
headers:
100+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
101+
body:
102+
name: "DOMjudge"
103+
body_format: json
104+
register: glitchtip_org
105+
106+
- name: Check for existing teams
107+
ansible.builtin.uri:
108+
method: GET
109+
return_content: yes
110+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/teams/"
111+
headers:
112+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
113+
register: glitchtip_team
114+
115+
- name: Create DOMjudge team
116+
when: glitchtip_team.json | community.general.json_query("[?slug=='DOMjudge']") == []
117+
ansible.builtin.uri:
118+
method: POST
119+
return_content: yes
120+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/teams/"
121+
status_code: 201
122+
headers:
123+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
124+
body:
125+
slug: "DOMjudge"
126+
body_format: json
127+
register: glitchtip_team
128+
129+
- name: Check for existing projects
130+
ansible.builtin.uri:
131+
method: GET
132+
return_content: yes
133+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/teams/domjudge/DOMjudge/projects/"
134+
headers:
135+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
136+
register: glitchtip_proj
137+
138+
- name: Create DOMjudge projects
139+
when: glitchtip_proj.json | community.general.json_query("[?name=='{{ item }}']") == []
140+
ansible.builtin.uri:
141+
method: POST
142+
return_content: yes
143+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/teams/domjudge/DOMjudge/projects/"
144+
status_code: 201
145+
headers:
146+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
147+
body:
148+
name: "{{ item }}"
149+
platform: "php-symfony"
150+
body_format: json
151+
loop: "{{ ['setup-phase'] + groups['domserver'] }}"
152+
153+
- name: Check for existing monitors
154+
ansible.builtin.uri:
155+
method: GET
156+
return_content: yes
157+
url: "http://localhost:{{ GLITCHTIP_PORT }}/api/0/organizations/domjudge/monitors/"
158+
headers:
159+
Authorization: "Bearer {{ GLITCHTIP_TOKEN }}"
160+
register: glitchtip_mon
161+
162+
- name: Create DOMjudge monitors
163+
when: glitchtip_mon.json | community.general.json_query("[?name=='{{ item }}']") == []
164+
loop: "{{ groups['domserver'] }}"
165+
include_tasks: create-monitor.yml

provision-contest/ansible/roles/glitchtip/templates/docker-compose.yaml.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ x-environment:
44
&default-environment
55
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
66
SECRET_KEY: {{ GLITCHTIP_SECRET }}
7-
PORT: {{ GLITCHTIP_PORT}}
7+
PORT: {{ GLITCHTIP_PORT }}
88
EMAIL_URL: consolemail://
99
GLITCHTIP_DOMAIN: http://glitchtip:{{ GLITCHTIP_PORT }}
1010
DEFAULT_FROM_EMAIL: email@glitchtip

0 commit comments

Comments
 (0)