This commit is contained in:
Mohit Panjwani
2019-12-11 13:35:32 +05:30
6 changed files with 160 additions and 3 deletions

10
.dockerignore Normal file
View File

@ -0,0 +1,10 @@
.dockerignore
.gitignore
*.md
.git/
.idea/
.DS_Store/
docker-compose.*
LICENSE
nginx.conf
yarn.lock

View File

@ -5,11 +5,11 @@ APP_LOG_LEVEL=debug
APP_URL=http://crater.test
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=db
DB_PORT=3306
DB_DATABASE=crater
DB_USERNAME=root
DB_PASSWORD=bytefury
DB_USERNAME=crater
DB_PASSWORD=crater
BROADCAST_DRIVER=log
CACHE_DRIVER=file

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ Homestead.yaml
.rnd
/.expo
/.vscode
docker-compose.yml
docker-compose.yaml

52
Dockerfile Normal file
View File

@ -0,0 +1,52 @@
##### STAGE 1 #####
FROM composer as composer
# Copy composer files from project root into composer container's working dir
COPY composer.* /app/
# Copy database directory for autoloader optimization
COPY database /app/database
# Run composer to build dependencies in vendor folder
RUN composer install --no-scripts --no-suggest --no-interaction --prefer-dist --optimize-autoloader
# Copy everything from project root into composer container's working dir
COPY . /app
RUN composer dump-autoload --optimize --classmap-authoritative
##### STAGE 2 #####
FROM php:7.3.12-fpm-alpine
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN apk add --no-cache libpng-dev libxml2-dev oniguruma-dev && \
docker-php-ext-install bcmath ctype json gd mbstring pdo pdo_mysql tokenizer xml
# Set container's working dir
WORKDIR /app
# Copy everything from project root into php container's working dir
COPY . /app
# Copy vendor folder from composer container into php container
COPY --from=composer /app/vendor /app/vendor
RUN touch database/database.sqlite && \
cp .env.example .env && \
php artisan config:cache && \
php artisan passport:keys && \
php artisan key:generate && \
chown -R www-data:www-data . && \
chmod -R 755 . && \
chmod -R 775 storage/framework/ && \
chmod -R 775 storage/logs/ && \
chmod -R 775 bootstrap/cache/
EXPOSE 9000
CMD ["php-fpm", "--nodaemonize"]

View File

@ -0,0 +1,40 @@
version: '3.1'
services:
web:
image: nginx
depends_on:
- php
ports:
- 8080:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- app:/app
restart: always
php:
build: .
depends_on:
- db
expose:
- 9000
volumes:
- app:/app
restart: always
db:
image: mariadb
restart: always
volumes:
- db:/var/lib/mysql
environment:
MYSQL_USER: crater
MYSQL_PASSWORD: crater
MYSQL_DATABASE: crater
MYSQL_ROOT_PASSWORD: crater
volumes:
app:
db:

53
nginx.conf Normal file
View File

@ -0,0 +1,53 @@
worker_processes 8;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 4096;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80 default_server;
root /app/public;
index index.php;
charset utf-8;
access_log off;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header Content-Security-Policy "frame-ancestors 'self'";
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
}