diff --git a/codimd.yml b/codimd.yml new file mode 100644 index 0000000..ac330c8 --- /dev/null +++ b/codimd.yml @@ -0,0 +1,6 @@ +--- +# Install CodiMD on CodiMD containers +- hosts: codimd.adm.auro.re + roles: + - debian-backports + - codimd diff --git a/roles/codimd/README.md b/roles/codimd/README.md new file mode 100644 index 0000000..9a41690 --- /dev/null +++ b/roles/codimd/README.md @@ -0,0 +1,6 @@ +# Rôle CodiMD + +Ce rôle Ansible permet d'installer CodiMD. + +Il doit être exécuté en tant que super-utilisateur +(option `-b` pour `--become`). diff --git a/roles/codimd/tasks/0_apt_dependencies.yml b/roles/codimd/tasks/0_apt_dependencies.yml new file mode 100644 index 0000000..d610b8a --- /dev/null +++ b/roles/codimd/tasks/0_apt_dependencies.yml @@ -0,0 +1,19 @@ +--- +# For NodeJS package +- name: Configure NodeJS pin + when: ansible_distribution == 'Debian' and ansible_distribution_release == 'stretch' + template: + src: 'apt/nodejs' + dest: '/etc/apt/preferences.d/nodejs' + mode: 0644 + +# Install CodiMD dependencies +- name: Install required packages + apt: + name: "{{item}}" + state: present + update_cache: yes + with_items: + - git + - nodejs + - npm diff --git a/roles/codimd/tasks/1_user_group.yml b/roles/codimd/tasks/1_user_group.yml new file mode 100644 index 0000000..d0bc67d --- /dev/null +++ b/roles/codimd/tasks/1_user_group.yml @@ -0,0 +1,26 @@ +--- +# Security #1 +- name: Create CodiMD system group + group: + name: codimd + system: yes + state: present + +# Security #2 +-name: Create CodiMD user + user: + name: codimd + group: codimd + home: '/var/local/codimd' + comment: CodiMD + system: yes + state: present + +# Security #3 +- name: Secure CodiMD home directory + file: + path: '/var/local/codimd' + state: directory + owner: codimd + group: codimd + mode: 0750 diff --git a/roles/codimd/tasks/main.yml b/roles/codimd/tasks/main.yml new file mode 100644 index 0000000..929de4e --- /dev/null +++ b/roles/codimd/tasks/main.yml @@ -0,0 +1,48 @@ +--- +# Install APT dependencies +- include_tasks: 0_apt_dependencies.yml + +# Create CodiMD user and group +- include_tasks: 1_user_group.yml + +# Download CodiMD +- name: Clone CodiMD project + git: + repo: 'https://github.com/hackmdio/codimd.git' + dest: /var/local/codimd/codimd + version: 1.2.1 + become: yes + become_user: codimd + +# Installation script + +# Setup dependencies and configs +- name: Install CodiMD depedencies + command: bin/setup + args: + chdir: /var/local/codimd/codimd + become: yes + become_user: codimd + +# Build front-end bundle +- name: Build front-end for CodiMD + command: npm run build + become: yes + become_user: CodiMD + +# Connection to database +- name: Connect CodiMD to database + template: + src: sequelizerc + dest: /var/local/codimd/codimd/.sequelizerc + owner: codimd + group: codimd + mode: 0600 + +# Update data base +- name: Migrate the Data Base to the latest schema + command: node_modules/.bin/sequelize db:migrate + args: + chdir /var/local/codimd/codimd + become: yes + become_user: codimd diff --git a/roles/codimd/templates/sequelizerc b/roles/codimd/templates/sequelizerc new file mode 100644 index 0000000..efd3d0f --- /dev/null +++ b/roles/codimd/templates/sequelizerc @@ -0,0 +1,8 @@ +var path = require('path'); + +module.exports = { + 'config': path.resolve('config.json'), + 'migrations-path': path.resolve('lib', 'migrations'), + 'models-path': path.resolve('lib', 'models'), + 'url': 'services-bdd.adm.auro.re' +}