Added role server/spotme
parent
93f30e6919
commit
93f1207bf9
@ -0,0 +1,19 @@
|
||||
---
|
||||
|
||||
domain: "spotme.localhost"
|
||||
|
||||
spotme_system_user: "spotme"
|
||||
spotme_service_name: "{{ domain }}.service"
|
||||
spotme_port: 12820
|
||||
|
||||
spotme_user_directory: "{{ global_webservers_directory }}/{{ domain }}"
|
||||
spotme_installation_directory: "{{ spotme_user_directory }}/server"
|
||||
|
||||
database_user: "spotme"
|
||||
# database_pass from mysql/database
|
||||
# database_name from mysql/database
|
||||
|
||||
spotme_remote_addr: "https://git.scc.kit.edu/pi/spot.me.git"
|
||||
# spotme_remote_user
|
||||
# spotme_remote_pass
|
||||
spotme_version: "public-release-2019-04-16"
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
|
||||
- name: restart spotme
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
enabled: yes
|
||||
name: "{{ spotme_service_name }}"
|
||||
state: restarted
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
dependencies:
|
||||
- role: mysql/database
|
||||
# database_user
|
||||
- role: nginx/proxy
|
||||
backend_port: "{{ spotme_port }}"
|
@ -0,0 +1,95 @@
|
||||
---
|
||||
|
||||
# TODO Role for nodejs application
|
||||
|
||||
- name: Add key for source for nodejs
|
||||
apt_key:
|
||||
id: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
|
||||
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
|
||||
|
||||
- name: Add source for nodejs
|
||||
apt_repository:
|
||||
repo: "deb https://deb.nodesource.com/node_11.x {{ ansible_distribution_release }} main"
|
||||
filename: nodesource
|
||||
|
||||
- name: Install required dependencies
|
||||
apt:
|
||||
state: present
|
||||
name:
|
||||
- git
|
||||
- nginx-extras
|
||||
- nodejs
|
||||
- openjdk-8-jdk-headless
|
||||
update_cache: yes
|
||||
|
||||
- name: Configure system user
|
||||
user:
|
||||
state: present
|
||||
name: "{{ spotme_system_user }}"
|
||||
system: yes
|
||||
shell: /bin/false
|
||||
home: "{{ spotme_user_directory }}"
|
||||
|
||||
- name: Configure user directory
|
||||
file:
|
||||
path: "{{ spotme_user_directory }}"
|
||||
state: directory
|
||||
owner: "{{ spotme_system_user }}"
|
||||
group: "{{ spotme_system_user }}"
|
||||
mode: "u=rwx,g=rx"
|
||||
|
||||
# TODO Role for Git Username / Password Configuration
|
||||
|
||||
- name: Configure git to use credential helper
|
||||
become_user: "{{ spotme_system_user }}"
|
||||
git_config:
|
||||
scope: global
|
||||
name: credential.helper
|
||||
value: store
|
||||
|
||||
- name: Encode username for SpotMe remote source
|
||||
become_user: "{{ spotme_system_user }}"
|
||||
command: "perl -p -e 's/%(..)/%\\L\\1\\E/g'"
|
||||
args:
|
||||
stdin: "{{ spotme_remote_user | urlencode }}"
|
||||
register: remote_user_encoded
|
||||
changed_when: False
|
||||
|
||||
- name: Encode password for SpotMe remote source
|
||||
become_user: "{{ spotme_system_user }}"
|
||||
command: "perl -p -e 's/%(..)/%\\L\\1\\E/g'"
|
||||
args:
|
||||
stdin: "{{ spotme_remote_pass | urlencode }}"
|
||||
register: remote_pass_encoded
|
||||
changed_when: False
|
||||
|
||||
- name: Store credentials for SpotMe remote source
|
||||
become_user: "{{ spotme_system_user }}"
|
||||
lineinfile:
|
||||
path: "~/.git-credentials"
|
||||
line: "{{ spotme_remote_addr | urlsplit('scheme') }}://{{ remote_user_encoded.stdout }}:{{ remote_pass_encoded.stdout }}@{{ spotme_remote_addr | urlsplit('hostname') }}"
|
||||
create: yes
|
||||
|
||||
# TODO Remove force
|
||||
- name: Clone SpotMe Repository
|
||||
become_user: "{{ spotme_system_user }}"
|
||||
git:
|
||||
repo: "{{ spotme_remote_addr }}"
|
||||
dest: "{{ spotme_installation_directory }}"
|
||||
version: "{{ spotme_version }}"
|
||||
force: yes
|
||||
register: git_spotme
|
||||
|
||||
# TODO Add changed detection
|
||||
- name: Build SpotMe
|
||||
become_user: "{{ spotme_system_user }}"
|
||||
command: npm run-script build
|
||||
args:
|
||||
chdir: "{{ spotme_installation_directory }}"
|
||||
notify: restart spotme
|
||||
|
||||
- name: Register service for SpotMe
|
||||
template:
|
||||
src: spotme.service
|
||||
dest: "/etc/systemd/system/{{ spotme_service_name }}"
|
||||
notify: restart spotme
|
@ -0,0 +1,30 @@
|
||||
[Unit]
|
||||
Description=SpotMe on {{ domain }}
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
Requires=mariadb.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ spotme_system_user }}
|
||||
Group={{ spotme_system_user }}
|
||||
|
||||
WorkingDirectory={{ spotme_installation_directory }}
|
||||
ExecStart=/usr/bin/npm start
|
||||
Environment="USER={{ spotme_system_user }}"
|
||||
Environment="HOME={{ spotme_user_directory }}"
|
||||
Environment="NODE_ENV=production"
|
||||
Environment="PORT={{ spotme_port }}"
|
||||
Environment="DATABASE_HOST=127.0.0.1"
|
||||
Environment="DATABASE_PORT=3306"
|
||||
Environment="DATABASE_USERNAME={{ database_user }}"
|
||||
Environment="DATABASE_PASSWORD={{ database_pass }}"
|
||||
Environment="DATABASE_NAME={{ database_name }}"
|
||||
|
||||
Restart=always
|
||||
RestartSec=2s
|
||||
StartLimitInterval=60s
|
||||
StartLimitBurst=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue