Skip to content

Commit

Permalink
Merge pull request #54 from shankari/create_prod_docker_compose
Browse files Browse the repository at this point in the history
Create production containers with all code copied in instead of mounted
  • Loading branch information
shankari committed Sep 8, 2022
2 parents cd51dd4 + 3ab7ab7 commit 9f7f965
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 13 deletions.
8 changes: 6 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
dashboard:
image: danjellz/http-server:latest
image: danjellz/http-server:1.4
depends_on:
- db
ports:
Expand All @@ -13,13 +13,17 @@ services:
networks:
- emission
notebook-server:
image: emission/em-public-dashboard-notebook:1.0.0
image: em-pub-dash-dev/viz-scripts
build:
context: viz_scripts
dockerfile: docker/Dockerfile.dev
depends_on:
- db
environment:
- DB_HOST=db
- WEB_SERVER_HOST=0.0.0.0
- CRON_MODE=
- STUDY_CONFIG=stage-program
ports:
# ipynb in numbers
- "47962:8888"
Expand Down
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3"
services:
dashboard:
image: em-pub-dash-prod/frontend
build:
context: frontend
dockerfile: docker/Dockerfile
depends_on:
- db
ports:
# DASH in numbers
- "3274:8080"
volumes:
- ./plots:/public/plots
networks:
- emission
notebook-server:
image: em-pub-dash-prod/viz-scripts
build:
context: viz_scripts
dockerfile: docker/Dockerfile
depends_on:
- db
environment:
- DB_HOST=db
- WEB_SERVER_HOST=0.0.0.0
- CRON_MODE=TRUE
- STUDY_CONFIG=stage-program
ports:
# ipynb in numbers
- "47962:8888"
networks:
- emission
volumes:
- ./plots:/plots
db:
image: mongo:4.4.0
volumes:
- mongo-data:/data/db
networks:
- emission

networks:
emission:

volumes:
mongo-data:

7 changes: 7 additions & 0 deletions frontend/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM danjellz/http-server:1.4

VOLUME /plots

RUN mkdir -p /public
COPY ../client /public/client
COPY ../*.html /public
22 changes: 21 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,30 @@
});
};

/*
* Copied and adapted from the phone `dynamic_config.js`
* Adapted by supporting program name via parameter to make it
* easier to test against localhost
*/
const _getStudyName = function(connectUrl) {
const orig_host = new URL(connectUrl).hostname;
// If we are running this on dev, use a param instead to enable testing
if (orig_host == "localhost") {
const param_study_name = new URL(connectUrl).searchParams.get("study_config");
return param_study_name == null? "stage-program" : param_study_name;
}
const first_domain = orig_host.split(".")[0];
if (first_domain == "openpath-stage") { return "stage"; }
const openpath_index = first_domain.search("-openpath");
if (openpath_index == -1) { return undefined; }
const study_name = first_domain.substr(0,openpath_index);
return study_name;
}

$(function() {
$(document).ready(function() {
// Simple solution to program/study plots dropdown; load the config and corresponding metrics.html
const STUDY_CONFIG = 'stage-program';
const STUDY_CONFIG = _getStudyName(window.location);
$.getJSON('https://raw.githubusercontent.com/e-mission/nrel-openpath-deploy-configs/main/configs/' + STUDY_CONFIG + '.nrel-op.json', function(data) {
// Load list of plots corresponding to study/program
if (data.intro.program_or_study=='program') {
Expand Down
11 changes: 9 additions & 2 deletions viz_scripts/bin/generate_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import arrow
import requests
import json
import os
import sys


# Configuration settings to use for all generated plots by this instance
# This could also be specified as a parser argument, if we want to generate plots for all programs from one instance
STUDY_CONFIG = "stage-program"
# Full list is at
# https://github.com/e-mission/nrel-openpath-deploy-configs/tree/main/configs
STUDY_CONFIG = os.getenv('STUDY_CONFIG', "stage-program")

parser = argparse.ArgumentParser(prog="generate_metrics")
parser.add_argument("plot_notebook", help="the notebook the generates the plot")
Expand All @@ -26,9 +30,12 @@
args.date = [yesterday.year, yesterday.month]

# Read and use parameters from the unified config file on the e-mission Github page
r = requests.get("https://raw.githubusercontent.com/e-mission/nrel-openpath-deploy-configs/main/configs/" + STUDY_CONFIG + ".nrel-op.json")
download_url = "https://raw.githubusercontent.com/e-mission/nrel-openpath-deploy-configs/main/configs/" + STUDY_CONFIG + ".nrel-op.json"
print("About to download config from %s" % download_url)
r = requests.get(download_url)
if r.status_code is not 200:
print(f"Unable to download study config, status code: {r.status_code}")
sys.exit(1)
else:
dynamic_config = json.loads(r.text)
print(f"Successfully downloaded config with version {dynamic_config['version']} "\
Expand Down
26 changes: 22 additions & 4 deletions viz_scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
# python 3
FROM emission/e-mission-server:2.9.2
FROM emission/e-mission-server.dev.server-only:4.0.0
ARG SERVER_REPO=https://github.com/aGuttman/e-mission-server.git
ARG SERVER_BRANCH=dashboard-dependencies

ADD environment36.dashboard.additions.yml /
VOLUME /plots

ADD docker/environment36.dashboard.additions.yml /

RUN /bin/bash -c "/clone_server.sh"

WORKDIR /usr/src/app

RUN /bin/bash -c "cd e-mission-server && source setup/activate.sh && conda env update --name emission --file setup/environment36.notebook.additions.yml"
RUN /bin/bash -c "cd e-mission-server && source setup/activate.sh && conda env update --name emission --file /environment36.dashboard.additions.yml"

ADD start_notebook.sh /usr/src/app/start_notebook.sh
RUN mkdir -p /usr/src/app/saved-notebooks
WORKDIR /usr/src/app/saved-notebooks

COPY auxiliary_files ./auxiliary_files
COPY bin ./bin
COPY *.ipynb .
COPY *.py .

WORKDIR /usr/src/app

ADD docker/start_notebook.sh /usr/src/app/start_notebook.sh
RUN chmod u+x /usr/src/app/start_notebook.sh

ADD crontab /usr/src/app/crontab
ADD docker/crontab /usr/src/app/crontab

EXPOSE 8888

Expand Down
24 changes: 24 additions & 0 deletions viz_scripts/docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# python 3
FROM emission/e-mission-server.dev.server-only:4.0.0
ARG SERVER_REPO=https://github.com/aGuttman/e-mission-server.git
ARG SERVER_BRANCH=dashboard-dependencies

VOLUME /plots

ADD docker/environment36.dashboard.additions.yml /

RUN /bin/bash -c "/clone_server.sh"

WORKDIR /usr/src/app

RUN /bin/bash -c "cd e-mission-server && source setup/activate.sh && conda env update --name emission --file setup/environment36.notebook.additions.yml"
RUN /bin/bash -c "cd e-mission-server && source setup/activate.sh && conda env update --name emission --file /environment36.dashboard.additions.yml"

ADD docker/start_notebook.sh /usr/src/app/start_notebook.sh
RUN chmod u+x /usr/src/app/start_notebook.sh

ADD docker/crontab /usr/src/app/crontab

EXPOSE 8888

CMD ["/bin/bash", "/usr/src/app/start_notebook.sh"]
8 changes: 4 additions & 4 deletions viz_scripts/docker/crontab
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
0 7 * * * python bin/update_mappings.py mapping_dictionaries.ipynb >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py mode_purpose_share.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py ebike_specific_metrics.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py generic_metrics.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py generic_timeseries.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py mode_specific_metrics.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py mode_specific_timeseries.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py energy_calculations.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py generic_metrics_ebike_project.ipynb default >> /var/log/intake.stdinout 2>&1
0 8 * * * python bin/generate_plots.py timeseries_analysis.ipynb default >> /var/log/intake.stdinout 2>&1
# For testing only
# */5 * * * * python bin/generate_plots.py mode_purpose_share.ipynb default >> /var/log/intake.stdinout 2>&1

0 comments on commit 9f7f965

Please sign in to comment.