From a9147c3698d8093765fde2c361428fe9eae2ec7e Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Thu, 28 Dec 2023 11:35:42 +0100 Subject: [PATCH] dockerized the application for easier distribution and depleyment --- Dockerfile.db | 2 ++ Dockerfile.math_wizard | 18 +++++++++++++++++ MatheApp.sql | 43 +++++++++++++++------------------------ config.php | 2 +- docker-compose.yml | 46 ++++++++++++++++++++++++++++++++++++++++++ nginx.conf | 17 ++++++++++++++++ 6 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 Dockerfile.db create mode 100644 Dockerfile.math_wizard create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/Dockerfile.db b/Dockerfile.db new file mode 100644 index 0000000..36de6de --- /dev/null +++ b/Dockerfile.db @@ -0,0 +1,2 @@ +FROM mariadb +COPY ./MatheApp.sql /docker-entrypoint-initdb.d/ diff --git a/Dockerfile.math_wizard b/Dockerfile.math_wizard new file mode 100644 index 0000000..dc3859f --- /dev/null +++ b/Dockerfile.math_wizard @@ -0,0 +1,18 @@ +# Verwende ein Basisimage mit PHP +FROM php:8.2-cli + +# Setze das Arbeitsverzeichnis +WORKDIR /app + +# Kopiere den Projektinhalt in das Arbeitsverzeichnis im Container +COPY . . + +# Installiere die erforderlichen PHP-Erweiterungen +RUN docker-php-ext-install pdo pdo_mysql + +# Exponiere den Port, den der PHP-Server verwenden wird +EXPOSE 8080 + +# Starte den PHP-Server beim Containerstart +CMD ["php", "-S", "0.0.0.0:8080"] + diff --git a/MatheApp.sql b/MatheApp.sql index d940500..9a63939 100644 --- a/MatheApp.sql +++ b/MatheApp.sql @@ -1,6 +1,6 @@ --- MariaDB dump 10.19 Distrib 10.6.11-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.11-MariaDB, for debian-linux-gnu (x86_64) -- --- Host: localhost Database: MatheApp +-- Host: localhost Database: MatheApp -- ------------------------------------------------------ -- Server version 10.6.11-MariaDB-0ubuntu0.22.04.1 @@ -20,22 +20,22 @@ -- DROP TABLE IF EXISTS `user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `username` varchar(255) NOT NULL, - `vorname` varchar(255) NOT NULL, - `nachname` varchar(255) NOT NULL, - `email` varchar(255) NOT NULL, - `password` varchar(255) NOT NULL, - `lesson_count` int(11) NOT NULL, - `level` int(11) NOT NULL, - `xp` int(11) NOT NULL, - `coins` int(11) NOT NULL, - `isAdmin` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `reference_unique` (`username`,`email`) + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) NOT NULL, + `vorname` varchar(255) NOT NULL, + `nachname` varchar(255) NOT NULL, + `email` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `lesson_count` int(11) NOT NULL, + `level` int(11) NOT NULL, + `xp` int(11) NOT NULL, + `coins` int(11) NOT NULL, + `isAdmin` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `reference_unique` (`username`,`email`) ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -48,14 +48,3 @@ LOCK TABLES `user` WRITE; INSERT INTO `user` VALUES (3,'patryk','patryk','hegenberg','testMail@test.de','$2y$10$G8s3UA8zMjHnKAQ01B4.R.NX7gLZi28BuQiOVyBbnbYbNCZusx13W',1,3,110,566,NULL),(16,'admin','','','admin@themathwizard.de','$2y$10$M8DKsBn2KA49XCzdUzVY4.hciLBOzgzB94z3YR4hNyNgvwNlnXiyO',0,1,0,0,1); /*!40000 ALTER TABLE `user` ENABLE KEYS */; UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-01-24 21:17:03 diff --git a/config.php b/config.php index 6dd0087..41df759 100644 --- a/config.php +++ b/config.php @@ -2,7 +2,7 @@ return [ 'database' => [ - 'host' => 'localhost', + 'host' => 'db', 'port' => 3306, 'dbname' => 'MatheApp', 'charset' => 'utf8mb4' diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b22948e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,46 @@ +version: '3' + +services: + web: + #image: math_wizard + build: + context: /home/pata/dev/WebProg/TheMathWizard + dockerfile: Dockerfile.math_wizard + ports: + - "8080:8080" + depends_on: + - db + networks: + - mathwizard-network + + db: + build: + context: /home/pata/dev/WebProg/TheMathWizard + dockerfile: Dockerfile.db + environment: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: MatheApp + MYSQL_USER: MatheApp + MYSQL_PASSWORD: password + volumes: + - ./math_wizard_db_data:/var/lib/mysql + networks: + - mathwizard-network + + nginx: + image: nginx + ports: + - "80:80" + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + - web + networks: + - mathwizard-network + +volumes: + math_wizard_db_data: + +networks: + mathwizard-network: + driver: bridge diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..35621aa --- /dev/null +++ b/nginx.conf @@ -0,0 +1,17 @@ +events {} + +http { + server { + listen 80; + server_name math-wizard; + + location / { + proxy_pass http://web:8080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +} +