From e901c1b0d0ab89a6b39f989e008316e7626381c5 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sun, 6 Feb 2022 14:31:06 +0700 Subject: [PATCH] feat: add docker support --- .dockerignore | 15 +++++++++++++ .env.docker | 39 ++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ Dockerfile | 53 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 41 ++++++++++++++++++++++++++++++++--- docker-compose.yml | 25 ++++++++++++++++++++++ 6 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100755 .env.docker create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b33c3b1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.github/ +.idea/ +.vscode/ +tests +docker-compose.yml +.dockerignore +.editorconfig +.gitattributes +.gitignore +.styleci.yml +Dockerfile +phpunit.xml +README.md + +mysql \ No newline at end of file diff --git a/.env.docker b/.env.docker new file mode 100755 index 0000000..bc93ac2 --- /dev/null +++ b/.env.docker @@ -0,0 +1,39 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=false +APP_URL=http://localhost + +LOG_CHANNEL=stack + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/.gitignore b/.gitignore index 7be9e10..7a86d50 100755 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ npm-debug.log yarn-error.log .idea + +mysql/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e70e32f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +FROM php:7.4-apache + +RUN apt-get update + +# 1. development packages +RUN apt-get install -y \ + git \ + zip \ + curl \ + sudo \ + unzip \ + libicu-dev \ + libzip-dev \ + libbz2-dev \ + libpng-dev \ + libjpeg-dev \ + libmcrypt-dev \ + libreadline-dev \ + libfreetype6-dev \ + g++ + +# Set Apache Root +ENV APACHE_DOCUMENT_ROOT=/var/www/html/public +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +# Enable Some Apache Mod +RUN a2enmod rewrite headers + +RUN docker-php-ext-install \ + bz2 \ + intl \ + iconv \ + bcmath \ + opcache \ + calendar \ + pdo_mysql \ + zip + +# Composer +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer + +# Copy Source Code +COPY .env.docker /var/www/html/.env +COPY . /var/www/html + +# Change Working Directory +WORKDIR /var/www/html + +# Composer install and generate key +RUN composer install && php artisan key:generate + +RUN chown -R www-data:www-data /var/www/html \ No newline at end of file diff --git a/README.md b/README.md index c153e64..7b8ff5c 100755 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ ![Show Case](https://i.ibb.co/Mhryxcy/Todo-App-Preview-1.png) + # Todo App -Self Hosted Simple Looking Todo Application, powered by Open Source framework such as Laravel + Admin LTE, customizable also beginner will easily understand the flow and the structure of this application +Self Hosted Simple Looking Todo Application, powered by Open Source framework such as Laravel + Admin LTE, customizable +also beginner will easily understand the flow and the structure of this application ## Demo + - Host : https://todo.supanadit.com - Email : admin@email.com - Password : 123 ## Requirement + - PHP 7.4+ - Laravel 7.2.5+ ## Quick Start + - create a database called `todo` or whatever you want - create `.env` file - setup database configuration at `.env` file @@ -23,6 +28,7 @@ Self Hosted Simple Looking Todo Application, powered by Open Source framework su - `php artisan serve` #### Apache Configuration for Virtual Host + ```apacheconfig DocumentRoot "/srv/http/todo/public" @@ -42,17 +48,46 @@ Self Hosted Simple Looking Todo Application, powered by Open Source framework su ``` +## Docker Way + +1. `docker-compose up -d` + +### Run Migration + +```bash +docker-compose exec todo-app php artisan migrate +``` + +### Run Seeder + +```bash +docker-compose exec todo-app php artisan db:seed +``` + +### Troubleshooting MySQL Won't Run In Docker + +Run this script `sudo chown -R 1001:1001 mysql` + +Because we used Bitnami distribution version of MySQL, so we need to change the permission of mysql folder, since it +also described in docker page of bitnami + ## Note + If you want to use forgot password feature, you must provide your email and password at `.env` ## Support + [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N01CIMZ) ## License + Copyright 2020 Supan Adit Pratama -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the +License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " +AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific +language governing permissions and limitations under the License. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..27a9c1c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "2" +services: + mysql: + image: "bitnami/mysql:8.0" + ports: + - "3306:3306" + volumes: + - "./mysql:/bitnami/mysql/data" + environment: + - MYSQL_ROOT_PASSWORD=secret + - MYSQL_DATABASE=todo + + todo-app: + image: "supanadit/todo:latest" + ports: + - "80:80" + environment: + - DB_CONNECTION=mysql + - DB_HOST=mysql + - DB_PORT=3306 + - DB_DATABASE=todo + - DB_USERNAME=root + - DB_PASSWORD=secret + depends_on: + - mysql \ No newline at end of file