Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
e8aa84c
feat: play with fastapi
sgratzl Dec 23, 2020
148b03b
feat: test flask based setup
sgratzl Dec 23, 2020
e28a1f3
feat: start with setup
sgratzl Dec 28, 2020
6c766cd
feat: add simple flask sqlalchemy core setup
sgratzl Dec 28, 2020
70a7db5
Merge branch 'sgratzl/streaming' into sgratzl/fastapi
sgratzl Dec 28, 2020
47be103
feat: start with printers
sgratzl Dec 28, 2020
ba99d6a
feat: work on analytics
sgratzl Dec 28, 2020
73ec501
feat: simple running version
sgratzl Dec 28, 2020
daf3974
feat: csv printer
sgratzl Dec 29, 2020
042fe1a
refactor: change fiel structure
sgratzl Dec 29, 2020
f91b938
feat: simple execute query
sgratzl Dec 29, 2020
04b80e4
feat: migrate covid_hosp_facility
sgratzl Dec 29, 2020
330f9a5
feat: migrate covidcast
sgratzl Dec 29, 2020
6e750c6
feat: more porting of endpoints
sgratzl Dec 29, 2020
bdf7dd4
feat: add more endpoints
sgratzl Dec 29, 2020
76ae5a7
feat: more endpoints
sgratzl Dec 29, 2020
23a8981
feat: finish migrating endpoints
sgratzl Dec 30, 2020
3d8067e
refactor: code cleanup
sgratzl Dec 30, 2020
192d17d
refactor: code cleanup
sgratzl Dec 30, 2020
966fa5e
fix: small bugs
sgratzl Dec 30, 2020
b6ed93f
revert: api.php
sgratzl Dec 30, 2020
736c972
feat: configure logger, /epidata subset, handle db connect
sgratzl Dec 30, 2020
65cc3fe
fix: unit tests
sgratzl Dec 30, 2020
5f3c5b8
feat: revert helpers
sgratzl Dec 30, 2020
fec5043
build: switch to python version
sgratzl Jan 4, 2021
939a542
build: fix building image
sgratzl Jan 4, 2021
a70763b
test: fix expected result
sgratzl Jan 4, 2021
2d63339
fix: date handling
sgratzl Jan 4, 2021
990232d
build: fix docker image
sgratzl Jan 4, 2021
246bcd3
build: fix test setup
sgratzl Jan 4, 2021
a8ae64c
Merge remote-tracking branch 'origin/main' into sgratzl/flask
sgratzl Jan 15, 2021
7500e3f
feat: port covidcast_nowcast
sgratzl Jan 15, 2021
2623f9d
build: prepare for pushing to AWS
sgratzl Jan 15, 2021
69ce1f7
fix: remove test script
sgratzl Jan 15, 2021
fff4f28
refactor: sensor secrets as individual os env
sgratzl Jan 15, 2021
c6537cf
feat: support alternative list support
sgratzl Jan 15, 2021
14dd738
feat: support alternative ways to give token
sgratzl Jan 15, 2021
fb5d11e
fix: tree printer and support custom grouping
sgratzl Jan 15, 2021
448615e
feat: QueryBuilder first version
sgratzl Jan 15, 2021
e48a9c1
refactor: use query builder
sgratzl Jan 15, 2021
b94d200
feat: migrate queries and simplify them
sgratzl Jan 15, 2021
fcbaf31
feat: list endpoints in missing endpoint exception
sgratzl Jan 18, 2021
c1e931a
feat: add optional url prefix for container
sgratzl Jan 18, 2021
ebcce40
build: prepare for pushing to Github docker registry
sgratzl Jan 19, 2021
61c8a24
build: set docker image label for github
sgratzl Jan 19, 2021
146f66e
build: fix docker registry access
sgratzl Jan 19, 2021
d424a4d
Merge remote-tracking branch 'origin/main' into sgratzl/flask
sgratzl Jan 20, 2021
d988834
test: disable test till
sgratzl Jan 20, 2021
8474a4b
fix: query builder field init
sgratzl Jan 20, 2021
5b72258
fix: sync api.php with main
sgratzl Jan 20, 2021
cf9a23d
feat: migrate latest api.php changes
sgratzl Jan 20, 2021
5aa8917
fix: empty result tests
sgratzl Jan 20, 2021
27ac1aa
build: support custom gunicorn conf
sgratzl Jan 20, 2021
8db4fd9
fix: endpoints and better error logging
sgratzl Jan 20, 2021
79e27f0
test: disable 414 testing in client
sgratzl Jan 20, 2021
33b4e2c
build: fix docker image location
sgratzl Jan 20, 2021
3d4457d
feat: bundle clients into the package
sgratzl Jan 22, 2021
a4d92d9
fix: restore db docker build
sgratzl Jan 22, 2021
1ca2a76
build: use different way to define dependency
sgratzl Jan 22, 2021
cbea29d
fix: better exception logging
sgratzl Jan 22, 2021
5862fde
buid: try tuning logging settings
sgratzl Jan 22, 2021
7c1080a
feat: better handling of database errors
sgratzl Jan 25, 2021
3e10a4c
fix: auth bug
sgratzl Jan 25, 2021
b9cd9f1
fix: cornercases
sgratzl Jan 25, 2021
3559456
feat: start with unit tests
sgratzl Jan 27, 2021
41f90e1
feat: make pytest compatible
sgratzl Jan 27, 2021
f9305e3
build: switch to pytest for testing
sgratzl Jan 27, 2021
6541f3f
tests: add endpoint test
sgratzl Jan 27, 2021
c864cd2
Merge remote-tracking branch 'origin/main' into sgratzl/flaskx
sgratzl Jan 27, 2021
6e74856
fix: integration test
sgratzl Jan 27, 2021
5580131
feat: use orjson for faster serialization
sgratzl Feb 2, 2021
0de3674
fix: proper use of orjson
sgratzl Feb 2, 2021
62244d0
fix: ensure endpoint length within limits
sgratzl Feb 2, 2021
6db5509
Merge remote-tracking branch 'origin/main' into sgratzl/flaskx
sgratzl Feb 23, 2021
ae19d9d
test(fix): fix pytest needed renaming
sgratzl Feb 23, 2021
27437c7
Merge remote-tracking branch 'origin/main' into sgratzl/flaskx
sgratzl Mar 19, 2021
4994e57
feat: add new signal dashboard endpoints
sgratzl Mar 19, 2021
cb38fe4
fix: add missing import
sgratzl Mar 19, 2021
3b49942
test: fix case syntax
sgratzl Mar 19, 2021
c75f714
Merge remote-tracking branch 'origin/main' into sgratzl/flask_updatet…
sgratzl Mar 22, 2021
4bbbddd
feat: adapt latest signal dashboard changes
sgratzl Mar 22, 2021
d0a0e54
Merge remote-tracking branch 'origin/main' into sgratzl/flask_updatet…
sgratzl Mar 24, 2021
99f8e2e
Merge pull request #457 from cmu-delphi/sgratzl/flask_updatetomain
sgratzl Mar 24, 2021
7ca4cda
feat: migrate latest api changes
sgratzl Mar 24, 2021
8a9e81f
ci: use different way to invoke pytest
sgratzl Mar 24, 2021
6ee680f
Merge pull request #465 from cmu-delphi/sgratzl/sync_flask
krivard Mar 31, 2021
52f57d6
feat: prepare for customizing the max results
sgratzl Apr 2, 2021
f8bd294
feat: create compatibility mode
sgratzl Apr 2, 2021
21953dd
test(fix): to be compatible again
sgratzl Apr 2, 2021
20a10d2
fix: tree compatibility
sgratzl Apr 2, 2021
81e8279
Merge pull request #478 from cmu-delphi/sgratzl/flask_compatibility
krivard Apr 2, 2021
7db0b52
feat: start with advanced param parsing
sgratzl Apr 7, 2021
1f7de75
test: add tests for parse_source_signal
sgratzl Apr 7, 2021
7c51803
feat: parse date param
sgratzl Apr 7, 2021
abeb1dd
feat: filter by new pairs
sgratzl Apr 7, 2021
0628403
feat: add new paramters to covidcast
sgratzl Apr 7, 2021
bfe09ca
feat: start with trend endpoint
sgratzl Apr 7, 2021
e4acd9e
fix: format code
sgratzl Apr 7, 2021
3fe4128
fix: tune formatting settings
sgratzl Apr 7, 2021
3066542
Merge branch 'sgratzl/flask_covidcast_params' into sgratzl/flask_covi…
sgratzl Apr 7, 2021
181f5ff
feat: setup for trend endpoint
sgratzl Apr 7, 2021
1d7f059
feat: trend computation
sgratzl Apr 7, 2021
28c507e
fix: apply suggestions
sgratzl Apr 7, 2021
69e7bbd
fix: apply suggestions
sgratzl Apr 7, 2021
84e52db
fix: apply suggestions
sgratzl Apr 7, 2021
04b6743
feat: normalize signal/geo values to lower case
sgratzl Apr 7, 2021
62ca062
Merge branch 'sgratzl/flask_covidcast_params' into sgratzl/flask_covi…
sgratzl Apr 8, 2021
c101077
fix: better regex for matching signal
sgratzl Apr 8, 2021
c788a3e
Merge branch 'sgratzl/flask_covidcast_params' into sgratzl/flask_covi…
sgratzl Apr 8, 2021
9c73a2c
test: add unit tests for trend
sgratzl Apr 8, 2021
6ae17f1
feat: add new columns unless in compatibility mode
sgratzl Apr 8, 2021
2664195
fix: typo in order name
sgratzl Apr 8, 2021
bfe17ef
fix: ensure proper trend row order
sgratzl Apr 8, 2021
f70bfb5
Merge branch 'sgratzl/flask_covidcast_params' into sgratzl/flask_covi…
sgratzl Apr 8, 2021
f6f9477
feat: add pandas hellper
sgratzl Apr 8, 2021
3ddea9c
feat: start with correlation endpoint
sgratzl Apr 8, 2021
0163043
Merge pull request #481 from cmu-delphi/sgratzl/flask_covidcast_params
sgratzl Apr 8, 2021
b2b6f3f
feat: parse dates in pandas for simpler calculation
sgratzl Apr 8, 2021
9bce8f1
test: add more cornercase tests
sgratzl Apr 8, 2021
109b37d
Merge pull request #483 from cmu-delphi/sgratzl/flask_covidcast_custom
sgratzl Apr 8, 2021
326b5ff
test: add unit tests
sgratzl Apr 8, 2021
d5626b1
fix: merge bug
sgratzl Apr 8, 2021
edcd433
feat: add /covidcast/csv endpoint
sgratzl Apr 8, 2021
b6f22b3
Merge pull request #485 from cmu-delphi/sgratzl/flask_export
sgratzl Apr 9, 2021
14b373b
Merge remote-tracking branch 'origin/sgratzl/flaskx' into sgratzl/fla…
sgratzl Apr 9, 2021
a54dc16
feat: add parse_single_time_arg
sgratzl Apr 12, 2021
787a4b6
feat: add option to transform rows
sgratzl Apr 12, 2021
75e177a
feat: add backfill endpoint
sgratzl Apr 12, 2021
3d4c916
Install newrelic package
korlaxxalrok Apr 14, 2021
368a2fa
Add simple wrapper script
korlaxxalrok Apr 16, 2021
ecb2637
Copy wrapper script, add entrypoint and command
korlaxxalrok Apr 16, 2021
b1c5d15
Fix sh path
korlaxxalrok Apr 16, 2021
735e6d4
Fix script path
korlaxxalrok Apr 16, 2021
ee4e999
Fix path
korlaxxalrok Apr 16, 2021
b39c76b
Don't invoke shell, make script executable
korlaxxalrok Apr 16, 2021
d09c0f3
[[ not sh compatible, use absolute path for start.sh
korlaxxalrok Apr 19, 2021
4529795
Use absolute path
korlaxxalrok Apr 19, 2021
7002a64
Fix command
korlaxxalrok Apr 19, 2021
61082a6
Merge pull request #491 from cmu-delphi/briancla/epidata-newrelic-int…
korlaxxalrok Apr 19, 2021
11c4f27
feat: use new completness definition with anchor date
sgratzl Apr 20, 2021
bf7633a
Merge branch 'sgratzl/flaskx' into sgratzl/flask_covidcast_correlation
sgratzl Apr 20, 2021
9a057df
Merge remote-tracking branch 'origin/sgratzl/flask_covidcast_correlat…
sgratzl Apr 20, 2021
e3906ab
fix: wrong variable
sgratzl Apr 20, 2021
ef3a391
fix: send something for empty csv files
sgratzl Apr 21, 2021
ebc1a5f
fix: also send somting for nljson
sgratzl Apr 21, 2021
ac2d5d6
Merge pull request #492 from cmu-delphi/sgratzl/flask_print_empty
chinandrew Apr 21, 2021
087036a
fix: integrate feedback
sgratzl Apr 27, 2021
41e8062
tests: add more unit tests
sgratzl Apr 27, 2021
f320121
feat: add integration tests for custom endpoints
sgratzl Apr 27, 2021
f2623ed
Merge branch 'sgratzl/flask_covidcast_correlation' into sgratzl/flask…
sgratzl Apr 27, 2021
b3691fb
test: add integration test for /backfill
sgratzl Apr 27, 2021
c4fd058
Merge pull request #488 from cmu-delphi/sgratzl/flask_backfil
sgratzl Apr 27, 2021
f25a520
Merge pull request #484 from cmu-delphi/sgratzl/flask_covidcast_corre…
sgratzl Apr 27, 2021
73fb6aa
refactor: remove analytics tracking
sgratzl Apr 28, 2021
d74817b
refactor: remove _api entry from meta endpoint
sgratzl Apr 28, 2021
5f984e7
test: remove analytics test since outdated
sgratzl Apr 28, 2021
af3cf4f
fix: fetch coverage data before streaming results
sgratzl Apr 28, 2021
22d11c3
fix: better exception logging and simplify error return
sgratzl Apr 28, 2021
987e8ad
Merge pull request #499 from cmu-delphi/sgratzl/flaskx_error
sgratzl Apr 28, 2021
03a443c
Merge branch 'sgratzl/flaskx' into sgratzl/flask_remove_analytics
sgratzl Apr 28, 2021
d335ac0
Merge pull request #498 from cmu-delphi/sgratzl/flask_remove_analytics
sgratzl Apr 30, 2021
9d76cb2
Add Flask server files to correct deployment location
krivard May 3, 2021
5b5478d
Spellign
krivard May 3, 2021
824bcd4
Measure once, cut twice
krivard May 3, 2021
2beee52
Merge pull request #508 from cmu-delphi/krivard-patch-1
krivard May 3, 2021
92488c2
Hack to move flask tests out of the way before py3test
krivard May 4, 2021
9bc704d
Merge pull request #511 from cmu-delphi/py3test-hack
krivard May 4, 2021
5a2ffa6
Hide the remaining flask tests from py3test
krivard May 4, 2021
05dce60
Merge pull request #512 from cmu-delphi/hide-flask
krivard May 4, 2021
e97e5a2
ci: separate image step and only build on certain branches
sgratzl May 5, 2021
2e3c079
build: try to fix moving tests
sgratzl May 5, 2021
664fe05
Merge pull request #514 from cmu-delphi/sgratzl/flask_deploy_fix
sgratzl May 5, 2021
014fa40
build: match is required for globbing
sgratzl May 5, 2021
34cc23b
Merge pull request #515 from cmu-delphi/sgratzl/flask_deploy_fix
korlaxxalrok May 5, 2021
331bb32
Merge pull request #513 from cmu-delphi/sgratzl/flask_image_tags
sgratzl May 5, 2021
9872c8a
Merge remote-tracking branch 'origin/main' into sgratzl/flaskx
sgratzl May 5, 2021
cbad2cf
Merge branch 'sgratzl/flaskx' of github.com:cmu-delphi/delphi-epidata…
sgratzl May 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/delphi-epidata
/.mypy_cache
/.github
/docs
__pycache__
/node_modules
18 changes: 18 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FLASK_DEBUG=True
SQLALCHEMY_DATABASE_URI=sqlite:///test.db
FLASK_SECRET=abc
SECRET_TWITTER=abc
SECRET_GHT=abc
SECRET_FLUVIEW=abc
SECRET_CDC=abc
SECRET_SENSORS=abc
SECRET_SENSOR_TWTR=abc
SECRET_SENSOR_GFT=abc
SECRET_SENSOR_GHT=abc
SECRET_SENSOR_GHTJ=abc
SECRET_SENSOR_CDC=abc
SECRET_SENSOR_QUID=abc
SECRET_SENSOR_WIKI=abc
SECRET_QUIDEL=abc
SECRET_NOROSTAT=abc
SECRET_AFHSB=abc
68 changes: 62 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ jobs:

- name: Build docker images
run: |
docker build -t delphi_web -f repos/delphi/operations/dev/docker/web/Dockerfile .
docker build -t delphi_database -f repos/delphi/operations/dev/docker/database/Dockerfile .
docker build -t delphi_python -f repos/delphi/operations/dev/docker/python/Dockerfile .
docker build -t delphi_web_epidata -f ./repos/delphi/delphi-epidata/dev/docker/web/epidata/Dockerfile .
docker build -t delphi_database_epidata -f ./repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile .
docker build -t delphi_web_python -f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile .
cd ./repos/delphi/delphi-epidata
docker build -t delphi_web_epidata -f ./devops/Dockerfile .
cd ../../../

- name: Start services
run: |
docker network create --driver bridge delphi-net
docker run --rm -d -p 13306:3306 --network delphi-net --name delphi_database_epidata delphi_database_epidata
docker run --rm -d -p 10080:80 --network delphi-net --name delphi_web_epidata delphi_web_epidata
docker run --rm -d -p 10080:80 --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --network delphi-net --name delphi_web_epidata delphi_web_epidata
docker ps

- run: |
Expand All @@ -71,13 +73,67 @@ jobs:
sleep 10s
- name: Run Unit Tests
run: |
docker run --rm --network delphi-net delphi_python python3 -m undefx.py3tester.py3tester --use-exit-code repos/delphi/delphi-epidata/tests
docker run --rm --network delphi-net --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" delphi_web_python python -m pytest --import-mode importlib repos/delphi/delphi-epidata/tests

- name: Run Integration Tests
run: |
docker run --rm --network delphi-net delphi_python python3 -m undefx.py3tester.py3tester --use-exit-code repos/delphi/delphi-epidata/integrations
docker run --rm --network delphi-net delphi_web_python python -m pytest --import-mode importlib repos/delphi/delphi-epidata/integrations

- name: Clean Up
run: |
docker stop delphi_database_epidata delphi_web_epidata
docker network remove delphi-net
docker network remove delphi-net

image:
# only on main and dev branch
if: startsWith(github.ref, 'refs/heads/main') || github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/sgratzl/flaskx'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: cmu-delphi-deploy-machine
password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
- name: Build Image
env:
DEVOPS_DOCKER_FILE: ./devops/Dockerfile
run: |
docker build -t repo --file ${DEVOPS_DOCKER_FILE} .
- name: Resolve Tag
id: tagname
run: |
baseRef="${GITHUB_REF#*/}"
imageTag="${baseRef#*/}"
case "${baseRef}" in
main)
imageTag="latest"
;;
*)
imageTag="${baseRef//\//_}" # replace `/` with `_` in branch name
;;
esac
echo "::set-output name=tag::$imageTag"
echo "::set-output name=repo::ghcr.io/${{ github.repository }}"
- name: Push Dev Tag
run: |
docker tag repo ${{ steps.tagname.outputs.repo }}:${{ steps.tagname.outputs.tag }}
docker push ${{ steps.tagname.outputs.repo }}:${{ steps.tagname.outputs.tag }}
# - name: Extract version
# if: startsWith(github.ref, 'refs/heads/main')
# id: extract_version
# run: node -pe "'::set-output name=version::' + require('./package.json').version"
- name: Trigger Webhook
run: |
# trigger a webhook update
curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \
-X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "repository=${{ steps.tagname.outputs.repo }}&tag=${{ steps.tagname.outputs.tag }}"
# - name: Push Version Tag Tag
# if: startsWith(github.ref, 'refs/heads/main')
# run: |
# docker tag repo ${{ steps.tagname.outputs.repo }}:v${{ steps.extract_version.outputs.version }}
# docker push ${{ steps.tagname.outputs.repo }}:v${{ steps.extract_version.outputs.version }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
__pycache__/
.DS_Store

/.vscode
/delphi-epidata
/.env
*.db
/build
/node_modules
6 changes: 6 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { process, minimizeJs, rename } = require('delphi-cmu-buildtools');

Promise.all([
process('*.+(coffee|js|py|R)', [], { srcDir: './src/client', dstDir: './build/lib' }),
process('*.js', [minimizeJs(), rename((f) => f.replace('.js', '.min.js'))], { srcDir: './src/client', dstDir: './build/lib' }),
]).then((r) => console.log(r.flat()));
35 changes: 33 additions & 2 deletions deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"paths": {
"root_web": "/var/www/html/epidata",
"auto_web": "/home/automation/public_html/public",
"package": "../delphi/epidata"
"package": "../delphi/epidata",
"stasis": "../stasis"
},
"actions": [

Expand Down Expand Up @@ -43,14 +44,28 @@
"add-header-comment": true
},

"// server - API tests",
"// server",
{
"type": "move",
"src": "src/server/",
"dst": "[[package]]/server/",
"match": "^.*\\.(py)$",
"add-header-comment": true
},
{
"type": "move",
"src": "src/server/endpoints",
"dst": "[[package]]/server/endpoints/",
"match": "^.*\\.(py)$",
"add-header-comment": true
},
{
"type": "move",
"src": "src/server/endpoints/covidcast_utils",
"dst": "[[package]]/server/endpoints/covidcast_utils/",
"match": "^.*\\.(py)$",
"add-header-comment": true
},

"// acquisition - fluview",
{
Expand Down Expand Up @@ -246,6 +261,22 @@
"add-header-comment": true
},

"// move flask tests out of the way",
{
"type": "move",
"src": "tests/server/",
"dst": "[[stasis]]/tests/",
"match": "^.*\\.(py)$",
"recursive": true
},
{
"type": "move",
"src": "integrations/server/",
"dst": "[[stasis]]/integrations/",
"match": "^.*\\.(py)$",
"recursive": true
},

"// run unit and coverage tests",
{"type": "py3test"}

Expand Down
4 changes: 4 additions & 0 deletions dev/docker/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# start with the `delphi_python` image
FROM delphi_python

RUN pip install --no-cache-dir -r repos/delphi/delphi-epidata/requirements.txt -r repos/delphi/delphi-epidata/requirements.dev.txt
26 changes: 26 additions & 0 deletions devops/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:lts-buster AS builder
WORKDIR /src
COPY . /src
RUN npm ci && npm run build

FROM tiangolo/meinheld-gunicorn:python3.7
LABEL org.opencontainers.image.source=https://github.com/cmu-delphi/delphi-epidata
# use delphi's timezome
RUN ln -s -f /usr/share/zoneinfo/America/New_York /etc/localtime

COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt

# disable python stdout buffering
ENV PYTHONUNBUFFERED 1

COPY ./devops/gunicorn_conf.py /app
COPY ./devops/start_wrapper.sh /
COPY ./src/server/ /app/app/
COPY --from=builder ./src/build/lib/ /app/app/lib/
RUN rm -rf /app/app/__pycache__ /app/app/*.php \
&& chmod -R o+r /app/app \
&& chmod 755 /start_wrapper.sh

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/start_wrapper.sh" ]
53 changes: 53 additions & 0 deletions devops/gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import print_function

import json
import multiprocessing
import os

workers_per_core_str = os.getenv("WORKERS_PER_CORE", "2")
web_concurrency_str = os.getenv("WEB_CONCURRENCY", None)
host = os.getenv("HOST", "0.0.0.0")
port = os.getenv("PORT", "80")
bind_env = os.getenv("BIND", None)
use_loglevel = os.getenv("LOG_LEVEL", "info")
if bind_env:
use_bind = bind_env
else:
use_bind = "{host}:{port}".format(host=host, port=port)

cores = multiprocessing.cpu_count()
workers_per_core = float(workers_per_core_str)
default_web_concurrency = workers_per_core * cores
if web_concurrency_str:
web_concurrency = int(web_concurrency_str)
assert web_concurrency > 0
else:
web_concurrency = int(default_web_concurrency)

# Gunicorn config variables
loglevel = use_loglevel
workers = web_concurrency
bind = use_bind
keepalive = 120

errorlog = "-"
accesslog = "-"
capture_output = True
enable_stdio_inheritance = True

# disable limit request line till 414 issue is resolved
limit_request_line = 0
limit_request_field_size = 0


# For debugging and testing
log_data = {
"loglevel": loglevel,
"workers": workers,
"bind": bind,
# Additional, non-gunicorn variables
"workers_per_core": workers_per_core,
"host": host,
"port": port,
}
print(json.dumps(log_data), flush=True)
10 changes: 10 additions & 0 deletions devops/start_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh
set -e

# If a New Relic license key is found then we start with custom New Relic
# commands, otherwise we start via start.sh.
if [ -z "${NEW_RELIC_LICENSE_KEY}" ]; then
sh /start.sh
else
newrelic-admin run-program /start.sh
fi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# first party
from delphi.epidata.acquisition.covid_hosp.common.database import Database
from delphi.epidata.acquisition.covid_hosp.common.test_utils import TestUtils
from delphi.epidata.acquisition.covid_hosp.common.test_utils import UnitTestUtils
from delphi.epidata.client.delphi_epidata import Epidata
from delphi.epidata.acquisition.covid_hosp.facility.update import Update
import delphi.operations.secrets as secrets
Expand All @@ -24,7 +24,7 @@ def setUp(self):
"""Perform per-test setup."""

# configure test data
self.test_utils = TestUtils(__file__)
self.test_utils = UnitTestUtils(__file__)

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# first party
from delphi.epidata.acquisition.covid_hosp.common.database import Database
from delphi.epidata.acquisition.covid_hosp.common.test_utils import TestUtils
from delphi.epidata.acquisition.covid_hosp.common.test_utils import UnitTestUtils
from delphi.epidata.client.delphi_epidata import Epidata
from delphi.epidata.acquisition.covid_hosp.state_daily.update import Update
from delphi.epidata.acquisition.covid_hosp.state_daily.network import Network
Expand All @@ -27,7 +27,7 @@ def setUp(self):
"""Perform per-test setup."""

# configure test data
self.test_utils = TestUtils(__file__)
self.test_utils = UnitTestUtils(__file__)

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# first party
from delphi.epidata.acquisition.covid_hosp.common.database import Database
from delphi.epidata.acquisition.covid_hosp.common.test_utils import TestUtils
from delphi.epidata.acquisition.covid_hosp.common.test_utils import UnitTestUtils
from delphi.epidata.client.delphi_epidata import Epidata
from delphi.epidata.acquisition.covid_hosp.state_timeseries.update import Update
import delphi.operations.secrets as secrets
Expand All @@ -25,7 +25,7 @@ def setUp(self):
"""Perform per-test setup."""

# configure test data
self.test_utils = TestUtils(__file__)
self.test_utils = UnitTestUtils(__file__)

# use the local instance of the Epidata API
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
Expand Down
Loading