Skip to content

Commit

Permalink
refs #2 add docker config files
Browse files Browse the repository at this point in the history
  • Loading branch information
mass-min committed Apr 22, 2019
1 parent 8c85305 commit a7cc6c8
Show file tree
Hide file tree
Showing 21 changed files with 71,996 additions and 14 deletions.
9 changes: 5 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
RESERBATH_DOMAIN=www.reserbath-local.jp

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=reserbath_mysql_1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_DATABASE=reserbath_dev
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
docker/mysql/tmp/

61 changes: 61 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: '3'

services:
mysql:
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
environment:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'reserbath_dev'
volumes:
- ./docker/mysql/tmp/mysql:/var/lib/mysql
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
ports:
- "3306:3306"
redis:
build:
context: .
dockerfile: ./docker/redis/Dockerfile
php:
build:
context: .
dockerfile: ./docker/php/Dockerfile
environment:
DB_HOST: $DB_HOST
tty: true
stdin_open: true
volumes:
- .:/usr/src/reserbath-web
- ./docker/php/php.ini:/usr/local/etc/php/php.ini
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- /usr/src/reserbath-web/vendor
depends_on:
- mysql
- redis
- nodejs
- mailhog
nginx:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
volumes:
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/reserbath.conf:/etc/nginx/conf.d/reserbath.conf
- ./public:/usr/src/reserbath-web/public
ports:
- "80:80"
depends_on:
- php
nodejs:
build:
context: .
dockerfile: ./docker/nodejs/Dockerfile
volumes:
- .:/usr/src/reserbath-web
- /usr/src/reserbath-web/node_modules
entrypoint: npm run dev
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025"
1 change: 1 addition & 0 deletions docker/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mysql:5.7.12
6 changes: 6 additions & 0 deletions docker/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[client]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
binlog-format=MIXED
innodb_buffer_pool_load_at_startup=OFF
10 changes: 10 additions & 0 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM nginx:1.15.6-alpine
ENV APP_ROOT /usr/src/reserbath-web

RUN mkdir $APP_ROOT

COPY ./public $APP_ROOT/public
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/nginx/conf.d/reserbath.conf /etc/nginx/conf.d/reserbath.conf

EXPOSE 80
32 changes: 32 additions & 0 deletions docker/nginx/conf.d/reserbath.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
server {
client_max_body_size 16M;
server_name *.reserbath-local.jp;
listen 80;
root /usr/src/reserbath-web/public;
index index.php;

# serve static files directly.
location ~* \.(jpg|jpeg|gif|png|js|css|ico|html)$ {
access_log off;
expires max;
}

# removes trailing slashes (prevents SEO duplicate content issues).
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}

# serve php contents.
location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~* \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
55 changes: 55 additions & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
user nginx;
worker_processes auto;

error_log /dev/stdout warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$host" "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /dev/stdout main;

sendfile on;
tcp_nopush on;

keepalive_timeout 65;

gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/x-javascript
application/xml
application/xml+rss
image/svg+xml;

server {
listen 80;

location = /health_check {
access_log off;
return 200 "healthy\n";
}
}

include /etc/nginx/conf.d/*.conf;
}
15 changes: 15 additions & 0 deletions docker/nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:8.15.0-alpine
ENV APP_ROOT /usr/src/reserbath-web

RUN mkdir -p $APP_ROOT
WORKDIR $APP_ROOT

COPY package.json $APP_ROOT
COPY package-lock.json $APP_ROOT

RUN apk add --update --no-cache \
git \
&& \
npm install

COPY . $APP_ROOT
52 changes: 52 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM node:8.15.0-alpine AS nodejs
ENV APP_ROOT /usr/src/reserbath-web

RUN mkdir -p $APP_ROOT
WORKDIR $APP_ROOT

COPY package.json $APP_ROOT
COPY package-lock.json $APP_ROOT

RUN apk add --update --no-cache \
git \
&& \
npm install

COPY . $APP_ROOT

RUN npm run production


FROM php:7.2.12-fpm-alpine3.8
ENV APP_ROOT /usr/src/reserbath-web
ENV COMPOSER_ALLOW_SUPERUSER 1

RUN mkdir $APP_ROOT
WORKDIR $APP_ROOT

COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/www.conf /usr/local/etc/php-fpm.d/www.conf
COPY docker/php/wait-for-it.sh /usr/src/wait-for-it.sh
COPY composer.json $APP_ROOT
COPY composer.lock $APP_ROOT

SHELL ["/bin/sh", "-o", "pipefail", "-c"]
RUN apk update && \
apk add --update --no-cache \
bash=4.4.19-r1 \
mysql-client \
zlib-dev \
&& \
NPROC="$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1)" && \
docker-php-ext-install -j"${NPROC}" pdo_mysql zip && \
wget https://raw.githubusercontent.com/composer/getcomposer.org/6cc488c7604093278748e0b4fb9b80f21141ecb8/web/installer -O - -q \
| php -- --quiet --install-dir=/usr/local/bin --filename composer && \
composer install --no-interaction --no-autoloader --no-scripts

COPY --from=nodejs $APP_ROOT $APP_ROOT

RUN composer dump-autoload --optimize

VOLUME /usr/src/reserbath-web/public/assets

ENTRYPOINT ["sh", "-c", "/usr/src/wait-for-it.sh $DB_HOST:3306 -t 60 -- php artisan migrate --force && docker-php-entrypoint php-fpm -R"]
Loading

0 comments on commit a7cc6c8

Please sign in to comment.