From f83e98818a4023015058ca8a6d6a6e718570cfd1 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 2 May 2016 11:01:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B8=D1=87=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BA=D0=B5=D1=80=D0=B0=20(=D0=BF=D0=BE=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D1=83=D0=B0=D0=BB=D0=B0=D0=BC=20=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D0=BF=D0=B0=D1=81=D1=82=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 8 ++++++ .env | 16 +++++++++++ Dockerfile | 24 +++++++++++++++++ docker-compose.yml | 36 +++++++++++++++++++++++++ nginx/Dockerfile | 2 ++ nginx/nginx.conf | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+) create mode 100644 .dockerignore create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/Dockerfile create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..19bcbdb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git/* +.env +api/config/*-local.php +common/config/*-local.php +console/config/*-local.php +api/runtime +console/runtime +api/web/assets diff --git a/.env b/.env new file mode 100644 index 0000000..b068e70 --- /dev/null +++ b/.env @@ -0,0 +1,16 @@ +# Whether to enable debug mode in Yii. If not set this will be 0. +YII_DEBUG=1 + +# The application mode. If not set, this will be 'prod' +YII_ENV=dev + +# The log trace level. If not set, this will be 0 +#YII_TRACELEVEL=0 + +# Make sure that you provide a different unique cookie validation key in production +COOKIE_VALIDATION_KEY="SeCrEt_DeV_Key--DO-NOT-USE-IN-PRODUCTION!" + +# DB credentials. Default is to fetch the host form docker vars and use 'web' as db name, username and password +#DB_DSN=mysql:host=my.dbhost.com;dbname=web +#DB_USER=user +#DB_PASSWORD=secret diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7577d6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +#FROM codemix/yii2-base:2.0.8-apache +FROM codemix/yii2-base:2.0.8-php-fpm +#FROM codemix/yii2-base:2.0.8-hhvm + + +# Composer packages are installed first. This will only add packages +# that are not already in the yii2-base image. +COPY composer.json /var/www/html/ +COPY composer.lock /var/www/html/ +RUN composer self-update --no-progress && \ + composer install --no-progress --ignore-platform-reqs + +# Copy the working dir to the image's web root +COPY . /var/www/html + +# The following directories are .dockerignored to not pollute the docker images +# with local logs and published assets from development. So we need to create +# empty dirs and set right permissions inside the container. +RUN mkdir api/runtime api/web/assets console/runtime \ + && chown www-data:www-data api/runtime api/web/assets console/runtime + +# Expose everything under /var/www (vendor + html) +# This is only required for the nginx setup +VOLUME ["/var/www"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4c4d378 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +app: + build: ./ + expose: + - "9000" + volumes: + - ./:/var/www/html/ + links: + - db + environment: + ENABLE_ENV_FILE: 1 + ENABLE_LOCALCONF: 1 + API_TOKEN: "78bb3e46d818793a299ccfcedee213d5ecad07f7" + +web: + build: ./nginx + ports: + - "8080:80" + links: + - app + volumes_from: + - app + +db: + image: mariadb:10.0 + ports: + - "3306:3306" + expose: + - "3306" + environment: + MYSQL_ROOT_PASSWORD: secret-root + MYSQL_DATABASE: web + MYSQL_USER: web + MYSQL_PASSWORD: web + + # Uncomment to autostart at boottime + #restart: always diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..ceab9b8 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:1.9 +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..83e92db --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,67 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log 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] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + + set $root_path '/var/www/html'; + set $api_path '${root_path}/api/web'; + set $frontend_path '${root_path}/frontend/dist'; + + root $root_path; + charset utf-8; + client_max_body_size 100M; + + location / { + alias $frontend_path; + index index.html; + try_files $uri /index.html =404; + } + + location /api { + try_files $uri /api/web/index.php?$args; + } + + location ~* \.php$ { + fastcgi_pass app:9000; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } + + # Раздача статики для frontend + location ~* ^.+\.(html|jpg|jpeg|gif|png|svg|js|json|css|zip|rar|eot|ttf|woff|ico) { + root $frontend_path; + expires max; + access_log off; + } + + location ~* \.(htaccess|htpasswd|svn|git) { + deny all; + } + } + +}