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; + } + } + +}