Split out nostr install and build roles.
authorLuke Hoersten <luke@hoersten.org>
Sat, 22 Jul 2023 15:50:36 -0500
changeset 217 e69a030975c4
parent 216 6c85835d4621
child 218 1db4800bc4f5
Split out nostr install and build roles.
nostr/build/defaults/main.yaml
nostr/build/tasks/main.yaml
nostr/relayer/defaults/main.yaml
nostr/relayer/files/relayer.service
nostr/relayer/handlers/main.yaml
nostr/relayer/tasks/main.yaml
nostr/relayer/templates/relayer.env.j2
nostr/relayer/templates/setup_db.psql.j2
relayer/defaults/main.yaml
relayer/files/relayer.service
relayer/handlers/main.yaml
relayer/tasks/main.yaml
relayer/templates/relayer.env.j2
relayer/templates/setup_db.psql.j2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/build/defaults/main.yaml	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,6 @@
+---
+
+relayer_version: "2.0.0"
+# https://github.com/fiatjaf/relayer/releases
+relayer_tar: "https://github.com/fiatjaf/relayer/archive/refs/tags/v{{relayer_version}}.tar.gz"
+relayer_build_dir: "/tmp/relayer-{{relayer_version}}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/build/tasks/main.yaml	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,39 @@
+---
+
+- name: install golang
+  become: yes
+  apt: name="golang-go"
+
+- name: unarchive nostr relayer
+  unarchive:
+    remote_src: yes
+    src: "{{relayer_tar}}"
+    dest: "/tmp/"
+    creates: "{{relayer_build_dir}}"
+
+- name: check if relayer build exists
+  stat:
+    path: "{{relayer_build_dir}}/whitelisted/whitelisted"
+  register: build_file
+
+- name: build relayer
+  command: "go build"
+  args:
+    chdir: "{{relayer_build_dir}}/whitelisted"
+  when: not build_file.stat.exists
+
+- name: create build server dir
+  become: yes
+  file:
+    path: "{{relayer_srv_dir}}"
+    mode: "0755"
+    state: "directory"
+  when: not build_file.stat.exists
+
+- name: copy bin to build server dir
+  become: yes
+  copy:
+    remote_src: yes
+    src: "{{relayer_build_dir}}/whitelisted/whitelisted"
+    dest: "{{relayer_srv_dir}}/nostr-relayer-whitelisted"
+  when: not build_file.stat.exists
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/relayer/defaults/main.yaml	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,9 @@
+---
+
+# https://github.com/fiatjaf/relayer/releases
+relayer_user: "relayer"
+relayer_pubkey: ""
+relayer_port: "7447"
+relayer_db: "relayer"
+relayer_db_user: "relayer"
+relayer_db_pass: "relayer"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/relayer/files/relayer.service	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,14 @@
+[Unit]
+Description=relayer nostr relay
+Requires=network.target postgresql.service
+Before=nginx.service
+
+[Service]
+User=relayer
+EnvironmentFile=/etc/relayer/relayer.env
+
+ExecStart=/usr/local/bin/relayer
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/relayer/handlers/main.yaml	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,5 @@
+---
+
+- name: restart relayer service
+  become: yes
+  systemd: name="relayer.service" state="restarted" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/relayer/tasks/main.yaml	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,60 @@
+---
+
+- name: add relayer user
+  become: yes
+  user: name="{{relayer_user}}" shell="/bin/false" create_home="false" system="yes"
+
+- name: install relayer systemd service
+  become: yes
+  copy:
+    src: "relayer.service"
+    dest: "/lib/systemd/system/relayer.service"
+  notify: restart relayer service
+
+- name: install relayer bin
+  become: yes
+  get_url:
+    url: "{{relayer_bin_url}}"
+    dest: "/usr/local/bin/relayer"
+    owner: "root"
+    group: "root"
+    mode: "0755"
+  notify: restart relayer service
+
+- name: create relayer dirs
+  become: yes
+  file:
+    path: "/etc/relayer"
+    owner: "root"
+    group: "root"
+    mode: "0755"
+    state: "directory"
+
+- name: install relayer config
+  become: yes
+  template:
+    src: "relayer.env.j2"
+    dest: "/etc/relayer/relayer.env"
+    owner: "root"
+    group: "root"
+    mode: "0600"
+  notify: restart relayer service
+
+- name: copy db schema file
+  become: yes
+  template:
+    src: "setup_db.psql.j2"
+    dest: "/tmp/setup_db_relayer.psql"
+    owner: "postgres"
+    group: "postgres"
+    mode: "0600"
+
+- name: install db schema psql
+  become: yes
+  become_user: "postgres"
+  command: "psql -f /tmp/setup_db_relayer.psql"
+  changed_when: false
+
+- name: ensure service is started
+  become: yes
+  systemd: name="relayer.service" enabled="yes" state="started"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/relayer/templates/relayer.env.j2	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,4 @@
+POSTGRESQL_DATABASE=postgres://{{relayer_db_user}}:{{relayer_db_pass}}@localhost:5432/{{relayer_db}}
+WHITELIST={{relayer_pubkey}}
+HOST=127.0.0.1
+PORT={{relayer_port}}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nostr/relayer/templates/setup_db.psql.j2	Sat Jul 22 15:50:36 2023 -0500
@@ -0,0 +1,2 @@
+CREATE USER {{relayer_db_user}} WITH ENCRYPTED PASSWORD '{{relayer_db_pass}}';
+CREATE DATABASE {{relayer_db}} WITH OWNER {{relayer_db_user}};
--- a/relayer/defaults/main.yaml	Sat Jul 22 15:50:07 2023 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
----
-
-# https://github.com/fiatjaf/relayer/releases
-relayer_user: "relayer"
-relayer_pubkey: ""
-relayer_port: "7447"
-relayer_db: "relayer"
-relayer_db_user: "relayer"
-relayer_db_pass: "relayer"
--- a/relayer/files/relayer.service	Sat Jul 22 15:50:07 2023 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-[Unit]
-Description=relayer nostr relay
-Requires=network.target postgresql.service
-Before=nginx.service
-
-[Service]
-User=relayer
-EnvironmentFile=/etc/relayer/relayer.env
-
-ExecStart=/usr/local/bin/relayer
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
--- a/relayer/handlers/main.yaml	Sat Jul 22 15:50:07 2023 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
----
-
-- name: restart relayer service
-  become: yes
-  systemd: name="relayer.service" state="restarted" daemon_reload="yes"
--- a/relayer/tasks/main.yaml	Sat Jul 22 15:50:07 2023 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
----
-
-- name: add relayer user
-  become: yes
-  user: name="{{relayer_user}}" shell="/bin/false" create_home="false" system="yes"
-
-- name: install relayer systemd service
-  become: yes
-  copy:
-    src: "relayer.service"
-    dest: "/lib/systemd/system/relayer.service"
-  notify: restart relayer service
-
-- name: install relayer bin
-  become: yes
-  copy:
-    src: "whitelisted"
-    dest: "/usr/local/bin/relayer"
-    owner: "root"
-    group: "root"
-    mode: "0755"
-  notify: restart relayer service
-
-- name: create relayer dirs
-  become: yes
-  file:
-    path: "/etc/relayer"
-    owner: "root"
-    group: "root"
-    mode: "0755"
-    state: "directory"
-
-- name: install relayer config
-  become: yes
-  template:
-    src: "relayer.env.j2"
-    dest: "/etc/relayer/relayer.env"
-    owner: "root"
-    group: "root"
-    mode: "0600"
-  notify: restart relayer service
-
-- name: copy db schema file
-  become: yes
-  template:
-    src: "setup_db.psql.j2"
-    dest: "/tmp/setup_db_relayer.psql"
-    owner: "postgres"
-    group: "postgres"
-    mode: "0600"
-
-- name: install db schema psql
-  become: yes
-  become_user: "postgres"
-  command: "psql -f /tmp/setup_db_relayer.psql"
-  changed_when: false
-
-- name: ensure service is started
-  become: yes
-  systemd: name="relayer.service" enabled="yes" state="started"
--- a/relayer/templates/relayer.env.j2	Sat Jul 22 15:50:07 2023 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-POSTGRESQL_DATABASE=postgres://{{relayer_db_user}}:{{relayer_db_pass}}@localhost:5432/{{relayer_db}}
-WHITELIST={{relayer_pubkey}}
-HOST=127.0.0.1
-PORT={{relayer_port}}
--- a/relayer/templates/setup_db.psql.j2	Sat Jul 22 15:50:07 2023 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-CREATE USER {{relayer_db_user}} WITH ENCRYPTED PASSWORD '{{relayer_db_pass}}';
-CREATE DATABASE {{relayer_db}} WITH OWNER {{relayer_db_user}};