Skip to content

Commit 335ac4e

Browse files
committed
Initial commit
Extract out the nodejs/npm tasks from tequila-django, in order to eliminate problems with the ordering of tasks.
0 parents  commit 335ac4e

File tree

7 files changed

+202
-0
lines changed

7 files changed

+202
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

CHANGES.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Tequila-nodejs
2+
==============
3+
4+
Changes
5+
6+
v 0.8.0 on Apr 26, 2018
7+
-----------------------
8+

LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2018, Caktus Consulting Group, LLC
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of the Caktus Consulting Group, LLC nor the names of its
15+
contributors may be used to endorse or promote products derived from this
16+
software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.rst

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
tequila-nodejs
2+
==============
3+
4+
This repository holds an `Ansible <http://www.ansible.com/home>`_ role
5+
that is installable using ``ansible-galaxy``. This role depends upon
6+
`geerlingguy/nodejs
7+
<https://github.com/geerlingguy/ansible-role-nodejs>`_ and contains
8+
tasks used to build the front-end assets for a Django web app. It
9+
exists primarily to support the `Caktus Django project template
10+
<https://github.com/caktus/django-project-template>`_.
11+
12+
More complete documenation can be found in `caktus/tequila
13+
<https://github.com/caktus/tequila>`_.
14+
15+
16+
License
17+
-------
18+
19+
This Ansible role is released under the BSD License. See the `LICENSE
20+
<https://github.com/caktus/tequila-nodejs/blob/master/LICENSE>`_ file for
21+
more details.
22+
23+
24+
Contributing
25+
------------
26+
27+
If you think you've found a bug or are interested in contributing to
28+
this project check out `tequila-nodejs on Github
29+
<https://github.com/caktus/tequila-nodejs>`_.
30+
31+
Development sponsored by `Caktus Consulting Group, LLC
32+
<http://www.caktusgroup.com/services>`_.
33+
34+
35+
Dependencies
36+
------------
37+
38+
- `geerlingguy/nodejs <https://github.com/geerlingguy/ansible-role-nodejs>`_
39+
40+
41+
Installation
42+
------------
43+
44+
Create an ``ansible.cfg`` file in your project directory to tell
45+
Ansible where to install your roles (optionally, set the
46+
``ANSIBLE_ROLES_PATH`` environment variable to do the same thing, or
47+
allow the roles to be installed into ``/etc/ansible/roles``) ::
48+
49+
[defaults]
50+
roles_path = deployment/roles/
51+
52+
Create a ``requirements.yml`` file in your project's deployment
53+
directory. It is recommended to include `tequila-common
54+
<https://github.com/caktus/tequila-common>`_, which sets up the
55+
project directory structure and users; `tequila-django
56+
<https://github.com/caktus/tequila-django>`_, which checks out your
57+
project and installs it as a Django web app; and also include and
58+
explicitly pin the version of `geerlingguy/nodejs
59+
<https://github.com/geerlingguy/ansible-role-nodejs>`_, which this
60+
role depends on to install nodejs and any front-end packages that your
61+
project requires ::
62+
63+
---
64+
# file: deployment/requirements.yml
65+
- src: https://github.com/caktus/tequila-common
66+
version: v0.8.0
67+
68+
- src: https://github.com/caktus/tequila-django
69+
version: v0.9.11
70+
71+
- src: geerlingguy.nodejs
72+
version: 4.1.2
73+
name: nodejs
74+
75+
- src: https://github.com/caktus/tequila-nodejs
76+
version: v0.8.0
77+
78+
Run ``ansible-galaxy`` with your requirements file ::
79+
80+
$ ansible-galaxy install -r deployment/requirements.yml
81+
82+
or, alternatively, run it directly against the url ::
83+
84+
$ ansible-galaxy install git+https://github.com/caktus/tequila-nodejs
85+
86+
The project then should have access to the ``tequila-nodejs`` role in
87+
its playbooks.
88+
89+
90+
Variables
91+
---------
92+
93+
The following variables are used by the ``tequila-nodejs`` role:
94+
95+
- ``project_name`` **required**
96+
- ``root_dir`` **default:** ``"/var/www/{{ project_name }}"``
97+
- ``source_dir`` **default:** ``"{{ root_dir }}/src"``
98+
- ``project_user`` **default:** ``"{{ project_name }}"``
99+
- ``ignore_devdependencies`` **default:** ``false``
100+
- ``nodejs_package_json_path`` **required**, typically should be ``"{{
101+
source_dir }}"``
102+
103+
Due to `some <https://github.com/npm/npm/issues/17471>`_ `issues
104+
<https://github.com/ansible/ansible/issues/29234>`_ discovered with
105+
npm not managing package installation when new packages are added to
106+
the ``devDependencies`` object in package.json, tequila-nodejs checks
107+
for the presence of any packages in this variable and will throw an
108+
error if found. This behavior can be disabled by setting
109+
``ignore_devdependencies`` to ``true``. Any such packages found
110+
should almost certainly be moved to the ``dependencies`` object
111+
instead.
112+
113+
114+
Notes
115+
-----
116+
117+
See `geerlingguy/nodejs
118+
<https://github.com/geerlingguy/ansible-role-nodejs>`_ for the
119+
expected Ansible configuration variables for that role.

defaults/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
root_dir: "/var/www/{{ project_name }}"
3+
source_dir: "{{ root_dir }}/src"
4+
project_user: "{{ project_name }}"
5+
ignore_devdependencies: false

meta/main.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
galaxy_info:
3+
author: Caktus Consulting Group, LLC
4+
description: Django project deployment -- nodejs
5+
company: Caktus Consulting Group, LLC
6+
license: BSD
7+
min_ansible_version: 1.9
8+
platforms:
9+
- name: Ubuntu
10+
versions: all
11+
galaxy_tags:
12+
- django
13+
- nodejs
14+
- installer
15+
- web
16+
dependencies:
17+
- { role: geerlingguy.nodejs }

tasks/main.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
- name: chown node_modules
3+
file:
4+
owner: "{{ project_user }}"
5+
group: "{{ project_user }}"
6+
path: "{{ source_dir }}/node_modules"
7+
recurse: yes
8+
9+
- name: check developer dependencies
10+
command: npm ls -dev --parseable --prefix {{ nodejs_package_json_path }}
11+
when: not ignore_devdependencies
12+
register: dev_dependencies
13+
14+
- name: fail when there are project-level devDependencies
15+
fail:
16+
msg: "There are packages listed under `devDependencies`. Please move them to `dependencies` instead."
17+
when: not ignore_devdependencies and dev_dependencies.stdout_lines|length > 1
18+
19+
- name: npm run build
20+
command: npm run build
21+
args:
22+
chdir: "{{ source_dir }}"
23+
become_user: "{{ project_user }}"
24+
vars:
25+
ansible_ssh_pipelining: true

0 commit comments

Comments
 (0)