Browse Source

Add plume role

Dryusdan 1 month ago
parent
commit
7cb1725c93
4 changed files with 226 additions and 0 deletions
  1. 13
    0
      roles/plume/files/plume.service
  2. 168
    0
      roles/plume/tasks/main.yml
  3. 24
    0
      roles/plume/templates/env.j2
  4. 21
    0
      vars.yml

+ 13
- 0
roles/plume/files/plume.service View File

@@ -0,0 +1,13 @@
1
+[Unit]
2
+Description=plume
3
+
4
+[Service]
5
+Type=simple
6
+User=plume
7
+WorkingDirectory=/var/www/plume/www
8
+ExecStart=/var/www/plume/.cargo/bin/plume
9
+TimeoutSec=30
10
+Restart=always
11
+
12
+[Install]
13
+WantedBy=multi-user.target

+ 168
- 0
roles/plume/tasks/main.yml View File

@@ -0,0 +1,168 @@
1
+---
2
+- name: Update repositories cache and install package
3
+  apt: 
4
+    name: "{{ packages }}"
5
+    state: latest 
6
+    update_cache: yes
7
+  vars:
8
+    packages:
9
+      - libpq-dev
10
+      - gettext
11
+      - git
12
+      - curl
13
+      - gcc
14
+      - make
15
+      - openssl
16
+      - libssl-dev
17
+      - pkg-config
18
+      - pwgen
19
+
20
+- name: check if Plume folder exists
21
+  stat:
22
+    path: /var/www/plume/www/.git/config
23
+  register: plumefolder
24
+
25
+- name: Create /var/www folder
26
+  file:
27
+    path: /var/www
28
+    state: directory
29
+    mode: 0755
30
+
31
+
32
+- name: Add the user 'Plume'
33
+  user:
34
+    name: plume
35
+    shell: /bin/bash
36
+    home: /var/www/plume
37
+    create_home: yes
38
+  when: plumefolder.stat.exists == False
39
+
40
+- name: install rust by rustup
41
+  shell: curl https://sh.rustup.rs -sSf | sh -s -- -y
42
+  become: yes
43
+  become_user: plume
44
+  when: plumefolder.stat.exists == False
45
+
46
+- name: Update rustup
47
+  shell: /var/www/plume/.cargo/bin/rustup update
48
+  become: yes
49
+  become_user: plume
50
+  when: plumefolder.stat.exists == True
51
+
52
+- name: install rust by rustup
53
+  shell: export PATH="$PATH:/var/www/plume/.cargo/bin:/var/www/plume/.local/bin:/usr/local/sbin"
54
+  become: yes
55
+  become_user: plume
56
+  when: plumefolder.stat.exists == False
57
+
58
+- name: Clone plume repo
59
+  git:
60
+    repo: https://github.com/Plume-org/Plume.git
61
+    dest: /var/www/plume/www
62
+    force: yes
63
+  become: yes
64
+  become_user: plume
65
+
66
+- name: install diesel
67
+  shell: "cd /var/www/plume/www && /var/www/plume/.cargo/bin/cargo install -j 1  diesel_cli --no-default-features --features postgres --version '=1.3.0' --force"
68
+  become: yes
69
+  become_user: plume
70
+
71
+- name: build front-end
72
+  shell: "cd /var/www/plume/www && /var/www/plume/.cargo/bin/cargo install -j 1 cargo-web --force"
73
+  become: yes
74
+  become_user: plume
75
+
76
+- name: Build front-end
77
+  shell: "cd /var/www/plume/www && /var/www/plume/.cargo/bin/cargo web deploy -p plume-front"
78
+  become: yes
79
+  become_user: plume
80
+
81
+- name: Build the back-end
82
+  shell: "cd /var/www/plume/www && /var/www/plume/.cargo/bin/cargo install -j 1  --no-default-features --features postgres --force"
83
+  become: yes
84
+  become_user: plume
85
+
86
+- name: Build plm, the CLI helper
87
+  shell: "cd /var/www/plume/www && /var/www/plume/.cargo/bin/cargo install -j 1  --no-default-features --features postgres --path plume-cli --force"
88
+  become: yes
89
+  become_user: plume
90
+
91
+#- debug:
92
+  #  msg: "{{ plume }}"
93
+
94
+- name: Add ssh ignore host
95
+  template:
96
+    src: env.j2
97
+    dest: /var/www/plume/www/.env
98
+    mode: 0644
99
+    owner: plume
100
+    group: plume
101
+
102
+- name: "Diesel run"
103
+  shell: "/var/www/plume/.cargo/bin/diesel migration run"
104
+  args:
105
+    chdir: /var/www/plume/www
106
+  become: yes
107
+  become_user: plume
108
+
109
+- name: "Initialise Plume"
110
+  shell: "/var/www/plume/.cargo/bin/plm instance new --name {{ plume.name }} --domain {{ plume.domain }} --default-license {{ plume.licence }}"
111
+  args:
112
+    chdir: /var/www/plume/www
113
+  become: yes
114
+  become_user: plume
115
+  when: plumefolder.stat.exists == False
116
+
117
+- name: Generate password
118
+  shell: "pwgen 21 1"
119
+  become: yes
120
+  become_user: plume
121
+  register: password
122
+  when: plumefolder.stat.exists == False
123
+
124
+- name: Display Password
125
+  debug: msg={{ password.stdout }}
126
+  when: plumefolder.stat.exists == False
127
+
128
+- name: Initialise Plume
129
+  shell: "/var/www/plume/.cargo/bin/plm users new --admin --display-name {{ plume.display_name }} --name {{ plume.admin_name }} --password {{ password.stdout }} --email {{ plume.admin_email }}"
130
+  args:
131
+    chdir: /var/www/plume/www
132
+  become: yes
133
+  become_user: plume
134
+  when: plumefolder.stat.exists == False
135
+
136
+- name: Initialise Plume
137
+  shell: "cd /var/www/plume/www && /var/www/plume/.cargo/bin/plm search init"
138
+  become: yes
139
+  become_user: plume
140
+  when: plumefolder.stat.exists == False
141
+
142
+- name: Copy plume service 
143
+  copy:
144
+    src: plume.service
145
+    dest: /etc/systemd/system/plume.service
146
+    owner: root
147
+    group: root
148
+    mode: 0640
149
+
150
+- name: Reload systemd
151
+  shell: "systemctl daemon-reload"
152
+
153
+- name: Start service plume
154
+  service:
155
+    name: plume.service
156
+    state: started
157
+  when: plumefolder.stat.exists == False
158
+
159
+- name: Restart service plume
160
+  service:
161
+    name: plume.service
162
+    state: restarted
163
+  when: plumefolder.stat.exists == True
164
+
165
+- name: Enable service plume
166
+  service:
167
+    name: plume.service
168
+    enabled: yes

+ 24
- 0
roles/plume/templates/env.j2 View File

@@ -0,0 +1,24 @@
1
+# The address of the database
2
+# (replace USER, PASSWORD, PORT and DATABASE_NAME with your values)
3
+#
4
+# If you are using SQlite, use the path of the database file (`plume.db` for instance)
5
+DATABASE_URL=postgres://{{ plume.db_user }}:{{ plume.db_password }}@{{ plume.db_host }}:{{ plume.db_port }}/{{ plume.db_name }}
6
+
7
+# For PostgreSQL: migrations/postgres
8
+# For SQlite: migrations/sqlite
9
+MIGRATION_DIRECTORY=migrations/postgres
10
+
11
+# The domain on which your instance will be available
12
+BASE_URL={{ plume.domain }}
13
+# Secret key used for private cookies and CSRF protection
14
+# You can generate one with `openssl rand -base64 32`
15
+ROCKET_SECRET_KEY={{ plume.rocket_secret_key }}
16
+ROCKET_ADDRESS={{ plume.rocket_address }}
17
+ROCKET_PORT={{ plume.rocket_port }}
18
+
19
+# Mail settings
20
+MAIL_SERVER={{ plume.mail_server }}
21
+MAIL_USER={{ plume.mail_user }}
22
+MAIL_PASSWORD={{ plume.mail_password }}
23
+MAIL_HELO_NAME={{ plume.mail_helo_name }}
24
+

+ 21
- 0
vars.yml View File

@@ -0,0 +1,21 @@
1
+---
2
+plume:
3
+  name: "Plume"
4
+  domain: "plume.me"
5
+  licence: "CC-BY-CA"
6
+  display_name: "Admin"
7
+  admin_name: "admin"
8
+  admin_email: "admin@domain.tld"
9
+  rocket_address: "0.0.0.0"
10
+  rocket_port: "7878"
11
+  rocket_secret_key: "ouhyufhdguoyfdsgufygsdufygsdufygsdf="
12
+  base_url: plume.me
13
+  db_host: 127.0.0.1
14
+  db_user: plume
15
+  db_password: dsdfsdfsdfsdfsdfsf
16
+  db_port: 5432
17
+  db_name: plume
18
+  mail_server: smtp.domain.tld
19
+  mail_user: noreply@plum.me
20
+  mail_password: 'Hfdsfsdfsdfsd'
21
+  mail_helo_name: plu.me

Loading…
Cancel
Save