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..1f7b486 --- /dev/null +++ b/.env.docker @@ -0,0 +1,39 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +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..2ba020b 100755 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ Homestead.yaml npm-debug.log yarn-error.log -.idea +.idea/ +.vscode/ + +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 eda9333..64ec5ad 100755 --- a/README.md +++ b/README.md @@ -51,6 +51,41 @@ This is url shortener application is similar to [bit.ly](http://bit.ly) ``` +## Docker Way + +This app can run inside docker with official support + +### Via Docker Compose + +```bash +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 +``` + +### Build Docker By Yourself + +```bash +docker build . -t supanadit/short-url:1.0.2 +``` + +### 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` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c243f53 --- /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=short + + todo-app: + image: "supanadit/short-url:1.0.2" + ports: + - "80:80" + environment: + - DB_CONNECTION=mysql + - DB_HOST=mysql + - DB_PORT=3306 + - DB_DATABASE=short + - DB_USERNAME=root + - DB_PASSWORD=secret + depends_on: + - mysql \ No newline at end of file