Skip to content

Commit

Permalink
Install the build directory as the production root
Browse files Browse the repository at this point in the history
The previous approach was to sync selected folders from the checkout
root but otherwise keep their location intact. The new approach works
out of the build directory, removing an unnecessary level of directory
hierarchy.
  • Loading branch information
lovett committed May 2, 2019
1 parent efff579 commit 3c2b456
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
49 changes: 35 additions & 14 deletions ansible/install.yml
@@ -1,8 +1,9 @@
---
- hosts: all
- hosts: notifier
vars:
application_user: notifier
installation_directory: /srv/notifier-prod
application_group: notifier
installation_directory: /srv/notifier
nodejs_path: /usr/local/bin/node
tasks:
- name: Create the application user
Expand All @@ -16,23 +17,43 @@
shell="/usr/sbin/nologin"
system=yes

- name: Create the log directory
become: true
file:
path: "/var/log/notifier"
state: directory
owner: "{{ application_user }}"
group: "{{ application_user }}"
mode: 0700

- name: Rsync the application
become: true
become_user: "{{ application_user }}"
synchronize:
archive: yes
src: "../notifier/"
src: "../build/"
dest: "{{ installation_directory }}"
delete: yes
recursive: true
rsync_opts:
- "--exclude=node_modules"
- "--exclude=package.json"
- "--exclude=package-lock.json"

- name: Copy package.json
become: true
copy:
src: "{{ item }}"
dest: "{{ installation_directory }}"
with_items:
- ../package.json
- ../package-lock.json

- name: Install NPM packages
become: true
npm:
executable: "/usr/local/bin/npm"
global: no
ignore_scripts: yes
path: "{{ installation_directory }}"
production: yes

- name: Set permissions on application root
become: true
file:
path: "{{ installation_directory }}"
recurse: yes
owner: "{{ application_user }}"
group: "{{ application_group }}"

- name: Populate the systemd service
become: true
Expand Down
2 changes: 1 addition & 1 deletion ansible/templates/notifer.service.j2
Expand Up @@ -8,7 +8,7 @@ NotifyAccess=all
User=notifier
Group=notifier
WorkingDirectory={{ installation_directory }}
ExecStart={{ nodejs_path }} build/server/server.js
ExecStart={{ nodejs_path }} server/server.js
Environment=NODE_ENV=production

[Install]
Expand Down

0 comments on commit 3c2b456

Please sign in to comment.