Skip to content

Commit

Permalink
Multi environment Docker configuration, resolve #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Jovert Lota Palonpon committed Apr 7, 2019
1 parent 9b02283 commit edc8871
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 34 deletions.
16 changes: 4 additions & 12 deletions .docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
FROM php:7.3-fpm

# Environment Variables
ENV MASTER_TZ=Asia/Manila
ENV MASTER_DIR=/var/www/html

RUN ln -snf /usr/share/zoneinfo/${MASTER_TZ} /etc/localtime && echo ${MASTER_TZ} > /etc/timezone

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libzip-dev \
Expand All @@ -21,15 +19,15 @@ RUN apt-get update && apt-get install -y \
git \
curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install bcmath pdo_mysql mbstring zip exif pcntl && \
docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ && \
docker-php-ext-install gd

# Install composer
# This will override default PHP configuration
COPY .docker/php-fpm/php.ini /usr/local/etc/php/conf.d/local.ini:ro

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# This will allow the container to use a cached version of PHP packages
Expand All @@ -38,19 +36,13 @@ COPY composer.lock composer.json ${MASTER_DIR}/
# This is included just to bypass errors thrown by composer scripts
COPY database ${MASTER_DIR}/database

WORKDIR ${MASTER_DIR}

# Install app dependencies
RUN composer install --no-interaction --no-plugins --no-scripts

# Copy app
COPY . ${MASTER_DIR}

# Copy scripts
COPY ./.docker/scripts/queuer.sh /usr/local/bin/laravel-queuer
COPY ./.docker/scripts/scheduler.sh /usr/local/bin/laravel-scheduler

# Give the scripts executable permissions
RUN chmod -R 775 /var/www/html/storage
RUN chmod u+x /usr/local/bin/laravel-queuer
RUN chmod u+x /usr/local/bin/laravel-scheduler

Expand Down
5 changes: 5 additions & 0 deletions .docker/webserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:alpine

COPY .docker/webserver/nginx.conf /etc/nginx/conf.d/nginx.conf

COPY . /var/www/html
33 changes: 33 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
services:
php-fpm:
volumes:
- ./:/var/www/html
- ./.docker/php-fpm/php.ini:/usr/local/etc/php/conf.d/local.ini:ro
environment:
APP_ENV: 'development'

scheduler:
volumes:
- ./:/var/www/html

queuer:
volumes:
- ./:/var/www/html

webserver:
ports:
- '80:80'
- '443:443'
volumes:
- ./:/var/www/html
- .docker/webserver/nginx.conf:/etc/nginx/conf.d/nginx.conf

db:
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: laravel-react-admin
MYSQL_ROOT_PASSWORD: secret
volumes:
- ~/.laravel-react-admin-data:/var/lib/mysql
19 changes: 19 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'
services:
php-fpm:
environment:
APP_ENV: 'production'

webserver:
ports:
- '80:80'
- '443:443'

db:
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: laravel-react-admin
MYSQL_ROOT_PASSWORD: secret
volumes:
- ~/.laravel-react-admin-data:/var/lib/mysql
27 changes: 5 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ services:
dockerfile: ./.docker/php-fpm/Dockerfile
image: laravel-react-admin-php-fpm
container_name: laravel-react-admin-php-fpm
restart: unless-stopped
working_dir: /var/www/html
volumes:
- ./:/var/www/html
- ./.docker/php-fpm/php.ini:/usr/local/etc/php/conf.d/local.ini:ro
restart: unless-stopped
env_file:
- .env

scheduler:
image: laravel-react-admin-php-fpm
container_name: laravel-react-admin-scheduler
volumes:
- ./:/var/www/html
depends_on:
- php-fpm
command: laravel-scheduler
Expand All @@ -28,37 +23,25 @@ services:
queuer:
image: laravel-react-admin-php-fpm
container_name: laravel-react-admin-queuer
volumes:
- ./:/var/www/html
depends_on:
- php-fpm
command: laravel-queuer
env_file:
- .env

webserver:
image: nginx:alpine
build:
context: .
dockerfile: ./.docker/webserver/Dockerfile
container_name: laravel-react-admin-webserver
working_dir: /var/www/html
restart: unless-stopped
ports:
- '80:80'
- '443:443'
volumes:
- ./:/var/www/html
- ./.docker/webserver/nginx.conf:/etc/nginx/conf.d/nginx.conf
depends_on:
- php-fpm

db:
image: mysql:5.7
container_name: laravel-react-admin-db
restart: unless-stopped
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: laravel-react-admin
MYSQL_ROOT_PASSWORD: secret
volumes:
- ~/.laravel-react-admin-data:/var/lib/mysql
depends_on:
- php-fpm

0 comments on commit edc8871

Please sign in to comment.