Skip to content

Commit e4ba23d

Browse files
committed
Refactor server launching
See skyportal#55
1 parent 89fd125 commit e4ba23d

File tree

6 files changed

+45
-16
lines changed

6 files changed

+45
-16
lines changed

Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,21 @@ ENV LANG=C.UTF-8
2525
ADD . /cesium
2626
WORKDIR /cesium
2727

28-
RUN bash -c "source /cesium_env/bin/activate && \
28+
RUN bash -c "\
29+
source /cesium_env/bin/activate && \
2930
make paths && \
30-
make dependencies && \
31+
(make dependencies || make dependencies) && \
32+
make bundle && \
33+
rm -rf node_modules && \
3134
chown -R cesium.cesium /cesium_env && \
32-
chown -R cesium.cesium /cesium"
35+
chown -R cesium.cesium /cesium && \
36+
cp docker.yaml config.yaml"
3337

3438
USER cesium
3539

3640
EXPOSE 5000
3741

3842
CMD bash -c "source /cesium_env/bin/activate && \
3943
(make log &) && \
40-
make dockerrun"
44+
make run_production"
4145

Makefile

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
SHELL = /bin/bash
22
SUPERVISORD=FLAGS=$$FLAGS supervisord -c baselayer/conf/supervisor/supervisor.conf
33
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
46

57
.DEFAULT_GOAL := run
68

79
bundle = ./static/build/bundle.js
810
webpack = ./node_modules/.bin/webpack
11+
baselayer_branch = $(shell git config -f .gitmodules submodule.baselayer.branch)
912

1013
baselayer/README.md:
1114
git submodule update --init --remote
@@ -43,14 +46,32 @@ log: paths
4346
./baselayer/tools/watch_logs.py
4447

4548
run: paths dependencies
46-
@echo "Supervisor will now fire up various micro-services."
49+
@echo "Supervisor will now fire up various services."
4750
@echo
48-
@echo " - Please run \`make log\` in another terminal to view logs"
49-
@echo " - Press Ctrl-C to abort the server"
51+
@echo " - Run \`make log\` in another terminal to view logs"
5052
@echo " - Run \`make monitor\` in another terminal to restart services"
5153
@echo
54+
@echo "The server is in debug mode:"
55+
@echo " JavaScript and Python files will be reloaded upon change."
56+
@echo
57+
58+
@FLAGS="--debug" && \
59+
$(ENV_SUMMARY) && echo && \
60+
echo "Press Ctrl-C to abort the server" && \
61+
echo && \
5262
$(SUPERVISORD)
5363

64+
run_production:
65+
export FLAGS="--config config.yaml" && \
66+
$(ENV_SUMMARY) && \
67+
$(SUPERVISORD)
68+
69+
run_testing: paths dependencies
70+
export FLAGS="--config _test_config.yaml" && \
71+
$(ENV_SUMMARY) && \
72+
$(SUPERVISORD)
73+
74+
5475
monitor:
5576
@echo "Entering supervisor control panel."
5677
@echo " - Type \`status\` too see microservice status"
@@ -60,11 +81,15 @@ monitor:
6081
attach:
6182
$(SUPERVISORCTL) fg app
6283

63-
testrun: paths dependencies
64-
export FLAGS="--config _test_config.yaml" && $(SUPERVISORD)
84+
run_production:
85+
export FLAGS="--config config.yaml" && \
86+
$(ENV_SUMMARY) && \
87+
$(SUPERVISORD)
6588

66-
dockerrun: paths dependencies
67-
export FLAGS="--config docker.yaml" && $(SUPERVISORD)
89+
run_testing: paths dependencies
90+
export FLAGS="--config _test_config.yaml" && \
91+
$(ENV_SUMMARY) && \
92+
$(SUPERVISORD)
6893

6994
debug:
7095
@echo "Starting web service in debug mode"

cesium_app/app_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from baselayer.app.config import Config
88
from . import models
99
from baselayer.app import model_util
10-
from baselayer.app.config import load_config
1110

1211
# This provides `login`, `complete`, and `disconnect` endpoints
1312
from social_tornado.routes import SOCIAL_AUTH_ROUTES

cesium_app/model_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import textwrap
22

3-
from baselayer.app.config import load_config
3+
from baselayer.app.config import load_env
44
from baselayer.app.model_util import status, create_tables, drop_tables
55
from cesium_app import models
66

@@ -59,7 +59,7 @@ def insert_test_data():
5959

6060

6161
if __name__ == "__main__":
62-
cfg = load_config()
62+
env, cfg = load_env()
6363

6464
with status(f"Connecting to database {cfg['database']['database']}"):
6565
models.init_db(**cfg['database'])

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ web:
22
image: cesium/web
33
ports:
44
- "9000:5000"
5+
- "9001:5001"
56
links:
67
- db
78

tools/test_frontend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ def delete_test_yaml():
6767

6868
# Initialize the test database connection
6969
from cesium_app.models import init_db
70-
from cesium_app.app_server import load_config
70+
from baselayer.app.config import load_config
7171
basedir = pathlib.Path(os.path.dirname(__file__))/'..'
7272
cfg = load_config([basedir/'config.yaml.example', basedir/TEST_CONFIG])
7373
init_db(**cfg['database'])
7474

7575
clear_tables()
7676

77-
web_client = subprocess.Popen(['make', 'testrun'], cwd=base_dir,
77+
web_client = subprocess.Popen(['make', 'run_testing'], cwd=base_dir,
7878
preexec_fn=os.setsid)
7979

8080
print('[test_frontend] Waiting for supervisord to launch all server processes...')

0 commit comments

Comments
 (0)