# HG changeset patch # User Luke Hoersten # Date 1690059036 18000 # Node ID e69a030975c4299901a3361ce95b4f777a3fad20 # Parent 6c85835d46219cdc7c0b78f8947e96a59a9a5bde Split out nostr install and build roles. diff -r 6c85835d4621 -r e69a030975c4 nostr/build/defaults/main.yaml --- /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}}" diff -r 6c85835d4621 -r e69a030975c4 nostr/build/tasks/main.yaml --- /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 diff -r 6c85835d4621 -r e69a030975c4 nostr/relayer/defaults/main.yaml --- /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" diff -r 6c85835d4621 -r e69a030975c4 nostr/relayer/files/relayer.service --- /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 diff -r 6c85835d4621 -r e69a030975c4 nostr/relayer/handlers/main.yaml --- /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" diff -r 6c85835d4621 -r e69a030975c4 nostr/relayer/tasks/main.yaml --- /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" diff -r 6c85835d4621 -r e69a030975c4 nostr/relayer/templates/relayer.env.j2 --- /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}} diff -r 6c85835d4621 -r e69a030975c4 nostr/relayer/templates/setup_db.psql.j2 --- /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}}; diff -r 6c85835d4621 -r e69a030975c4 relayer/defaults/main.yaml --- 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" diff -r 6c85835d4621 -r e69a030975c4 relayer/files/relayer.service --- 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 diff -r 6c85835d4621 -r e69a030975c4 relayer/handlers/main.yaml --- 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" diff -r 6c85835d4621 -r e69a030975c4 relayer/tasks/main.yaml --- 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" diff -r 6c85835d4621 -r e69a030975c4 relayer/templates/relayer.env.j2 --- 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}} diff -r 6c85835d4621 -r e69a030975c4 relayer/templates/setup_db.psql.j2 --- 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}};