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 8afb225..0000000 Binary files a/weer_app/modules/__pycache__/database.cpython-39.pyc and /dev/null differ