Skip to content

Commit f156348

Browse files
nickygerritsenvmcj
andcommitted
Add CDS role to Ansible.
Co-authored-by: MCJ Vasseur <[email protected]>
1 parent 7432f03 commit f156348

File tree

11 files changed

+271
-2
lines changed

11 files changed

+271
-2
lines changed

icpc-wf/ansible/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ default:
55
@echo " - make judgehost"
66
@echo " - make admin"
77
@echo " - make grafana"
8+
@echo " - make cds"
89

910
LIBVENDORTGZ=roles/domjudge_checkout/files/lib-vendor.tgz
1011
SSHKEY=roles/ssh/files/id_rsa
@@ -21,7 +22,7 @@ $(LIBVENDOR): $(LIBVENDORTGZ)
2122
-cd roles/domjudge_checkout/files && tar xzf $(notdir $<)
2223
endif
2324

24-
domserver judgehost admin grafana: %: %.yml hosts group_vars/all/secret.yml $(LIBVENDOR) $(SSHKEY) $(SSHKEY).pub
25+
domserver judgehost admin grafana cds: %: %.yml hosts group_vars/all/secret.yml $(LIBVENDOR) $(SSHKEY) $(SSHKEY).pub
2526
ansible-playbook -i hosts $<
2627

2728
admin: $(SSL_LOCALHOST_FILES)
@@ -45,4 +46,4 @@ distclean: clean
4546
rm -f $(SSL_LOCALHOST_FILES)
4647
rm -f $(SSL_GRAFANA_FILES)
4748

48-
.PHONY: default clean distclean domserver judgehost admin grafana
49+
.PHONY: default clean distclean domserver judgehost admin grafana cds

icpc-wf/ansible/cds.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
# This playbook installs the CDS
3+
4+
- name: setup CDS
5+
hosts: cds
6+
vars:
7+
host_type: cds
8+
become: yes
9+
roles:
10+
- role: base_packages
11+
tags: base_packages
12+
- role: icpc_fixes
13+
tags: icpc_fixes
14+
when: ICPC_IMAGE
15+
- role: system_fixes
16+
tags: system_fixes
17+
- role: hosts
18+
tags: hosts
19+
- role: ssl
20+
tags: ssl
21+
when: CDS_HOSTNAME
22+
vars:
23+
INSTALL_SSL_PRIVATE_KEYS: true
24+
- role: domjudge_user
25+
tags: domjudge_user
26+
- role: ssh
27+
tags: ssh
28+
- role: cds
29+
tags: cds

icpc-wf/ansible/group_vars/all/all.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ PHPSTORM_VERSION: 2021.2
4646
PHPSTORM_FULL_VERSION: 212.5284.49
4747

4848
GRAFANA_MONITORING: false
49+
50+
# Hostname of the CDS. If set, will add an nginx in front of the CDS
51+
# If not set, will only expose CDS directly
52+
CDS_HOSTNAME: cds
53+
54+
# CDS SSL cert and key. Only needed when CDS_HOSTNAME is set
55+
CDS_SSL_CERT: /etc/ssl/certs/cds.crt
56+
CDS_SSL_KEY: /etc/ssl/private/cds.key

icpc-wf/ansible/group_vars/all/secret.yml.example

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,34 @@ ADMIN_PASSWORD: some-admin-password
1717
# Set this to enable a password on the 'domjudge' shell accounts
1818
# created on the domserver and judgehosts.
1919
#DJ_SHELL_USER_PW: some-hashed-password
20+
21+
# Users to create when setting up the CDS
22+
CDS_USERS:
23+
- username: admin
24+
password: adm1n
25+
- username: presAdmin
26+
password: padm1n
27+
- username: blue
28+
password: blu3
29+
- username: balloon
30+
password: balloonPr1nter
31+
- username: public
32+
password: publ1c
33+
- username: presentation
34+
password: presentat1on
35+
- username: myicpc
36+
password: my1cpc
37+
- username: live
38+
password: l1ve
39+
- username: team1
40+
password: t3am
41+
42+
# Contest(s) to configure in the CDS
43+
CDS_CONTESTS:
44+
- path: nwerc18 # Path in the contest directory
45+
ccs:
46+
id: nwerc18 # ID of the contest if hosted at DOMJUDGE_URL
47+
# Or provide a absolute URL
48+
# url: https://www.domjudge.org/demoweb/api/contests/nwerc18
49+
username: admin
50+
password: admin

icpc-wf/ansible/hosts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ domjudge-ccsadmin5 ansible_host=10.3.3.227
3535

3636
[grafana]
3737
domjudge-prometheus ansible_host=10.3.3.223
38+
39+
[cds]
40+
domjudge-cds ansible_host=10.2.2.228
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=CDS
3+
[Service]
4+
User=domjudge
5+
Restart=always
6+
ExecStart=/home/domjudge/cds/wlp/bin/server run cds
7+
TimeoutStopSec=20s
8+
[Install]
9+
WantedBy=multi-user.target
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# Define here handlers associated to this role.
3+
4+
- name: restart systemctl
5+
shell: systemctl daemon-reload
6+
7+
- name: restart cds
8+
service: name=cds enabled=yes state=restarted
9+
10+
- name: restart nginx
11+
service: name=nginx enabled=yes state=restarted
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
# These tasks configure the CDS
3+
4+
- name: Get the latest CDS release
5+
uri:
6+
url: https://api.github.com/repos/icpctools/icpctools/releases/latest
7+
method: GET
8+
return_content: yes
9+
status_code: 200
10+
body_format: json
11+
register: latest_cds_release
12+
13+
- name: Set CDS latest version
14+
set_fact:
15+
cds_version: "{{ latest_cds_release.json.name | replace('v', '') }}"
16+
17+
- name: Check if CDS is installed
18+
stat:
19+
path: /home/domjudge/cds/wlp/usr/servers/cds/apps/CDS.war
20+
register: cds_war
21+
22+
- name: create CDS directory
23+
file:
24+
path: /home/domjudge/cds
25+
state: directory
26+
owner: domjudge
27+
group: domjudge
28+
mode: 0755
29+
30+
- name: Download and unpack full CDS
31+
unarchive:
32+
src: https://github.com/icpctools/icpctools/releases/download/v{{ cds_version }}/wlp.CDS-{{ cds_version }}.zip
33+
dest: /home/domjudge/cds
34+
remote_src: true
35+
owner: domjudge
36+
group: domjudge
37+
when: not cds_war.stat.exists
38+
notify: restart cds
39+
40+
- name: Download and unpack CDS WAR
41+
unarchive:
42+
src: https://github.com/icpctools/icpctools/releases/download/v{{ cds_version }}/CDS-{{ cds_version }}.zip
43+
dest: /root
44+
remote_src: true
45+
when: cds_war.stat.exists
46+
47+
- name: Copy new CDS war
48+
copy:
49+
src: /root/CDS-2.3/CDS.war
50+
dest: /home/domjudge/cds/wlp/usr/servers/cds/apps/CDS.war
51+
remote_src: yes
52+
owner: domjudge
53+
group: domjudge
54+
when: cds_war.stat.exists
55+
notify: restart cds
56+
57+
- name: Populate CDS users.xml
58+
template:
59+
src: users.xml.j2
60+
dest: /home/domjudge/cds/wlp/usr/servers/cds/users.xml
61+
owner: domjudge
62+
group: domjudge
63+
mode: 0600
64+
notify: restart cds
65+
66+
- name: Populate CDS cdsConfig.xml
67+
template:
68+
src: cdsConfig.xml.j2
69+
dest: /home/domjudge/cds/wlp/usr/servers/cds/config/cdsConfig.xml
70+
owner: domjudge
71+
group: domjudge
72+
mode: 0600
73+
notify: restart cds
74+
75+
- name: Create contests config directory
76+
file:
77+
path: /home/domjudge/cds/contests
78+
state: directory
79+
owner: domjudge
80+
group: domjudge
81+
mode: 0755
82+
83+
- name: Create contest specific directory
84+
file:
85+
path: /home/domjudge/cds/contests/{{ item.path }}
86+
state: directory
87+
owner: domjudge
88+
group: domjudge
89+
mode: 0755
90+
loop: "{{ CDS_CONTESTS }}"
91+
92+
- name: copy cds systemd unit file
93+
copy:
94+
src: cds.service
95+
dest: /etc/systemd/system/
96+
notify:
97+
- restart systemctl
98+
- restart cds
99+
100+
- name: Setup nginx
101+
block:
102+
- name: install nginx
103+
apt:
104+
state: present
105+
pkg:
106+
- nginx
107+
108+
- name: add CDS nginx conf
109+
template:
110+
src: cds.conf.j2
111+
dest: /etc/nginx/sites-available/cds.conf
112+
notify: restart nginx
113+
114+
- name: enable nginx conf for CDS
115+
file:
116+
src: /etc/nginx/sites-available/cds.conf
117+
dest: /etc/nginx/sites-enabled/cds.conf
118+
state: link
119+
notify: restart nginx
120+
121+
- name: disable default nginx site
122+
file:
123+
path: /etc/nginx/sites-enabled/default
124+
state: absent
125+
notify: restart nginx
126+
when: CDS_HOSTNAME
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# nginx configuration for the CDS
2+
server {
3+
listen 80;
4+
listen [::]:80;
5+
6+
server_name {{CDS_HOSTNAME}};
7+
8+
return 301 https://$host$request_uri;
9+
}
10+
11+
server {
12+
listen 443 ssl http2;
13+
listen [::]:443 ssl http2;
14+
15+
server_name {{CDS_HOSTNAME}};
16+
17+
ssl_certificate {{CDS_SSL_CERT}};
18+
ssl_certificate_key {{CDS_SSL_KEY}};
19+
ssl_session_timeout 5m;
20+
ssl_prefer_server_ciphers on;
21+
22+
add_header Strict-Transport-Security max-age=31556952;
23+
24+
location / {
25+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
26+
proxy_set_header X-Forwarded-Proto https;
27+
proxy_set_header Host $host;
28+
29+
proxy_pass https://localhost:8443;
30+
31+
proxy_http_version 1.1;
32+
proxy_set_header Upgrade $http_upgrade;
33+
proxy_set_header Connection "upgrade";
34+
proxy_request_buffering off;
35+
proxy_buffering off;
36+
}
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<cds>
2+
{% for contest in CDS_CONTESTS %}
3+
<contest location="/home/domjudge/cds/contests/{{ contest.path }}" recordReactions="false">
4+
<ccs url="{% if contest.ccs.id is defined %}{{ DOMSERVER_URL }}/api/contests/{{ contest.ccs.id }}{% else %}{{ contest.ccs.url }}{% endif %}" user="{{ contest.ccs.username }}" password="{{ contest.ccs.password }}" />
5+
</contest>
6+
{% endfor %}
7+
</cds>

0 commit comments

Comments
 (0)