feat: docker usage for development

This commit is contained in:
Supan Adit Pratama 2022-05-02 21:30:06 +07:00
parent a0f995d00a
commit 70fa9caf7a
8 changed files with 109 additions and 35 deletions

View File

@ -1,14 +1,23 @@
.github/
.idea/
.vscode/
tests
docker-compose.dev.yml
docker-compose.yml
.dockerignore
.editorconfig
.gitattributes
.gitignore
.styleci.yml
vendor
Dockerfile
PHP.Dockerfile
phpunit.xml
README.md

View File

@ -1,5 +1,5 @@
APP_NAME=Laravel
APP_ENV=local
APP_ENV=production
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

10
.gitignore vendored
View File

@ -1,8 +1,8 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
node_modules/
public/hot/
public/storage/
storage/*.key/
vendor/
.env
.env.backup
.phpunit.result.cache

View File

@ -2,22 +2,7 @@ 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++
RUN apt-get install -y git zip
# Set Apache Root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
@ -27,15 +12,7 @@ RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf
# Enable Some Apache Mod
RUN a2enmod rewrite headers
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
pdo_mysql \
zip
RUN docker-php-ext-install pdo pdo_mysql
# Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

16
PHP.Dockerfile Normal file
View File

@ -0,0 +1,16 @@
FROM php:7.4-cli
RUN apt-get update
RUN apt-get install -y git zip
RUN docker-php-ext-install pdo pdo_mysql
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
# Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
WORKDIR /short
CMD [ "php", "artisan","serve" ,"--host","0.0.0.0"]

View File

@ -64,13 +64,13 @@ docker-compose up -d
### Run Migration
```bash
docker-compose exec todo-app php artisan migrate
docker-compose exec short-app php artisan migrate
```
### Run Seeder
```bash
docker-compose exec todo-app php artisan db:seed
docker-compose exec short-app php artisan db:seed
```
### Build Docker By Yourself
@ -79,6 +79,56 @@ docker-compose exec todo-app php artisan db:seed
docker build . -t supanadit/short-url:1.0.2
```
## Development Using Docker
### Run Application
```bash
docker-compose -f docker-compose.dev.yml up -d
```
### Installing / Updating Dependencies
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv short composer install # Composer Install
```
### Generate Key
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv short php artisan key:generate # Generate Key
```
### Database Migration
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv short php artisan migrate
```
### Database Seed
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv short php artisan db:seed
```
### Shutdown Application
```bash
docker-compose -f docker-compose.dev.yml down
```
### Updating `.env`
```bash
docker-compose -f docker-compose.dev.yml exec -w /srv short php artisan config:cache
```
### Rebuilding Dockerfile
```bash
docker-compose -f docker-compose.dev.yml build
```
### Troubleshooting MySQL Won't Run In Docker
Run this script `sudo chown -R 1001:1001 mysql`

20
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,20 @@
version: "3.8"
services:
todo:
build:
context: .
dockerfile: PHP.Dockerfile
ports:
- "8000:8000"
volumes:
- "./:/short"
mysqldb:
image: "bitnami/mysql:8.0"
ports:
- "3306:3306"
volumes:
- "./mysql:/bitnami/mysql/data"
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=short

View File

@ -10,8 +10,10 @@ services:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=short
todo-app:
image: "supanadit/short-url:1.0.2"
short-app:
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
environment: