Skip to content

Commit 5a7f0b2

Browse files
verdanbolkedebruin
authored andcommitted
[AIRFLOW-2691] Manage JS dependencies via npm
Closes #3572 from verdan/AIRFLOW-2691-npm-webpack
1 parent 27fde38 commit 5a7f0b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+12990
-16643
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ rat-results.txt
138138
*.generated
139139
*.tar.gz
140140
scripts/ci/kubernetes/kube/.generated/airflow.yaml
141+
142+
# Node & Webpack Stuff
143+
*.entry.js
144+
node_modules
145+
npm-debug.log*
146+
static/dist

.rat-excludes

+2
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ bootstrap-toggle.min.js
3737
bootstrap-toggle.min.css
3838
d3.v3.min.js
3939
ace.js
40+
airflow/www_rbac/node_modules
41+
.*json

CONTRIBUTING.md

+57
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,60 @@ $ alembic revision -m "add new field to db"
242242
Generating
243243
~/airflow/airflow/migrations/versions/12341123_add_new_field_to_db.py
244244
```
245+
246+
## Setting up the node / npm javascript environment (ONLY FOR www_rbac)
247+
248+
`airflow/www_rbac/` contains all npm-managed, front end assets.
249+
Flask-Appbuilder itself comes bundled with jQuery and bootstrap.
250+
While these may be phased out over time, these packages are currently not
251+
managed with npm.
252+
253+
### Node/npm versions
254+
Make sure you are using recent versions of node and npm. No problems have been found with node>=8.11.3 and npm>=6.1.3
255+
256+
### Using npm to generate bundled files
257+
258+
#### npm
259+
First, npm must be available in your environment. If it is not you can run the following commands
260+
(taken from [this source](https://gist.github.com/DanHerbert/9520689))
261+
```
262+
brew install node --without-npm
263+
echo prefix=~/.npm-packages >> ~/.npmrc
264+
curl -L https://www.npmjs.com/install.sh | sh
265+
```
266+
267+
The final step is to add `~/.npm-packages/bin` to your `PATH` so commands you install globally are usable.
268+
Add something like this to your `.bashrc` file, then `source ~/.bashrc` to reflect the change.
269+
```
270+
export PATH="$HOME/.npm-packages/bin:$PATH"
271+
```
272+
273+
#### npm packages
274+
To install third party libraries defined in `package.json`, run the
275+
following within the `airflow/www_rbac/` directory which will install them in a
276+
new `node_modules/` folder within `www_rbac/`.
277+
278+
```bash
279+
# from the root of the repository, move to where our JS package.json lives
280+
cd airflow/www_rbac/
281+
# run npm install to fetch all the dependencies
282+
npm install
283+
```
284+
285+
To parse and generate bundled files for airflow, run either of the
286+
following commands. The `dev` flag will keep the npm script running and
287+
re-run it upon any changes within the assets directory.
288+
289+
```
290+
# Compiles the production / optimized js & css
291+
npm run prod
292+
293+
# Start a web server that manages and updates your assets as you modify them
294+
npm run dev
295+
```
296+
297+
#### Upgrading npm packages
298+
299+
Should you add or upgrade a npm package, which involves changing `package.json`, you'll need to re-run `npm install`
300+
and push the newly generated `package-lock.json` file so we get the reproducible build.
301+

MANIFEST.in

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# to you under the Apache License, Version 2.0 (the
77
# "License"); you may not use this file except in compliance
88
# with the License. You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing,
1313
# software distributed under the License is distributed on an
1414
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -24,10 +24,12 @@ include README.md
2424
graft licenses/
2525
graft airflow/www/templates
2626
graft airflow/www/static
27+
graft airflow/www_rbac
2728
graft airflow/www_rbac/static
2829
graft airflow/www_rbac/templates
2930
graft airflow/www_rbac/translations
3031
include airflow/alembic.ini
3132
graft scripts/systemd
3233
graft scripts/upstart
3334
graft airflow/config_templates
35+
recursive-exclude airflow/www_rbac/node_modules *

airflow/www_rbac/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from airflow import settings
3232
from airflow import configuration as conf
3333
from airflow.logging_config import configure_logging
34-
34+
from airflow.www_rbac.static_config import configure_manifest_files
3535

3636
app = None
3737
appbuilder = None
@@ -64,6 +64,7 @@ def create_app(config=None, session=None, testing=False, app_name="Airflow"):
6464
app.register_blueprint(routes)
6565

6666
configure_logging()
67+
configure_manifest_files(app)
6768

6869
with app.app_context():
6970

airflow/www_rbac/compile_assets.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# first bump up package.json manually, commit and tag
19+
rm airflow/www_rbac/static/dist/*
20+
cd airflow/www_rbac/
21+
npm install
22+
npm run build
23+
cd ../..

0 commit comments

Comments
 (0)