summaryrefslogtreecommitdiff
path: root/ansible/radicle.liw.fi.yml
blob: 076c5128cccd533468931f321fc5e6d897f93b33 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
- hosts: radicle.liw.fi
  remote_user: root
  become: yes
  roles:
    - role: sane_debian_system
    - role: sshd
    - role: comfortable-debian-system
    - role: unix_users
    - role: rust-rustup
    - role: liw
  tasks:
    - name: "install important additional packages"
      apt:
        name:
          - caddy
          - moreutils
          - nmap
          - ripgrep

    - name: "install Caddy configuration"
      copy:
        content: |
          :80 {
                  root * /usr/share/caddy
          }
          radicle.liw.fi:443 {
                  reverse_proxy 127.0.0.1:8888
          }
          ci.radicle.liw.fi:443 {
                  root * /srv/http/
                  file_server browse
          }
        dest: /etc/caddy/Caddyfile

    - name: "create directory for CI logs"
      file:
        state: directory
        path: /srv/http
        owner: liw
        group: liw

    - name: "restart Caddy"
      systemd:
        name: caddy
        state: restarted
        masked: no
        enabled: yes
        daemon_reload: yes

    - name: "install radicle using installer"
      shell: |
        curl -sSf https://radicle.xyz/install | sudo -u liw bash

    - name: "create directory for Radicle keys"
      file:
        state: directory
        path: /home/liw/.radicle/keys
        owner: liw
        group: liw

    - name: "install Radicle private key"
      copy:
        content: |
          {{ lookup('pipe', 'pass show radicle/radicle.liw.fi/key') }}
        dest: /home/liw/.radicle/keys/radicle
        owner: liw
        group: liw
        mode: 0600

    - name: "install Radicle public key"
      copy:
        content: |
          {{ lookup('pipe', 'pass show radicle/radicle.liw.fi/key.pub') }}
        dest: /home/liw/.radicle/keys/radicle.pub
        owner: liw
        group: liw
        mode: 0644

    - name: "install systemd unit for Radicle node"
      copy:
        content: |
          [Unit]
          After=syslog.target network.target
          Description=Radicle Node

          [Service]
          Type=simple
          ExecStart=/home/liw/.radicle/bin/radicle-node --listen 0.0.0.0:8776
          Environment=RAD_HOME=/home/liw/.radicle
          KillMode=process
          Restart=never
          RestartSec=1
          User=liw
          Group=liw

          [Install]
          WantedBy=default.target
        dest: /lib/systemd/system/radicle-node.service

    - name: "enable systemd unit for Radicle node"
      systemd:
        name: radicle-node
        state: restarted
        masked: no
        enabled: yes
        daemon_reload: yes

    - name: "install systemd unit for Radicle HTTPD"
      copy:
        content: |
          [Unit]
          After=syslog.target network.target
          Description=Radicle HTTPd

          [Service]
          Type=simple
          ExecStart=/home/liw/.radicle/bin/radicle-httpd --listen 127.0.0.1:8888
          Environment=RAD_HOME=/home/liw/.radicle
          KillMode=process
          Restart=always
          RestartSec=1
          User=liw
          Group=liw

          [Install]
          WantedBy=default.target
        dest: /lib/systemd/system/radicle-httpd.service

    - name: "enable systemd unit for Radicle node"
      systemd:
        name: radicle-httpd
        state: restarted
        masked: no
        enabled: yes
        daemon_reload: yes

    - name: "install script to install Radicle CI stuff"
      copy:
        content: |
          #!/bin/bash
          set -xeuo pipefail

          clone_install() {
                  local url dir root
                  url="$1"
                  dir="$2"
                  root="$3"

                  if [ ! -e "$dir" ]; then
                          git clone "$url" "$dir"
                  else
                          (cd "$dir" && git pull)
                  fi

                  (cd "$dir" && cargo install --path=. --root="$root")
          }

          clone_install git://git.liw.fi/radicle-ci-broker radicle-ci-broker "$(pwd)/root"
          clone_install git://git.liw.fi/radicle-native-ci radicle-native-ci "$(pwd)/root"

          install root/bin/* $HOME/bin
        dest: /home/liw/install-radicle-ci
        owner: liw
        group: liw
        mode: 0755

    - name: "install Radicle CI stuff"
      shell: |
        sudo -i -u liw bash -c 'cd /home/liw && install -d bin && ./install-radicle-ci'

    - name: "install systemd unit for Radicle node"
      copy:
        content: |
          [Unit]
          After=syslog.target network.target
          Description=Radicle Node

          [Service]
          Type=simple
          ExecStart=/home/liw/.radicle/bin/radicle-node --listen 0.0.0.0:8776
          Environment=RAD_HOME=/home/liw/.radicle
          KillMode=process
          Restart=never
          RestartSec=1
          User=liw
          Group=liw

          [Install]
          WantedBy=default.target
        dest: /lib/systemd/system/radicle-node.service

    - name: "enable systemd unit for Radicle node"
      systemd:
        name: radicle-node
        state: restarted
        masked: no
        enabled: yes
        daemon_reload: yes

    - name: "install Radicle CI broker config"
      copy:
        content: |
          default_adapter: native
          adapters:
            native:
              command: /home/liw/bin/radicle-native-ci
              env:
                RADICLE_NATIVE_CI: /home/liw/native-ci.yaml
          filters:
            - !Or
              - !And
                - !Repository "rad:zZnk3hS8C3WAhnv7mWcCUToCqpBs"
                - !AnyPatch
              - !And
                - !Repository "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5"
                - !AnyPatch
        dest: /home/liw/ci-broker.yaml
        owner: liw
        group: liw
        mode: 0644

    - name: "create state directory for Radicle native CI"
      file:
        state: directory
        path: /home/liw/native-ci.state
        owner: liw
        group: liw
        mode: 0755

    - name: "install Radicle native CI config"
      copy:
        content: |
          state: /srv/http
          log: /home/liw/native-ci.log
        dest: /home/liw/native-ci.yaml
        owner: liw
        group: liw
        mode: 0644

    - name: "install systemd unit for Radicle CI broker"
      copy:
        content: |
          [Unit]
          After=radicle-node.service
          Description=Radicle CI broker

          [Service]
          Type=simple
          Environment=RAD_HOME=/home/liw/.radicle
          Environment=PATH=/home/liw/bin:/home/liw/.cargo/bin:/home/liw/.local/bin:/home/liw/.radicle/bin:/bin:/sbin
          ExecStart=bash -c '/home/liw/bin/ci-broker /home/liw/ci-broker.yaml >> /srv/http/broker.log'
          KillMode=process
          Restart=never
          RestartSec=1
          User=liw
          Group=liw

          [Install]
          WantedBy=default.target
        dest: /lib/systemd/system/radicle-ci-broker.service

    - name: "enable systemd unit for Radicle CI broker"
      systemd:
        name: radicle-ci-broker
        state: restarted
        masked: no
        enabled: yes
        daemon_reload: yes

  vars:
    ansible_python_interpreter: /usr/bin/python3

    sane_debian_system_version: 2
    sane_debian_system_hostname: "{{ inventory_hostname }}"
    sane_debian_system_codename: bookworm
    sane_debian_system_timezone: Europe/Helsinki
    sane_debian_system_sources_lists:
      - repo: |
          deb http://security.debian.org/debian-security bookworm-security main contrib non-free

    unix_users_version: 2
    unix_users:
      - username: liw
        comment: Lars Wirzenius

    sshd_version: 1

    rustup_cargo_install: |
      starship