From 8047bcb9d06726790c1bed25b778a0c0948a3157 Mon Sep 17 00:00:00 2001 From: les Date: Fri, 2 Oct 2020 23:31:41 +0200 Subject: [PATCH] up1 role up&running --- roles/lufi/tasks/main.yml | 36 -------------------- roles/up1/defaults/main.yml | 5 +++ roles/up1/meta/main.yml | 15 +++++++++ roles/up1/tasks/main.yml | 53 ++++++++++++++++++++++++++++++ roles/up1/templates/config.js.j2 | 4 +++ roles/up1/templates/server.conf.j2 | 29 ++++++++++++++++ up1.playbook.yml | 10 ++++++ 7 files changed, 116 insertions(+), 36 deletions(-) delete mode 100644 roles/lufi/tasks/main.yml create mode 100644 roles/up1/defaults/main.yml create mode 100644 roles/up1/meta/main.yml create mode 100644 roles/up1/tasks/main.yml create mode 100644 roles/up1/templates/config.js.j2 create mode 100644 roles/up1/templates/server.conf.j2 create mode 100644 up1.playbook.yml diff --git a/roles/lufi/tasks/main.yml b/roles/lufi/tasks/main.yml deleted file mode 100644 index 75779dd..0000000 --- a/roles/lufi/tasks/main.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- name: Install lufi deps - apt: - pkg: - git - build-essential - libssl-dev - libio-socket-ssl-perl - liblwp-protocol-https-perl - zlib1g-dev - -- name: Install Carton - cpanm: name=Carton - -- name: ensure lufi user is present - user: - name: "lufi" - home: "/srv/lufi" - shell: "/bin/bash" - state: present - - -- name: Clone lufi repo - git: - repo: git clone https://framagit.org/fiat-tux/hat-softwares/lufi.git - dest: /srv/lufi/lufi - become: true - become_user: lufi - -- name: Install lufi - shell: carton install --deployment --without=test --without=postgresql --without=mysql - args: - chdir: /srv/lufi/lufi - - - diff --git a/roles/up1/defaults/main.yml b/roles/up1/defaults/main.yml new file mode 100644 index 0000000..d5c4206 --- /dev/null +++ b/roles/up1/defaults/main.yml @@ -0,0 +1,5 @@ +--- +api_key: "{{lookup('password', './.pass/up1_api_key')}}" +maximum_file_size: 500000000 +port: 31337 +footer: Source Code - Contact diff --git a/roles/up1/meta/main.yml b/roles/up1/meta/main.yml new file mode 100644 index 0000000..5076592 --- /dev/null +++ b/roles/up1/meta/main.yml @@ -0,0 +1,15 @@ +--- +dependencies: + + # install nodejs + - role: nodejs + + # install caddy and configure it as reverse proxy + - role: caddy + vars: + caddy_config: | + {{hostname}} + encode gzip + reverse_proxy /api/* 127.0.0.1:31337 + root * /srv/up1/up1/client + file_server \ No newline at end of file diff --git a/roles/up1/tasks/main.yml b/roles/up1/tasks/main.yml new file mode 100644 index 0000000..80b19a7 --- /dev/null +++ b/roles/up1/tasks/main.yml @@ -0,0 +1,53 @@ +--- + +- name: ensure lufi user is present + user: + name: "up1" + home: "/srv/up1" + shell: "/bin/bash" + state: present + +- name: Clone up1 repo + git: + repo: https://github.com/Upload/Up1 + dest: /srv/up1/up1 + become: true + become_user: up1 + +- name: copy server settings + template: + src: server.conf.j2 + dest: /srv/up1/up1/server/server.conf + owner: up1 + group: up1 + mode: 0600 + +- name: copy client settings + template: + src: config.js.j2 + dest: /srv/up1/up1/client/config.js + owner: up1 + group: up1 + mode: 0600 + +- name: Install up1 deps + become: true + become_user: up1 + npm: + path: /srv/up1/up1/server + + +- name: NODE | Install pm2 + npm: + name: pm2 + global: yes + production: yes + state: present + +- name: NODE | Start APP + become: true + become_user: up1 + shell: pm2 start server.js --name server + args: + chdir: /srv/up1/up1/server + ignore_errors: yes \ No newline at end of file diff --git a/roles/up1/templates/config.js.j2 b/roles/up1/templates/config.js.j2 new file mode 100644 index 0000000..182167a --- /dev/null +++ b/roles/up1/templates/config.js.j2 @@ -0,0 +1,4 @@ +upload.config.server = '' // Empty if the webapp is in the same place as the server +// upload.config.server = 'https://yourserver.com/' // If the webapp is separated from the server - remember the trailing slash +upload.config.api_key = '{{ api_key }}' // Should be the same as the server, used for uploading +upload.config.footer = '{{ footer }}' diff --git a/roles/up1/templates/server.conf.j2 b/roles/up1/templates/server.conf.j2 new file mode 100644 index 0000000..00c441b --- /dev/null +++ b/roles/up1/templates/server.conf.j2 @@ -0,0 +1,29 @@ +{ + "api_key": "{{ api_key }}", + "delete_key": "", + "maximum_file_size": {{ maximum_file_size }}, + + "path": { + "i": "../i", + "client": "../client" + }, + + "http": { + "enabled": true, + "listen": "127.0.0.1:{{ port }}" + }, + + "https": { + "enabled": false, + "listen": ":443", + "cert": "./cert.pem", + "key": "./key.pem" + }, + + "cloudflare-cache-invalidate": { + "enabled": false, + "token": "Cloudflare API token here", + "email": "Cloudflare login email here", + "domain": "Domain to invalidate cache on" + } +} diff --git a/up1.playbook.yml b/up1.playbook.yml new file mode 100644 index 0000000..b7d719e --- /dev/null +++ b/up1.playbook.yml @@ -0,0 +1,10 @@ +--- + +- name: "Testing up1 role" + hosts: localhost + become: true + roles: + - role: common + - role: up1 + vars: + hostname: :8000