Skip to content

Commit 3d4457d

Browse files
committed
feat: bundle clients into the package
1 parent 33b4e2c commit 3d4457d

File tree

9 files changed

+198
-6
lines changed

9 files changed

+198
-6
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/.mypy_cache
33
/.github
44
/docs
5-
__pycache__
5+
__pycache__
6+
/node_modules

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ __pycache__/
33
/.vscode
44
/delphi-epidata
55
/.env
6-
*.db
6+
*.db
7+
/build
8+
/node_modules

build.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { process, minimizeJs, rename } = require('delphi-cmu-buildtools');
2+
3+
Promise.all([
4+
process('*.+(coffee|js|py|R)', [], { srcDir: './src/client', dstDir: './build/lib' }),
5+
process('*.js', [minimizeJs(), rename((f) => f.replace('.js', '.min.js'))], { srcDir: './src/client', dstDir: './build/lib' }),
6+
]).then((r) => console.log(r.flat()));

dev/docker/database/epidata/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV MYSQL_USER user
99
ENV MYSQL_PASSWORD pass
1010

1111
# provide DDL which will create empty tables at container startup
12-
COPY repos/delphi/delphi-epidata/src/ddl/*.sql /docker-entrypoint-initdb.d/
12+
COPY ./src/ddl/*.sql /docker-entrypoint-initdb.d/
1313

1414
# grant access to SQL scripts
1515
RUN chmod o+r /docker-entrypoint-initdb.d/*.sql

devops/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
FROM node:lts-buster AS builder
2+
WORKDIR /src
3+
COPY . /src
4+
RUN npm ci && npm run build
5+
16
FROM tiangolo/meinheld-gunicorn:python3.7
27
LABEL org.opencontainers.image.source=https://github.com/cmu-delphi/delphi-epidata
38
# use delphi's timezome
@@ -8,4 +13,5 @@ RUN pip install --no-cache-dir -r requirements.txt
813

914
COPY ./devops/gunicorn_conf.py /app
1015
COPY ./src/server/ /app/app/
16+
COPY --from=builder ./src/build/lib/ /app/app/lib/
1117
RUN rm -rf /app/app/__pycache__ /app/app/*.php && chmod -R o+r /app/app

package-lock.json

Lines changed: 158 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "delphi-epidata",
3+
"private": true,
4+
"dependencies": {},
5+
"devDependencies": {
6+
"delphi-cmu-buildtools": "github:sgratzl/delphi-cmu-buildtools"
7+
},
8+
"scripts": {
9+
"build": "node build.js",
10+
"image": "docker build -t delphi-epidata:latest --file ./devops/Dockerfile ."
11+
}
12+
}

src/server/_common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from typing import cast
22

3-
from flask import Flask, g
3+
from flask import Flask, g, request
44
from sqlalchemy.engine import Connection
55
from werkzeug.local import LocalProxy
66

77
from ._config import SECRET
88
from ._db import engine
99
from ._exceptions import DatabaseErrorException
1010

11-
app = Flask("EpiData")
11+
app = Flask("EpiData", static_url_path="")
1212
app.config["SECRET"] = SECRET
1313

1414

@@ -27,6 +27,8 @@ def _get_db() -> Connection:
2727

2828
@app.before_request
2929
def connect_db():
30+
if request.path.startswith('/lib'):
31+
return
3032
# try to get the db
3133
try:
3234
_get_db()

src/server/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from typing import Dict, Callable
44

5-
from flask import request, send_file, Response
5+
from flask import request, send_file, Response, send_from_directory
66

77
from ._config import URL_PREFIX
88
from ._common import app
@@ -37,6 +37,11 @@ def handle_generic():
3737
def send_index_file():
3838
return send_file(pathlib.Path(__file__).parent / "index.html")
3939

40+
@app.route(f"{URL_PREFIX}/lib/<path:path>")
41+
def send_lib_file(path: str):
42+
print(path, flush=True)
43+
return send_from_directory(pathlib.Path(__file__).parent / "lib", path)
44+
4045

4146
if __name__ == "__main__":
4247
app.run(host="0.0.0.0", port=5000)

0 commit comments

Comments
 (0)