feat: add docker support

This commit is contained in:
Supan Adit Pratama 2022-02-06 14:31:06 +07:00
parent a91ff6ecfd
commit e901c1b0d0
6 changed files with 172 additions and 3 deletions

15
.dockerignore Normal file
View File

@ -0,0 +1,15 @@
.github/
.idea/
.vscode/
tests
docker-compose.yml
.dockerignore
.editorconfig
.gitattributes
.gitignore
.styleci.yml
Dockerfile
phpunit.xml
README.md
mysql

39
.env.docker Executable file
View File

@ -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}"

2
.gitignore vendored
View File

@ -12,3 +12,5 @@ npm-debug.log
yarn-error.log yarn-error.log
.idea .idea
mysql/

53
Dockerfile Normal file
View File

@ -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

View File

@ -1,18 +1,23 @@
![Show Case](https://i.ibb.co/Mhryxcy/Todo-App-Preview-1.png) ![Show Case](https://i.ibb.co/Mhryxcy/Todo-App-Preview-1.png)
# Todo App # 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 ## Demo
- Host : https://todo.supanadit.com - Host : https://todo.supanadit.com
- Email : admin@email.com - Email : admin@email.com
- Password : 123 - Password : 123
## Requirement ## Requirement
- PHP 7.4+ - PHP 7.4+
- Laravel 7.2.5+ - Laravel 7.2.5+
## Quick Start ## Quick Start
- create a database called `todo` or whatever you want - create a database called `todo` or whatever you want
- create `.env` file - create `.env` file
- setup database configuration at `.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` - `php artisan serve`
#### Apache Configuration for Virtual Host #### Apache Configuration for Virtual Host
```apacheconfig ```apacheconfig
<VirtualHost *:80> <VirtualHost *:80>
DocumentRoot "/srv/http/todo/public" DocumentRoot "/srv/http/todo/public"
@ -42,17 +48,46 @@ Self Hosted Simple Looking Todo Application, powered by Open Source framework su
</VirtualHost> </VirtualHost>
``` ```
## 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 ## Note
If you want to use forgot password feature, you must provide your email and password at `.env` If you want to use forgot password feature, you must provide your email and password at `.env`
## Support ## Support
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N01CIMZ) [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N01CIMZ)
## License ## License
Copyright 2020 Supan Adit Pratama 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 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.

25
docker-compose.yml Normal file
View File

@ -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