Skip to content

Commit 7a2697e

Browse files
authored
Centralize Makefile logic in baselayer (#229)
* Remove unneeded config/print * Centralize Makefile logic in baselayer * Rename config.yaml.example to config.yaml.defaults * Move test Makefile target to baselayer * Always initialize submodule first for any make target
1 parent dba88ec commit 7a2697e

File tree

11 files changed

+43
-239
lines changed

11 files changed

+43
-239
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ ghostdriver.log
1313
__pycache__/
1414
node_modules/
1515
*.pyc
16-
_test_config.yaml
1716
config.yaml
1817
data

.travis/travis_install.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ section "install.cesium_web.requirements"
1717
npm -g install npm@latest
1818
npm --version
1919
node --version
20-
make dependencies
21-
make check-js-updates
2220

2321
if [[ ${TRIGGERED_FROM_REPO} == "cesium-ml/cesium" ]]; then
2422
mkdir cesium-clone
@@ -35,11 +33,9 @@ pip list --format=columns
3533
section_end "install.cesium_web.requirements"
3634

3735

38-
section "init.cesium_web"
39-
make paths
36+
section "init.db"
4037
make db_init
41-
make bundle
42-
section_end "init.cesium_web"
38+
section_end "init.db"
4339

4440

4541
section "install.chromedriver"

Makefile

Lines changed: 17 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,39 @@
1-
SHELL = /bin/bash
2-
SUPERVISORD=FLAGS=$$FLAGS supervisord -c baselayer/conf/supervisor/supervisor.conf
3-
SUPERVISORCTL=FLAGS=$$FLAGS supervisorctl -c baselayer/conf/supervisor/supervisor.conf
4-
ENV_SUMMARY=PYTHONPATH=. ./baselayer/tools/env_summary.py $$FLAGS
5-
ESLINT=./node_modules/.bin/eslint
6-
71
.DEFAULT_GOAL := run
82

9-
bundle = ./static/build/bundle.js
10-
webpack = ./node_modules/.bin/webpack
11-
baselayer_branch = $(shell git config -f .gitmodules submodule.baselayer.branch)
12-
133
baselayer/README.md:
144
git submodule update --init --remote
155
$(MAKE) baselayer-update
166

17-
.PHONY: baselayer-update
7+
.PHONY: baselayer-update run log
188
baselayer-update:
199
./baselayer/tools/submodule_update.sh
2010

21-
dependencies: baselayer/README.md
22-
@./baselayer/tools/silent_monitor.py pip install -r baselayer/requirements.txt
23-
@./baselayer/tools/silent_monitor.py pip install -r requirements.txt
24-
@./baselayer/tools/silent_monitor.py ./baselayer/tools/check_js_deps.sh
25-
26-
db_init:
27-
@PYTHONPATH=. ./baselayer/tools/silent_monitor.py ./baselayer/tools/db_init.py
28-
29-
db_clear:
30-
PYTHONPATH=. ./baselayer/tools/db_init.py -f
31-
32-
$(bundle): webpack.config.js package.json
33-
$(webpack)
34-
35-
bundle: $(bundle)
36-
37-
bundle-watch:
38-
$(webpack) -w
11+
log:
12+
make -C baselayer log
3913

40-
paths:
41-
@mkdir -p log run tmp
42-
@mkdir -p log/sv_child
43-
@mkdir -p ~/.local/cesium/logs
14+
run:
15+
make -C baselayer run
4416

45-
fill_conf_values:
46-
PYTHONPATH=. ./baselayer/tools/fill_conf_values.py
47-
48-
log: paths
49-
./baselayer/tools/watch_logs.py
50-
51-
run: paths dependencies fill_conf_values
52-
@echo "Supervisor will now fire up various micro-services."
53-
@echo
54-
@echo " - Run \`make log\` in another terminal to view logs"
55-
@echo " - Run \`make monitor\` in another terminal to restart services"
56-
@echo
57-
@echo "The server is in debug mode:"
58-
@echo " JavaScript and Python files will be reloaded upon change."
59-
@echo
60-
61-
@FLAGS="--debug" && \
62-
$(ENV_SUMMARY) && echo && \
63-
echo "Press Ctrl-C to abort the server" && \
64-
echo && \
65-
$(SUPERVISORD)
17+
run_testing:
18+
make -C baselayer run_testing
6619

6720
run_production:
68-
export FLAGS="--config config.yaml" && \
69-
$(ENV_SUMMARY) && \
70-
$(SUPERVISORD)
71-
72-
run_testing: paths dependencies
73-
export FLAGS="--config _test_config.yaml" && \
74-
$(ENV_SUMMARY) && \
75-
$(SUPERVISORD)
76-
77-
monitor:
78-
@echo "Entering supervisor control panel."
79-
@echo " - Type \`status\` too see microservice status"
80-
$(SUPERVISORCTL) -i status
21+
make -C baselayer run_production
8122

82-
# Attach to terminal of running webserver; useful to, e.g., use pdb
83-
attach:
84-
$(SUPERVISORCTL) fg app
23+
test:
24+
make -C baselayer test
8525

86-
clean:
87-
rm $(bundle)
26+
test_headless:
27+
make -C baselayer test_headless
8828

89-
test_headless: paths dependencies fill_conf_values
90-
PYTHONPATH='.' xvfb-run ./tools/test_frontend.py
91-
92-
test: paths dependencies fill_conf_values
93-
PYTHONPATH='.' ./tools/test_frontend.py
94-
95-
stop:
96-
$(SUPERVISORCTL) stop all
29+
db_init:
30+
make -C baselayer db_init
9731

98-
status:
99-
PYTHONPATH='.' ./baselayer/tools/supervisor_status.py
32+
db_clear:
33+
make -C baselayer db_clear
10034

10135
docker-images:
10236
# Add --no-cache flag to rebuild from scratch
10337
docker build -t cesium/web . && docker push cesium/web
10438

105-
# Call this target to see which Javascript dependencies are not up to date
106-
check-js-updates:
107-
./baselayer/tools/check_js_updates.sh
39+
-include "baselayer/README.md" # always clone baselayer if it doesn't exist

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ The easiest way to try the web app is to run it through Docker:
5454
```
5555
and restart `postgresl` (`sudo service postgresql restart`).
5656
57-
2. Install Python and JavaScript dependencies with `make_dependencies`
58-
3. Initialize the database with `make db_init`
57+
2. Initialize the database with `make db_init`
5958
6059
If you've run this script before, you may see warnings here about the
6160
database already existing. Ignore those.
@@ -64,7 +63,7 @@ database already existing. Ignore those.
6463
6564
## Configuration
6665
67-
Copy `config.yaml.example` to `config.yaml` and customize.
66+
Copy `config.yaml.defaults` to `config.yaml` and customize.
6867
6968
- Under `server`, set 'multi_user' to True to enable logins. Also provide the
7069
Google credentials, obtained as described in the config file.

cesium_app/handlers/dataset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ def post(self):
2222
return self.error('No tar file uploaded')
2323

2424
zipfile = data['tarFile']
25-
tarball_content_type_str = 'data:application/gzip;base64,'
25+
tarball_content_types = ('data:application/gzip;base64',
26+
'data:application/x-gzip;base64')
2627

27-
if not zipfile['body'].startswith(tarball_content_type_str):
28+
if not zipfile['body'].startswith(tarball_content_types):
2829
return self.error('Invalid tar file - please ensure file is gzip '
2930
'format.')
3031

@@ -38,9 +39,10 @@ def post(self):
3839
util.secure_filename(zipfile['name']))
3940
zipfile_path = pjoin(self.cfg['paths:upload_folder'], zipfile_name)
4041

42+
for prefix in tarball_content_types:
43+
zipfile['body'] = zipfile['body'].replace(prefix, '')
4144
with open(zipfile_path, 'wb') as f:
42-
f.write(base64.b64decode(
43-
zipfile['body'].replace(tarball_content_type_str, '')))
45+
f.write(base64.b64decode(zipfile['body']))
4446
try:
4547
tarfile.open(zipfile_path)
4648
except tarfile.ReadError:

cesium_app/tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from selenium.common.exceptions import TimeoutException
1414
from seleniumrequests.request import RequestMixin
1515
from pytest_factoryboy import register, LazyFixture
16-
from baselayer.app.config import Config
16+
from baselayer.app.config import load_config
1717
from baselayer.app.test_util import (driver, MyCustomWebDriver, reset_state,
1818
set_server_url)
1919
from cesium_app import models
@@ -22,10 +22,10 @@
2222
PredictionFactory)
2323

2424

25-
print('Loading test configuration from _test_config.yaml')
25+
print('Loading test configuration from test_config.yaml')
2626
basedir = pathlib.Path(os.path.dirname(__file__))/'../..'
27-
cfg = Config([basedir/'config.yaml.example', basedir/'_test_config.yaml'])
28-
set_server_url(cfg['server:url'])
27+
cfg = load_config([basedir/'test_config.yaml'])
28+
set_server_url(f'http://localhost:{cfg["ports:app"]}')
2929
print('Setting test database to:', cfg['database'])
3030
models.init_db(**cfg['database'])
3131

cesium_app/tests/frontend/test_predict.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def test_predict_specific_ts_name(driver, project, dataset, featureset, model):
234234
response = driver.request(
235235
'POST', '{}/predictions'.format(driver.server_url),
236236
json=data).json()
237-
print(response)
238237
assert response['status'] == 'success'
239238

240239
for i in range(10):

config.yaml.example renamed to config.yaml.defaults

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ database:
3030
password:
3131

3232
server:
33-
url: http://localhost:5000
34-
3533
# From https://console.developers.google.com/
3634
#
3735
# - Create Client ID
@@ -44,13 +42,3 @@ server:
4442
debug_login: True
4543
google_oauth2_key:
4644
google_oauth2_secret:
47-
48-
ports:
49-
websocket: 64000
50-
fake_oauth: 63000
51-
app: 5000
52-
app_http_proxy: 5001
53-
app_internal: 65000
54-
dask: 63500
55-
websocket_path_in: 'ipc:///tmp/message_flow_in'
56-
websocket_path_out: 'ipc:///tmp/message_flow_out'

test_config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
database:
2+
database: cesium_test
3+
user: cesium
4+
host: localhost
5+
port: 5432
6+
7+
server:
8+
auth:
9+
debug_login: True
10+
google_oauth2_key:
11+
google_oauth2_secret:

0 commit comments

Comments
 (0)