From fdcdd8226026a495c1be4576a271d522f43868e7 Mon Sep 17 00:00:00 2001 From: "peter.fong" Date: Tue, 4 Feb 2025 21:05:09 +0000 Subject: [PATCH] weatherapp dockerized --- WeatherApp/Dockerfile | 36 ++++++++++++++++++ WeatherApp/docker-compose.yml | 20 ++++++++++ {weer_app => WeatherApp}/main.py | 0 {weer_app => WeatherApp}/modules/database.py | 0 WeatherApp/start.sh | 15 ++++++++ {weer_app => WeatherApp}/static/style.css | 0 {weer_app => WeatherApp}/templates/index.html | 0 energie/Dockerfile | 2 +- .../__pycache__/database.cpython-39.pyc | Bin 1555 -> 0 bytes 9 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 WeatherApp/Dockerfile create mode 100644 WeatherApp/docker-compose.yml rename {weer_app => WeatherApp}/main.py (100%) rename {weer_app => WeatherApp}/modules/database.py (100%) create mode 100644 WeatherApp/start.sh rename {weer_app => WeatherApp}/static/style.css (100%) rename {weer_app => WeatherApp}/templates/index.html (100%) delete mode 100644 weer_app/modules/__pycache__/database.cpython-39.pyc diff --git a/WeatherApp/Dockerfile b/WeatherApp/Dockerfile new file mode 100644 index 0000000..ea70d1c --- /dev/null +++ b/WeatherApp/Dockerfile @@ -0,0 +1,36 @@ +# Gebruik een officiƫle Python-image als basis +FROM python:3.9-slim + +RUN apt-get update && apt-get -y install cron nano && procps +# Werkdirectory instellen +WORKDIR /app + +# Kopieer je Python-bestanden naar de container +COPY . /app + +# Kopieer de requirements.txt naar de container +COPY requirements.txt . +# Kopieer de requirements.txt naar de container +COPY .env . + +# Installeer de vereiste Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Installeer cron en zorg ervoor dat de cron-demon actief is +RUN apt-get update && apt-get install -y cron + +# Voeg het cron-script toe +COPY cronfile.energie /etc/cron.d/cronfile.energie +# Zorg ervoor dat het cron-script uitvoerbaar is +RUN chmod 0644 /etc/cron.d/cronfile.energie + +# Voeg een cronjob toe die de Python-script dagelijks uitvoert +RUN crontab /etc/cron.d/cronfile.energie + + +# Voeg start.sh toe +COPY start.sh /start.sh +RUN chmod +x /start.sh + +# Gebruik start.sh om zowel cron als currentprice.py te starten +CMD ["/start.sh"] \ No newline at end of file diff --git a/WeatherApp/docker-compose.yml b/WeatherApp/docker-compose.yml new file mode 100644 index 0000000..fd7d0ea --- /dev/null +++ b/WeatherApp/docker-compose.yml @@ -0,0 +1,20 @@ +# docker compose -f energyprices_docker-compose.yml up -d --build + +version: "3.3" +services: + WeatherApp: + restart: always + container_name: WeatherApp + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/Amsterdam + - FLASK_ENV=production + - FLASK_APP=main.py + build: + dockerfile: ./Dockerfile + env_file: + - .env + deploy: + mode: replicated + replicas: 1 diff --git a/weer_app/main.py b/WeatherApp/main.py similarity index 100% rename from weer_app/main.py rename to WeatherApp/main.py diff --git a/weer_app/modules/database.py b/WeatherApp/modules/database.py similarity index 100% rename from weer_app/modules/database.py rename to WeatherApp/modules/database.py diff --git a/WeatherApp/start.sh b/WeatherApp/start.sh new file mode 100644 index 0000000..2ddfa07 --- /dev/null +++ b/WeatherApp/start.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Laad omgevingsvariabelen als .env bestaat +if [ -f .env ]; then + export $(grep -v '^#' .env | xargs) +fi + +# Start de cron-service correct +service cron start + +# Start de Flask-app met Gunicorn (betere productie-optie) +gunicorn --bind 0.0.0.0:5000 main:app --workers 4 & + +# Houd de container draaiende en log cron-uitvoer +tail -f /var/log/cron.log diff --git a/weer_app/static/style.css b/WeatherApp/static/style.css similarity index 100% rename from weer_app/static/style.css rename to WeatherApp/static/style.css diff --git a/weer_app/templates/index.html b/WeatherApp/templates/index.html similarity index 100% rename from weer_app/templates/index.html rename to WeatherApp/templates/index.html diff --git a/energie/Dockerfile b/energie/Dockerfile index ea70d1c..6d80330 100644 --- a/energie/Dockerfile +++ b/energie/Dockerfile @@ -1,7 +1,7 @@ # Gebruik een officiƫle Python-image als basis FROM python:3.9-slim -RUN apt-get update && apt-get -y install cron nano && procps +RUN apt-get update && apt-get -y install cron nano procps # Werkdirectory instellen WORKDIR /app diff --git a/weer_app/modules/__pycache__/database.cpython-39.pyc b/weer_app/modules/__pycache__/database.cpython-39.pyc deleted file mode 100644 index 8afb2256f5414d70e40d74aa8a293a438affbcbd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1555 zcmZ`(&1>UE6rUMMj$#s;E?sCB3Oe)f$ z8@Uv^^w!=>X-S}${!6;{)PJF;z9)agUb-XZ>CL>adB1t{~C6Z z4ht7gaheB66jMBALw?MZP}W&XsZ}mDDjpJ zEoCVi|F&{e4gZeXK~HY!c4RJJNdo~zUk&2PTN|f2KvM96`K%B~(JNZ=UPF|%AWcS5 zSk~e+3_&-n(l!u}G?{D6kp0DU4S)akTGy$*FqsU%v@*y+w>oJs8AFnr))|UgnU1bx z4y}vvC{NSaw5|cPFSD#QPSqqvGqpTuGnywke3G5X!FyX}G3IT~~iCwb8Dq#?lJp|_>Bv^aWke3-)+1IT=$ zq0*LDp-+47w=iiewU0)lRF7p6+}Tx<_Zwd0b^9g*Q0qu{TmNr%e0uWjH-7u1*FG8? zcAoVI&w7~NHOTxmz6k{;&{0NcEHb@Yo2`7mJUw~7w!&jWAWgmvNfpWa;^iH7TOLkM zJKa+f6Pn&pzrB_=oT{3z15C7`;)FL4OmY~yBgli-GLB0ph*JZoNadsViBKmgoy!U6 zX=$TR`A&tF2O;GCI#E=(hZcqi6E3&8E%vxwuX7i_*(d9web=hjs8NeZ8sGjKR#o%M4w^a!@ VoK!x^Q|W%bIK>lcNrrs5)_)Drb|3%%