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/ .github/
.idea/ .idea/
.vscode/ .vscode/
tests tests
docker-compose.dev.yml
docker-compose.yml docker-compose.yml
.dockerignore .dockerignore
.editorconfig .editorconfig
.gitattributes .gitattributes
.gitignore .gitignore
.styleci.yml .styleci.yml
vendor
Dockerfile Dockerfile
PHP.Dockerfile
phpunit.xml phpunit.xml
README.md README.md

View File

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

10
.gitignore vendored
View File

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

View File

@ -2,22 +2,7 @@ FROM php:7.4-apache
RUN apt-get update RUN apt-get update
# 1. development packages RUN apt-get install -y git zip
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 # Set Apache Root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public 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 # Enable Some Apache Mod
RUN a2enmod rewrite headers RUN a2enmod rewrite headers
RUN docker-php-ext-install \ RUN docker-php-ext-install pdo pdo_mysql
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
pdo_mysql \
zip
# Composer # Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/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 ### Run Migration
```bash ```bash
docker-compose exec todo-app php artisan migrate docker-compose exec short-app php artisan migrate
``` ```
### Run Seeder ### Run Seeder
```bash ```bash
docker-compose exec todo-app php artisan db:seed docker-compose exec short-app php artisan db:seed
``` ```
### Build Docker By Yourself ### 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 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 ### Troubleshooting MySQL Won't Run In Docker
Run this script `sudo chown -R 1001:1001 mysql` 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_ROOT_PASSWORD=secret
- MYSQL_DATABASE=short - MYSQL_DATABASE=short
todo-app: short-app:
image: "supanadit/short-url:1.0.2" build:
context: .
dockerfile: Dockerfile
ports: ports:
- "80:80" - "80:80"
environment: environment: