From e4f0eeddedadbf0d330198eb543d5ad1efc386ec Mon Sep 17 00:00:00 2001 From: Dominik Siebel Date: Mon, 16 Sep 2024 11:48:20 +0200 Subject: [PATCH] ci: dockerize setup --- .dockerignore | 14 ++++++++++++++ .env | 3 +++ .gitignore | 2 ++ Dockerfile | 25 +++++++++++++++++++++++++ Makefile | 4 ++++ config.example.py | 18 ++++++++---------- docker-compose.yaml | 31 +++++++++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 .dockerignore create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9f9033d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.git +.github +eos-data/ +mariadb-data/ +test_data/ +.dockerignore +.env +.gitignore +docker-compose.yaml +Dockerfile +LICENSE +Makefile +NOTICE +README.md diff --git a/.env b/.env new file mode 100644 index 0000000..09f03ba --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +EOS_VERSION=latest +MARIADB_VERSION=11.1.6 +PYTHON_VERSION=3.12.6 diff --git a/.gitignore b/.gitignore index b779e98..e5342ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .venv docs +eos-data/ +mariadb-data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e57f2b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +ARG PYTHON_VERSION=3.12.6 +FROM python:${PYTHON_VERSION}-slim + +LABEL source="https://github.com/Akkudoktor-EOS/EOS" + +ARG APT_OPTS="--yes --auto-remove --no-install-recommends --no-install-suggests" +RUN DEBIAN_FRONTEND=noninteractive \ + apt-get update \ + && apt-get install ${APT_OPTS} gcc libhdf5-dev libmariadb-dev pkg-config \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /var/lib/eos +WORKDIR /opt/eos + +COPY requirements.txt requirements.txt + +RUN pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt + +COPY . . +COPY config.example.py config.py + +ENTRYPOINT [] + +CMD ["python", "flask_server.py"] diff --git a/Makefile b/Makefile index 6acfeb1..ceeb872 100644 --- a/Makefile +++ b/Makefile @@ -36,3 +36,7 @@ clean: run: @echo "Starting flask server, please wait..." .venv/bin/python ./flask_server.py + +# Run entire setup on docker +docker-run: + @docker-compose up diff --git a/config.example.py b/config.example.py index 4cee206..06a9034 100644 --- a/config.example.py +++ b/config.example.py @@ -1,25 +1,23 @@ from datetime import datetime, timedelta -prediction_hours=48 +prediction_hours=48 optimization_hours=24 strafe=10 moegliche_ladestroeme_in_prozent = [0.0 ,6.0/16.0, 7.0/16.0, 8.0/16.0, 9.0/16.0, 10.0/16.0, 11.0/16.0, 12.0/16.0, 13.0/16.0, 14.0/16.0, 15.0/16.0, 1.0 ] # Optional -db_config = { - 'user': '', - 'password': '', - 'host': '192.168.1.135', - 'database': '' +db_config = { + 'user': 'eos', + 'password': 'eos', + 'host': '127.0.0.1', + 'database': 'eos' } - - - + def get_start_enddate(prediction_hours=48,startdate=None): ############ - # Parameter + # Parameter ############ if startdate == None: date = (datetime.now().date() + timedelta(hours = prediction_hours)).strftime("%Y-%m-%d") diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..ddd1f26 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +--- +networks: + eos: + name: 'eos' +services: + eos: + image: 'akkudoktor/eos:${EOS_VERSION}' + build: + context: . + dockerfile: 'Dockerfile' + args: + PYTHON_VERSION: '${PYTHON_VERSION}' + depends_on: + - 'mariadb' + init: true + environment: {} + networks: + - 'eos' + volumes: + - ./eos-data:/data + mariadb: + image: 'mariadb:${MARIADB_VERSION}-jammy' + environment: + MARIADB_ROOT_PASSWORD: 'root' + MARIADB_DATABASE: 'eos' + MARIADB_USER: 'eos' + MARIADB_PASSWORD: 'eos' + networks: + - 'eos' + volumes: + - ./mariadb-data:/var/lib/mysql