Deployment scripts
This commit is contained in:
parent
a39a0f61e9
commit
b9a475c817
22 changed files with 363 additions and 4 deletions
|
@ -21,6 +21,7 @@ module.exports = function(grunt) {
|
|||
}
|
||||
},
|
||||
|
||||
// TODO: switch to https://github.com/sindresorhus/grunt-sass
|
||||
sass: { // Task
|
||||
dev: { // Target
|
||||
options: { // Target options
|
||||
|
|
10
ansible/node.yaml
Normal file
10
ansible/node.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
- hosts: webservers
|
||||
become: yes
|
||||
become_method: 'sudo'
|
||||
gather_facts: yes
|
||||
roles:
|
||||
- role: geerlingguy.nodejs
|
||||
nodejs_install_npm_user: ansible
|
||||
nodejs_npm_global_packages:
|
||||
- name: bower
|
||||
- name: grunt-cli
|
2
ansible/roles/geerlingguy.nodejs/.gitignore
vendored
Normal file
2
ansible/roles/geerlingguy.nodejs/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.retry
|
||||
tests/test.sh
|
33
ansible/roles/geerlingguy.nodejs/.travis.yml
Normal file
33
ansible/roles/geerlingguy.nodejs/.travis.yml
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
services: docker
|
||||
|
||||
env:
|
||||
- distro: centos7
|
||||
- distro: centos6
|
||||
- distro: ubuntu1604
|
||||
- distro: ubuntu1404
|
||||
- distro: ubuntu1204
|
||||
|
||||
script:
|
||||
# Configure test script so we can run extra tests after playbook is run.
|
||||
- export container_id=$(date +%s)
|
||||
- export cleanup=false
|
||||
|
||||
# Download test shim.
|
||||
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
|
||||
- chmod +x ${PWD}/tests/test.sh
|
||||
|
||||
# Run tests.
|
||||
- ${PWD}/tests/test.sh
|
||||
|
||||
# Ensure Node.js is installed.
|
||||
- 'docker exec --tty ${container_id} env TERM=xterm which node'
|
||||
- 'docker exec --tty ${container_id} env TERM=xterm node -v'
|
||||
|
||||
# Ensure npm packages are installed globally.
|
||||
- 'docker exec --tty ${container_id} env TERM=xterm bash --login -c "npm list -g --depth=0 jslint"'
|
||||
- 'docker exec --tty ${container_id} env TERM=xterm bash --login -c "npm list -g --depth=0 node-sass"'
|
||||
- 'docker exec --tty ${container_id} env TERM=xterm bash --login -c "npm list -g --depth=0 yo"'
|
||||
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
20
ansible/roles/geerlingguy.nodejs/LICENSE
Normal file
20
ansible/roles/geerlingguy.nodejs/LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Jeff Geerling
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
71
ansible/roles/geerlingguy.nodejs/README.md
Normal file
71
ansible/roles/geerlingguy.nodejs/README.md
Normal file
|
@ -0,0 +1,71 @@
|
|||
# Ansible Role: Node.js
|
||||
|
||||
[](https://travis-ci.org/geerlingguy/ansible-role-nodejs)
|
||||
|
||||
Installs Node.js on RHEL/CentOS or Debian/Ubuntu.
|
||||
|
||||
## Requirements
|
||||
|
||||
Requires the EPEL repository on RedHat/CentOS (you can install it by simply adding the `geerlingguy.repo-epel` role to your playbook).
|
||||
|
||||
## Role Variables
|
||||
|
||||
Available variables are listed below, along with default values (see `defaults/main.yml`):
|
||||
|
||||
nodejs_version: "6.x"
|
||||
|
||||
The Node.js version to install. "6.x" is the default and works on most supported OSes. Other versions such as "0.12", "4.x", "5.x", "6.x", etc. should work on the latest versions of Debian/Ubuntu and RHEL/CentOS.
|
||||
|
||||
nodejs_install_npm_user: "{{ ansible_ssh_user }}"
|
||||
|
||||
The user for whom the npm packages will be installed can be set here, this defaults to `ansible_user`.
|
||||
|
||||
npm_config_prefix: "~/.npm-global"
|
||||
|
||||
The global installation directory. This should be writeable by the `nodejs_install_npm_user`.
|
||||
|
||||
npm_config_unsafe_perm: "false"
|
||||
|
||||
Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.
|
||||
|
||||
nodejs_npm_global_packages: []
|
||||
|
||||
A list of npm packages with a `name` and (optional) `version` to be installed globally. For example:
|
||||
|
||||
nodejs_npm_global_packages:
|
||||
# Install a specific version of a package.
|
||||
- name: jslint
|
||||
version: 0.9.3
|
||||
# Install the latest stable release of a package.
|
||||
- name: node-sass
|
||||
<!-- code block separator -->
|
||||
|
||||
nodejs_package_json_path: ""
|
||||
|
||||
Set a path pointing to a particular `package.json` (e.g. `"/var/www/app/package.json"`). This will install all of the defined packages globally using Ansible's `npm` module.
|
||||
|
||||
## Dependencies
|
||||
|
||||
None.
|
||||
|
||||
## Example Playbook
|
||||
|
||||
- hosts: utility
|
||||
vars_files:
|
||||
- vars/main.yml
|
||||
roles:
|
||||
- geerlingguy.nodejs
|
||||
|
||||
*Inside `vars/main.yml`*:
|
||||
|
||||
nodejs_npm_global_packages:
|
||||
- name: jslint
|
||||
- name: node-sass
|
||||
|
||||
## License
|
||||
|
||||
MIT / BSD
|
||||
|
||||
## Author Information
|
||||
|
||||
This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
|
24
ansible/roles/geerlingguy.nodejs/defaults/main.yml
Normal file
24
ansible/roles/geerlingguy.nodejs/defaults/main.yml
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
# Set the version of Node.js to install ("0.10", "0.12", "4.x", "5.x", "6.x").
|
||||
# Version numbers from Nodesource: https://github.com/nodesource/distributions
|
||||
nodejs_version: "6.x"
|
||||
|
||||
# The user for whom the npm packages will be installed.
|
||||
# nodejs_install_npm_user: username
|
||||
|
||||
# The directory for global installations.
|
||||
npm_config_prefix: "/usr/local/lib/npm"
|
||||
|
||||
# Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.
|
||||
npm_config_unsafe_perm: "false"
|
||||
|
||||
# Define a list of global packages to be installed with NPM.
|
||||
nodejs_npm_global_packages: []
|
||||
# # Install a specific version of a package.
|
||||
# - name: jslint
|
||||
# version: 0.9.3
|
||||
# # Install the latest stable release of a package.
|
||||
# - name: node-sass
|
||||
|
||||
# The path of a package.json file used to install packages globally.
|
||||
nodejs_package_json_path: ""
|
|
@ -0,0 +1 @@
|
|||
{install_date: 'Mon Apr 24 15:38:26 2017', version: 4.1.0}
|
27
ansible/roles/geerlingguy.nodejs/meta/main.yml
Normal file
27
ansible/roles/geerlingguy.nodejs/meta/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
dependencies: []
|
||||
|
||||
galaxy_info:
|
||||
author: geerlingguy
|
||||
description: Node.js installation for Linux
|
||||
company: "Midwestern Mac, LLC"
|
||||
license: "license (BSD, MIT)"
|
||||
min_ansible_version: 1.9
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- 6
|
||||
- 7
|
||||
- name: Debian
|
||||
versions:
|
||||
- all
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- precise
|
||||
- raring
|
||||
- saucy
|
||||
- trusty
|
||||
- xenial
|
||||
galaxy_tags:
|
||||
- development
|
||||
- web
|
41
ansible/roles/geerlingguy.nodejs/tasks/main.yml
Normal file
41
ansible/roles/geerlingguy.nodejs/tasks/main.yml
Normal file
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
- include: setup-RedHat.yml
|
||||
when: ansible_os_family == 'RedHat'
|
||||
|
||||
- include: setup-Debian.yml
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Define nodejs_install_npm_user
|
||||
set_fact:
|
||||
nodejs_install_npm_user: "{{ ansible_user | default(lookup('env', 'USER')) }}"
|
||||
when: nodejs_install_npm_user is not defined
|
||||
|
||||
- name: Create npm global directory
|
||||
file:
|
||||
path: "{{ npm_config_prefix }}"
|
||||
owner: "{{ nodejs_install_npm_user }}"
|
||||
group: "{{ nodejs_install_npm_user }}"
|
||||
state: directory
|
||||
|
||||
- name: Add npm_config_prefix bin directory to global $PATH.
|
||||
template:
|
||||
src: npm.sh.j2
|
||||
dest: /etc/profile.d/npm.sh
|
||||
mode: 0644
|
||||
|
||||
- name: Ensure npm global packages are installed.
|
||||
npm:
|
||||
name: "{{ item.name }}"
|
||||
version: "{{ item.version | default('latest') }}"
|
||||
global: yes
|
||||
state: latest
|
||||
environment:
|
||||
NPM_CONFIG_PREFIX: "{{ npm_config_prefix }}"
|
||||
NODE_PATH: "{{ npm_config_prefix }}/lib/node_modules"
|
||||
NPM_CONFIG_UNSAFE_PERM: "{{ npm_config_unsafe_perm }}"
|
||||
with_items: "{{ nodejs_npm_global_packages }}"
|
||||
|
||||
- name: Install packages defined in a given package.json.
|
||||
npm:
|
||||
path: "{{ nodejs_package_json_path }}"
|
||||
when: nodejs_package_json_path is defined and nodejs_package_json_path
|
25
ansible/roles/geerlingguy.nodejs/tasks/setup-Debian.yml
Normal file
25
ansible/roles/geerlingguy.nodejs/tasks/setup-Debian.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- name: Ensure apt-transport-https is installed.
|
||||
apt: name=apt-transport-https state=present
|
||||
|
||||
- name: Add Nodesource apt key.
|
||||
apt_key:
|
||||
url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280
|
||||
id: "68576280"
|
||||
state: present
|
||||
|
||||
- name: Add NodeSource repositories for Node.js.
|
||||
apt_repository:
|
||||
repo: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- "deb https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main"
|
||||
- "deb-src https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main"
|
||||
register: node_repo
|
||||
|
||||
- name: Update apt cache if repo was added.
|
||||
apt: update_cache=yes
|
||||
when: node_repo.changed
|
||||
|
||||
- name: Ensure Node.js and npm are installed.
|
||||
apt: "name=nodejs={{ nodejs_version|regex_replace('x', '') }}* state=present"
|
37
ansible/roles/geerlingguy.nodejs/tasks/setup-RedHat.yml
Normal file
37
ansible/roles/geerlingguy.nodejs/tasks/setup-RedHat.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
- name: Set up the Nodesource RPM directory for Node.js > 0.10.
|
||||
set_fact:
|
||||
nodejs_rhel_rpm_dir: "pub_{{ nodejs_version }}"
|
||||
when: nodejs_version != '0.10'
|
||||
|
||||
- name: Set up the Nodesource RPM variable for Node.js == 0.10.
|
||||
set_fact:
|
||||
nodejs_rhel_rpm_dir: "pub"
|
||||
when: nodejs_version == '0.10'
|
||||
|
||||
- name: Import Nodesource RPM key (CentOS < 7).
|
||||
rpm_key:
|
||||
key: http://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL
|
||||
state: present
|
||||
when: ansible_distribution_major_version|int < 7
|
||||
|
||||
- name: Import Nodesource RPM key (CentOS 7+)..
|
||||
rpm_key:
|
||||
key: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL
|
||||
state: present
|
||||
when: ansible_distribution_major_version|int >= 7
|
||||
|
||||
- name: Add Nodesource repositories for Node.js (CentOS < 7).
|
||||
yum:
|
||||
name: "http://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm"
|
||||
state: present
|
||||
when: ansible_distribution_major_version|int < 7
|
||||
|
||||
- name: Add Nodesource repositories for Node.js (CentOS 7+).
|
||||
yum:
|
||||
name: "https://rpm.nodesource.com/{{ nodejs_rhel_rpm_dir }}/el/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/nodesource-release-el{{ ansible_distribution_major_version }}-1.noarch.rpm"
|
||||
state: present
|
||||
when: ansible_distribution_major_version|int >= 7
|
||||
|
||||
- name: Ensure Node.js and npm are installed.
|
||||
yum: "name=nodejs-{{ nodejs_version[0] }}.* state=present enablerepo='epel,nodesource'"
|
3
ansible/roles/geerlingguy.nodejs/templates/npm.sh.j2
Normal file
3
ansible/roles/geerlingguy.nodejs/templates/npm.sh.j2
Normal file
|
@ -0,0 +1,3 @@
|
|||
export PATH={{ npm_config_prefix }}/bin:$PATH
|
||||
export NPM_CONFIG_PREFIX={{ npm_config_prefix }}
|
||||
export NODE_PATH=$NODE_PATH:{{ npm_config_prefix }}/lib/node_modules
|
11
ansible/roles/geerlingguy.nodejs/tests/README.md
Normal file
11
ansible/roles/geerlingguy.nodejs/tests/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Ansible Role tests
|
||||
|
||||
To run the test playbook(s) in this directory:
|
||||
|
||||
1. Install and start Docker.
|
||||
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
|
||||
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
|
||||
1. Make the test shim executable: `chmod +x tests/test.sh`.
|
||||
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
|
||||
|
||||
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`
|
21
ansible/roles/geerlingguy.nodejs/tests/test.yml
Normal file
21
ansible/roles/geerlingguy.nodejs/tests/test.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
- hosts: all
|
||||
|
||||
vars:
|
||||
nodejs_version: "5.x"
|
||||
nodejs_install_npm_user: root
|
||||
npm_config_prefix: /root/.npm-global
|
||||
npm_config_unsafe_perm: "true"
|
||||
nodejs_npm_global_packages:
|
||||
- name: node-sass
|
||||
- name: jslint
|
||||
version: 0.9.6
|
||||
- name: yo
|
||||
|
||||
pre_tasks:
|
||||
- name: Update apt cache.
|
||||
apt: update_cache=yes cache_valid_time=600
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
roles:
|
||||
- role_under_test
|
9
ansible/roles/web/tasks/frontend.yaml
Normal file
9
ansible/roles/web/tasks/frontend.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
|
||||
- name: Install packages based on package.json.
|
||||
npm:
|
||||
path: "{{ release_dir }}"
|
||||
|
||||
- name: Install packages based on bower.json.
|
||||
bower:
|
||||
path: "{{ release_dir }}"
|
|
@ -1,7 +1,8 @@
|
|||
---
|
||||
|
||||
- name: Create release directory
|
||||
file: path={{ release_dir }} state=directory
|
||||
file: path={{ release_dir }} state=directory owner=ansible group=ansible
|
||||
become: true
|
||||
|
||||
- name: Checkout code branch from git
|
||||
git:
|
||||
|
|
|
@ -11,6 +11,12 @@
|
|||
- docker
|
||||
- setup
|
||||
|
||||
- include: frontend.yaml
|
||||
tags:
|
||||
- frontend
|
||||
- nodejs
|
||||
- setup
|
||||
|
||||
- include: manage.yaml
|
||||
tags:
|
||||
- manage
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
---
|
||||
|
||||
#- name: Build a current site
|
||||
# shell: "docker-compose build web"
|
||||
|
||||
- name: Migrate the site data
|
||||
shell: "docker-compose exec web ./manage.py migrate"
|
||||
|
||||
- name: Create administrative user
|
||||
shell: "docker-compose exec web ./manage.py createsuperuser"
|
||||
|
||||
- name: Compress site frontend
|
||||
shell: "docker-compose exec web ./manage.py compress"
|
||||
|
||||
- name: Collect static frontend files
|
||||
shell: "docker-compose exec web ./manage.py collectstatic"
|
||||
|
||||
- name: Start Docker site
|
||||
shell: docker-compose up -d
|
||||
shell: "docker-compose up -d"
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
# Note that changing the domain leaves the old config in place
|
||||
- name: Copy Nginx site config
|
||||
become: true
|
||||
template:
|
||||
src: nginx.conf.j2
|
||||
dest: /etc/nginx/sites-available/{{ domain }}
|
||||
|
||||
- name: Activate Nginx site config
|
||||
become: true
|
||||
file:
|
||||
state: link
|
||||
src: /etc/nginx/sites-available/{{ domain }}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- hosts: webservers
|
||||
become: True
|
||||
become: false
|
||||
gather_facts: True
|
||||
vars:
|
||||
release_dir: /opt/publichealth
|
||||
|
|
|
@ -9,7 +9,6 @@ import django.db.models.deletion
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0033_auto_20170410_2307'),
|
||||
('home', '0014_auto_20170421_1426'),
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue