From 8d30acf7ce9d04959c1d65d3f69778927377dfce Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Thu, 24 Aug 2023 20:14:03 +0000 Subject: [PATCH 1/4] add devcontainer --- .devcontainer/Dockerfile | 29 +++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 19 +++++++++++++++++++ Dockerfile | 1 + requirements_webserver.txt | 14 +------------- 4 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..b99fe7ec --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,29 @@ +FROM mcr.microsoft.com/devcontainers/python:1-3.8-buster + +# copy the requirements file into the image +COPY requirements.txt requirements.txt +COPY requirements_webserver.txt requirements_webserver.txt + +# Setup +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + coinor-cbc \ + coinor-libcbc-dev \ + gcc \ + gfortran \ + libhdf5-dev \ + libhdf5-serial-dev \ + libnetcdf-dev \ + netcdf-bin \ + && ln -s /usr/include/hdf5/serial /usr/include/hdf5/include \ + && export HDF5_DIR=/usr/include/hdf5 \ + && pip install netCDF4 \ + && apt-get purge -y --auto-remove \ + gcc \ + libhdf5-dev \ + libhdf5-serial-dev \ + netcdf-bin \ + libnetcdf-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN pip install -r requirements_webserver.txt diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..bcbb974a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "EMHASS", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + } + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e5403af1..af4d5752 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ FROM python:3.8-slim-buster WORKDIR /app # copy the requirements file into the image +COPY requirements.txt requirements.txt COPY requirements_webserver.txt requirements_webserver.txt COPY setup.py setup.py COPY README.md README.md diff --git a/requirements_webserver.txt b/requirements_webserver.txt index 498a017c..d5dfd368 100644 --- a/requirements_webserver.txt +++ b/requirements_webserver.txt @@ -1,16 +1,4 @@ -wheel -numpy==1.22.2 -pandas==1.4.1 -scipy<1.9.0 -pvlib>=0.10.1 -protobuf>=3.0.0 -pytz>=2021.1 -requests>=2.25.1 -beautifulsoup4>=4.9.3 -pulp>=2.4 -pyyaml>=5.4.1 -tables==3.7.0 -skforecast==0.9.1 +-r requirements.txt flask>=2.0.3 waitress>=2.1.1 plotly>=5.6.0 From 885e3d0993babeaabec696c586fa4e2902c36ab4 Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Thu, 24 Aug 2023 21:01:36 +0000 Subject: [PATCH 2/4] respect ingress path as path root --- src/emhass/templates/index.html | 136 +++++--------------------------- src/emhass/web_server.py | 3 +- 2 files changed, 22 insertions(+), 117 deletions(-) diff --git a/src/emhass/templates/index.html b/src/emhass/templates/index.html index 03587c94..22000956 100644 --- a/src/emhass/templates/index.html +++ b/src/emhass/templates/index.html @@ -1,10 +1,9 @@ - EMHASS: Energy Management Optimization for Home Assistant - +
@@ -14,8 +13,8 @@

EMHASS: Energy Management Op

Use the buttons below to manually launch different optimization tasks

- - + +

Use the button below to publish the optimized variables at the current timestamp

Use the buttons below to fit, predict and tune a machine learning model for testing

@@ -43,118 +42,23 @@

Use the buttons below to fit diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index 60d978cb..3e120f8e 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -166,7 +166,8 @@ def index(): else: app.logger.warning("The data container dictionary is empty... Please launch an optimization task") injection_dict={} - return make_response(template.render(injection_dict=injection_dict)) + basename = request.headers.get("X-Ingress-Path", "") + return make_response(template.render(injection_dict=injection_dict, basename=basename)) @app.route('/action/', methods=['POST']) def action_call(action_name): From 133ac129dc90172b4f44b8f9aed859c478893c9c Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Thu, 24 Aug 2023 21:41:55 +0000 Subject: [PATCH 3/4] add external docker to devcontainer --- .devcontainer/devcontainer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index bcbb974a..90555f65 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,6 +5,9 @@ "build": { "dockerfile": "Dockerfile", "context": ".." + }, + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, From 50d382c5bbe6bc10b60bd2a2d917bc8e1ffda89a Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Thu, 24 Aug 2023 22:36:28 +0000 Subject: [PATCH 4/4] create separate setup script --- .devcontainer/Dockerfile | 29 ++--------------------------- .devcontainer/setup.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 27 deletions(-) create mode 100755 .devcontainer/setup.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b99fe7ec..dbd9423b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,29 +1,4 @@ FROM mcr.microsoft.com/devcontainers/python:1-3.8-buster -# copy the requirements file into the image -COPY requirements.txt requirements.txt -COPY requirements_webserver.txt requirements_webserver.txt - -# Setup -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - coinor-cbc \ - coinor-libcbc-dev \ - gcc \ - gfortran \ - libhdf5-dev \ - libhdf5-serial-dev \ - libnetcdf-dev \ - netcdf-bin \ - && ln -s /usr/include/hdf5/serial /usr/include/hdf5/include \ - && export HDF5_DIR=/usr/include/hdf5 \ - && pip install netCDF4 \ - && apt-get purge -y --auto-remove \ - gcc \ - libhdf5-dev \ - libhdf5-serial-dev \ - netcdf-bin \ - libnetcdf-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN pip install -r requirements_webserver.txt +COPY .devcontainer/setup.sh requirements.txt requirements_webserver.txt ./ +RUN ./setup.sh diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 00000000..1158538e --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + set -x + apt-get update + apt-get install -y --no-install-recommends \ + coinor-cbc \ + coinor-libcbc-dev \ + gcc \ + gfortran \ + libhdf5-dev \ + libhdf5-serial-dev \ + libnetcdf-dev \ + netcdf-bin + + ln -s /usr/include/hdf5/serial /usr/include/hdf5/include + export HDF5_DIR=/usr/include/hdf5 + pip install netCDF4 + + pip install -r requirements_webserver.txt + + rm -rf "$0" +} + +main