From 08b1a62dc696a588cd061d046ab080fb1df76e3d Mon Sep 17 00:00:00 2001 From: jedi Date: Tue, 17 Dec 2019 01:33:40 +0100 Subject: [PATCH] first try at docker --- .gitignore | 1 + app/Http/Controllers/ItemController.php | 6 ++++ container/db/01_init.sql | 6 ++++ container/web/01_init.sh | 8 ++++++ docker-compose.yml | 37 +++++++++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 container/db/01_init.sql create mode 100644 container/web/01_init.sh create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 467f39c..e7a5ad8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ Homestead.json Homestead.yaml .env +.local /public/docs /public/staticimages /public/thumbnails diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index adb3108..6847cb6 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -37,17 +37,22 @@ class ItemController extends Controller public function showOneItem($event, $id) { + $eid = Event::where('slug','=',$event)->first()->eid; return response()->json(Item::find($id)); } public function create($event, Request $request) { + $eid = Event::where('slug','=',$event)->first()->eid; + $data = $request->all(); + $data['eid'] = $eid; $item = Item::create($request->all()); return response()->json($item, 201); } public function update($event, $id, Request $request) { + $eid = Event::where('slug','=',$event)->first()->eid; $item = Item::findOrFail($id); $item->update($request->all()); @@ -56,6 +61,7 @@ class ItemController extends Controller public function delete($event, $id) { + $eid = Event::where('slug','=',$event)->first()->eid; Item::findOrFail($id)->delete(); return response()->json(array("satus"=>'Deleted Successfully'), 200); } diff --git a/container/db/01_init.sql b/container/db/01_init.sql new file mode 100644 index 0000000..72a43cf --- /dev/null +++ b/container/db/01_init.sql @@ -0,0 +1,6 @@ +DROP DATABASE IF EXISTS lostfound; +CREATE DATABASE lostfound; + +CREATE OR REPLACE USER lostfound IDENTIFIED BY 'lostfound'; + +GRANT ALL privileges ON `lostfound`.* TO 'lostfound'; diff --git a/container/web/01_init.sh b/container/web/01_init.sh new file mode 100644 index 0000000..0176b21 --- /dev/null +++ b/container/web/01_init.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e +cd /app +echo "executing COMPOSER UPDATE" +composer update +echo "executing DATABASE MIGRATE" +php artisan migrate --force diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c0b81fe --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.6' +services: + webserver: + image: webdevops/php-nginx-dev + ports: + - "80:80" + volumes: + - ./:/app + - ./container/web/:/entrypoint.d + environment: + WEB_DOCUMENT_ROOT: /app/public + XDEBUG_REMOTE_HOST: marvin + links: + - dbserver + depends_on: + - dbserver + networks: + - backend + restart: on-failure + dbserver: + image: mariadb:latest + environment: + MYSQL_ROOT_PASSWORD: 'foobar' + MYSQL_DATABASE: ${DB_DATABASE} + MYSQL_USER: ${DB_USERNAME} + MYSQL_PASSWORD: ${DB_PASSWORD} + networks: + - backend + restart: on-failure + ports: + - "${DB_PORT}:3306" + volumes: + - ./.local/db:/var/lib/mysql + - ./container/db/:/docker-entrypoint-initdb.d +networks: + backend: + driver: bridge