diff --git a/.gitignore b/.gitignore index 92fe3d69bdb1462bb9b93534545371025e709e0b..fd438a1bf80f6e4e3e21330e8c5c0eafa4fca16d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ -/mysql \ No newline at end of file +/mysql +/db-init/seeding/init.flag + +/app/storage/image/book_cover/* +!/app/storage/image/book_cover/.gitkeep +/app/storage/image/profile_pic/* +!/app/storage/image/profile_pic/.gitkeep +/app/storage/audio/* +!/app/storage/audio/.gitkeep \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fd71aacd317624da01632fbfc61c154c623ca6a7..42439ca05ceff62636087b2acb7da37e4b058ecf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,4 @@ WORKDIR /var/www/html # PHP extension and Apache configuration RUN docker-php-ext-install mysqli RUN a2enmod rewrite -RUN apt-get -y update && apt-get -y upgrade && apt-get install -y ffmpeg - -# Data seeding with Python script -# ... - -EXPOSE 80 \ No newline at end of file +RUN apt-get -y update && apt-get -y upgrade && apt-get install -y ffmpeg \ No newline at end of file diff --git a/app/controllers/BookController.php b/app/controllers/BookController.php index abbf3ce98a8cc847f0dd2fa10a986f9a8686749f..cd92b5bf4140c091d2d7976c33860f19f033f6c4 100644 --- a/app/controllers/BookController.php +++ b/app/controllers/BookController.php @@ -49,7 +49,6 @@ class BookController extends Controller implements ControllerInterface{ $audioFile = $_FILES['audio']['tmp_name']; $duration = (int) $fileHandler->getAudioDuration($audioFile); - $uploadedAudio = $fileHandler->saveAudioTo($audioFile, $_POST['title'], AUDIOBOOK_PATH); $uploadedImage = $fileHandler->saveImageTo($imageFile, $_POST['title'], BOOK_COVER_PATH); @@ -71,8 +70,6 @@ class BookController extends Controller implements ControllerInterface{ $title, $year, $summary, $price, $duration, $lang, $uploadedAudio, $uploadedImage, $authors, $genres ); - - error_log("Book ID: $bookId\n\n"); // header("Location: /public/song/detail/$bookId", true, 301); exit; diff --git a/app/main/SessionManager.php b/app/main/SessionManager.php new file mode 100644 index 0000000000000000000000000000000000000000..361adae2eeb306793c38f342560963012d01e698 --- /dev/null +++ b/app/main/SessionManager.php @@ -0,0 +1,14 @@ +<? +class SessionManager { + private static $instance = null; + + private function __construct() {} + + public static function getInstance() { + if (self::$instance == null) { + self::$instance = new SessionManager(); + } + return self::$instance; + } +} +?> \ No newline at end of file diff --git a/app/storage/audio/.gitkeep b/app/storage/audio/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scripts/build-image.sh b/build-image.sh similarity index 100% rename from scripts/build-image.sh rename to build-image.sh diff --git a/clean-run.sh b/clean-run.sh new file mode 100644 index 0000000000000000000000000000000000000000..99c7570ac3a3d7fcb70534871cdb3d8f954cd6f6 --- /dev/null +++ b/clean-run.sh @@ -0,0 +1,3 @@ +sh reset-db.sh +sh build-images.sh +docker-compose up \ No newline at end of file diff --git a/db-init/seeding/all.sh b/db-init/seeding/all.sh old mode 100644 new mode 100755 index 04f5ba9c4b4b539df35439832eee7278535dd2db..0694db82d40cb0ac3fecc897fab6b5fa72713f17 --- a/db-init/seeding/all.sh +++ b/db-init/seeding/all.sh @@ -1,4 +1,18 @@ -python3 user.py -python3 genre.py -python3 author.py -python3 book.py \ No newline at end of file +apt-get update +apt-get install -y python3 python3-pip + +pip3 install requests Faker + +# check if seeding has already been done +if [ ! -f init.flag ]; then + echo "Seeding database... ###########################################" + python3 user.py + python3 genre.py + python3 author.py + python3 book.py + touch init.flag +else + echo "Action already initiated. Skipping..." + +echo "Seeding complete." +fi \ No newline at end of file diff --git a/db-init/seeding/author.py b/db-init/seeding/author.py index d53e67eabd1c8c5122e4f2ed71ea3604b2c69363..19ff43c2f22d763de9cd29105510da22fd810487 100644 --- a/db-init/seeding/author.py +++ b/db-init/seeding/author.py @@ -1,13 +1,13 @@ import requests import random -api_url = 'http://localhost:8000/author/add' +api_url = 'http://web/author/add' print (""" - Seeding Authors - ==================================== - - ... +Seeding Authors +==================================== + +... """) # Authors Generator diff --git a/db-init/seeding/book.py b/db-init/seeding/book.py index 456164e6e06f9538dc9e3a93679e5adf98f4eca9..d551699b8baf36a73cf0773e91b6ee6f3803bb5b 100644 --- a/db-init/seeding/book.py +++ b/db-init/seeding/book.py @@ -3,17 +3,17 @@ import random import os print (""" - Seeding Books - ==================================== - - ... +Seeding Books +==================================== + +... """) NUM_OF_AUTHORS = 15 NUM_OF_GENRES = 15 -post_api = 'http://localhost:8000/book/add' +post_api = 'http://web/book/add' books = [] @@ -76,8 +76,8 @@ for b in books: 'title': title, 'year': year, 'summary': b['description'], - 'author': authors, - 'genre': genres, + 'authors[]': authors, + 'genres[]': genres, 'price': price, 'lang': 'English', } diff --git a/db-init/seeding/genre.py b/db-init/seeding/genre.py index 04d5ca3ed279339b013f2f37a041236fbfa379e8..b477fbd17bb08156bf4ced6ec40ed1a10aa44901 100644 --- a/db-init/seeding/genre.py +++ b/db-init/seeding/genre.py @@ -1,10 +1,10 @@ import requests print (""" - Seeding Genres - ==================================== - - ... +Seeding Genres +==================================== + +... """) BOOK_GENRES = [ @@ -25,7 +25,7 @@ BOOK_GENRES = [ "Classics" ] -api_url = 'http://localhost:8000/genre/add' +api_url = 'http://web/genre/add' for genre in BOOK_GENRES: data = { diff --git a/db-init/seeding/user.py b/db-init/seeding/user.py index 0bf8a74ab473ae301456b99f0f8bd963e27e9688..df31fb5bbcbac6761d6064e49ca88e8c87c0bb85 100644 --- a/db-init/seeding/user.py +++ b/db-init/seeding/user.py @@ -5,13 +5,13 @@ import os fake = Faker() -api_url = 'http://localhost:8000/user/register' +api_url = 'http://web/user/register' print (""" - Seeding Users - ==================================== - - ... +Seeding Users +==================================== + +... """) users = [] diff --git a/docker-compose.yml b/docker-compose.yml index bf9f9aa3a2b84f055bf4d0b9f01776f47b33745d..cc30bcad4ac2654117d7b21f331ceb8186dee340 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,7 @@ services: web: container_name: tubes-1 user: "1000:1000" - build: - context: . - dockerfile: Dockerfile - # image: tubes-1:latest + image: tubes-1:latest ports: - 8000:80 depends_on: @@ -15,6 +12,8 @@ services: - ./app:/var/www/html/ networks: - wbd-network + expose: + - '80' db: container_name: wbd-db image: mysql @@ -33,5 +32,17 @@ services: - '3306' networks: - wbd-network + data-seeding: + container_name: python-seeding + image: python:3.7 + volumes: + - ./db-init/seeding/:/app + working_dir: /app + command: ["sh", "all.sh"] + depends_on: + - web + - db + networks: + - wbd-network networks: wbd-network: \ No newline at end of file diff --git a/reset-db.sh b/reset-db.sh new file mode 100644 index 0000000000000000000000000000000000000000..f99d2aba6731c888034b5f6c3e965ad138c5c1cf --- /dev/null +++ b/reset-db.sh @@ -0,0 +1,15 @@ +sudo chown 1000 ./mysql/* +rm -rf ./mysql/* +touch ./mysql/.gitkeep + +sudo chown 1000 ./db-init/seeding/init.flag +rm -rf ./db-init/seeding/init.flag + +rm -rf ./app/storage/image/book_cover/* +touch ./app/storage/image/book_cover/.gitkeep + +rm -rf ./app/storage/image/profile_pic/* +touch ./app/storage/image/profile_pic/.gitkeep + +rm -rf ./app/storage/audio/* +touch ./app/storage/audio/.gitkeep \ No newline at end of file