diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..312db80 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12-bookworm + +RUN apt-get update +RUN apt install dumb-init + +COPY requirements.txt . +RUN pip install -r requirements.txt + +EXPOSE 8000 +EXPOSE 8001 + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/README.md b/README.md index dceccb6..3d89b00 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,17 @@ Use `pip install -r requirements.txt` to install the requirements. The usage of ### Step 4: Running the application Run the application by executing the file `EzLanManager.py` found at `src/ez_lan_manager`. Check the STDOUT for information regarding the port on which the application is now served. + +## Docker Deployment + +To get the docker compose setup running, you need to manually complete the following steps: + +1. Create a valid `config.toml` in the project root, so it gets copied over into the container. +2. Create the database user: +```sql +CREATE USER 'ez_lan_manager'@'%' IDENTIFIED BY 'PASSWORD'; +GRANT ALL PRIVILEGES ON ez_lan_manager.* TO 'ez_lan_manager'@'%'; +FLUSH PRIVILEGES; +``` +3. Make sure to **NOT** use the default passwords! +4. Apply the `create_database.sql` when starting the MariaDB container for the first time. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..229e059 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +services: + lan_manager: + build: . + depends_on: + db: + condition: service_healthy + environment: + PYTHONPATH: /opt/ez-lan-manager + ports: + - "8000:8000" + - "8001:8001" + volumes: + - ./:/opt/ez-lan-manager + entrypoint: ["/bin/sh", "-c", "cd /opt/ez-lan-manager/src && python3 /opt/ez-lan-manager/src/EzLanManager.py"] + + db: + image: mariadb:latest + environment: + MARIADB_ROOT_PASSWORD: Alkohol1 + MARIADB_DATABASE: ez_lan_manager + MARIADB_USER: ez_lan_manager + MARIADB_PASSWORD: Alkohol1 + healthcheck: + test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"] + interval: 5s + timeout: 3s + retries: 5 + ports: + - "127.0.0.1:3306:3306" + volumes: + - database:/var/lib/mysql + - ./sql/create_database.sql:/docker-entrypoint-initdb.d/init.sql + + +volumes: + database: diff --git a/requirements.txt b/requirements.txt index 08c2369..9cc8d0b 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/src/EzLanManager.py b/src/EzLanManager.py index bef7526..602df08 100644 --- a/src/EzLanManager.py +++ b/src/EzLanManager.py @@ -186,4 +186,7 @@ if __name__ == "__main__": } ) - sys.exit(app.run_as_web_server()) + sys.exit(app.run_as_web_server( + host="0.0.0.0", + port=8000, + ))