Skip to content

Commit

Permalink
Merge pull request #32 from caktus/split-out-tequila-nodejs
Browse files Browse the repository at this point in the history
Split out the nodejs and npm related tasks into a new role
  • Loading branch information
nmashton authored May 31, 2018
2 parents e70cefc + 1c339f0 commit f138a7a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 73 deletions.
15 changes: 15 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ Tequila-django

Changes

v 0.9.12 on May 31, 2018
--------------------------

* Split out the npm tasks into a new role, `tequila-nodejs
<https://github.com/caktus/tequila-nodejs>`_. Projects upgrading to
this version will need to add tequila-nodejs to their
requirements.yml file while still retaining geerlingguy.nodejs,
which is a dependency of this new role. Additionally, the
playbook/web.yml playbook should be updated to execute
tequila-nodejs instead of geerlingguy.nodejs, and it should be
placed immediately after the tequila-django role. See the new
example web.yml file in the playbooks directory in the
`caktus/tequila <https://github.com/caktus/tequila>`_ repo.


v 0.9.11 on March 19, 2018
--------------------------

Expand Down
38 changes: 12 additions & 26 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,27 @@ allow the roles to be installed into ``/etc/ansible/roles``) ::

Create a ``requirements.yml`` file in your project's deployment
directory. It is recommended to include `tequila-common
<https://github.com/caktus/tequila-common>`_, which sets up
the project directory structure and users, and also `geerlingguy/nodejs
<https://github.com/geerlingguy/ansible-role-nodejs>`_
to install nodejs and any front-end packages that your project
requires ::
<https://github.com/caktus/tequila-common>`_, which sets up the
project directory structure and users, and also `tequila-nodejs
<https://github.com/caktus/tequila-nodejs>`_ and `geerlingguy/nodejs
<https://github.com/geerlingguy/ansible-role-nodejs>`_ to install
nodejs and any front-end packages that your project requires ::

---
# file: deployment/requirements.yml
- src: geerlingguy.nodejs
version: 4.1.2
name: nodejs

- src: https://github.com/caktus/tequila-common
version: v0.8.0

- src: https://github.com/caktus/tequila-django
version: v0.9.11

- src: geerlingguy.nodejs
version: 4.1.2
name: nodejs

- src: https://github.com/caktus/tequila-nodejs
version: v0.8.0

Run ``ansible-galaxy`` with your requirements file ::

$ ansible-galaxy install -r deployment/requirements.yml
Expand Down Expand Up @@ -116,7 +119,6 @@ The following variables are used by the ``tequila-django`` role:
- ``source_is_local`` **default:** ``false``
- ``github_deploy_key`` **required if source_is_local is false**
- ``local_project_dir`` **required if source_is_local**
- ``ignore_devdependencies`` **default:** ``false``
- ``extra_env`` **default:** empty dict

The ``extra_env`` variable is a dict of keys and values that is
Expand All @@ -141,14 +143,6 @@ every web instance, since they'll be getting in each other's way.
This variable set to ``true`` causes the ``collectstatic`` task to be
run only once.

Due to `some <https://github.com/npm/npm/issues/17471>`_ `issues
<https://github.com/ansible/ansible/issues/29234>`_ discovered with
npm not managing package installation when new packages are added to
the ``devDependencies`` object in package.json, tequila-django checks
for the presence of any packages in this variable and will throw an
error if found. This behavior can be disabled by setting
``ignore_devdependencies`` to ``true``.


Optimizations
-------------
Expand All @@ -163,11 +157,3 @@ to your project's `ansible.cfg` file ::

**Warning:** this will cause deployments to break if ``securetty`` is used in your server's
``/etc/sudoers`` file.


Notes
-----

See `geerlingguy/nodejs
<https://github.com/geerlingguy/ansible-role-nodejs>`_ for the
expected Ansible configuration variables for that role.
1 change: 0 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ use_newrelic: false
source_is_local: false
is_web: false
is_worker: false
ignore_devdependencies: false
extra_env: {}
15 changes: 0 additions & 15 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
---
- name: chown node_modules
file:
owner: "{{ project_user }}"
group: "{{ project_user }}"
path: "{{ source_dir }}/node_modules"
recurse: yes

- name: npm run build
command: npm run build
args:
chdir: "{{ source_dir }}"
become_user: "{{ project_user }}"
vars:
ansible_ssh_pipelining: true

- name: collectstatic
django_manage:
command: collectstatic
Expand Down
19 changes: 0 additions & 19 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,6 @@
vars:
ansible_ssh_pipelining: true

- name: check for a package.json file
stat: path={{ source_dir }}/package.json
register: package_json

- name: check for build script in package.json
command: awk '/\<scripts\>/,/\<build\>/' {{ source_dir }}/package.json
register: build_script
when: package_json.stat.exists == True

- name: check developer dependencies
command: npm ls -dev --parseable --prefix {{ source_dir }}
register: dev_dependencies
when: package_json.stat.exists == True

- name: fail when there are project-level devDependencies
fail:
msg: "There are packages listed under `devDependencies`. Please move them to `dependencies` instead."
when: not ignore_devdependencies and package_json.stat.exists == True and dev_dependencies.stdout_lines|length > 1

- name: clear out leftover build cruft from the project requirements
file: path={{ venv_dir }}/build state=absent

Expand Down
17 changes: 5 additions & 12 deletions tasks/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,11 @@
group={{ project_name }}
mode=700

# Note: we want the npm build and collectstatic steps to happen at the
# very end of the roles section for the current playbook, so that
# they'll still happen in the order needed even if the playbook has a
# 3rd-party role after tequila-django, e.g. geerlingguy/nodejs. Thus,
# they are moved out into handlers.

- name: trigger build of npm artifacts
command: /bin/true
notify:
- chown node_modules
- npm run build
when: package_json.stat.exists == True and build_script.stdout != ""
# Note: we want the collectstatic step to happen at the very end of
# the roles section for the current playbook, so that it'll still
# happen in the order needed even if the playbook has another role
# after tequila-django, e.g. geerlingguy/nodejs and tequila-nodejs.
# Thus, it is moved out into handlers.

- name: trigger collectstatic
command: /bin/true
Expand Down

0 comments on commit f138a7a

Please sign in to comment.