Skip to content

Commit 59f1340

Browse files
authored
Merge pull request #8 from CottaCush/features/docker-setup
Docker setup
2 parents 497fe86 + 4ab364b commit 59f1340

File tree

7 files changed

+157
-5
lines changed

7 files changed

+157
-5
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git/*
2+
app/runtime
3+
app/web/assets
4+
vendor

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM codemix/yii2-base:2.0.11.2-php7-fpm
2+
3+
# Install Additional PHP extensions
4+
RUN apt-get update \
5+
&& apt-get -y install \
6+
libfreetype6-dev \
7+
libjpeg62-turbo-dev \
8+
libmcrypt-dev \
9+
libpng12-dev \
10+
libxslt-dev \
11+
--no-install-recommends \
12+
&& rm -r /var/lib/apt/lists/* \
13+
&& docker-php-ext-install iconv mcrypt xsl \
14+
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
15+
&& docker-php-ext-install gd
16+
17+
# Composer packages are installed first. This will only add packages
18+
# that are not already in the yii2-base image
19+
COPY composer.json /var/www/html/
20+
COPY composer.lock /var/www/html/
21+
RUN composer self-update --no-progress && \
22+
composer install --no-progress
23+
24+
# Copy the working dir to the image's web root
25+
COPY . /var/www/html
26+
27+
28+
# The following directories are .dockerignored to not pollute the docker images
29+
# with local logs and published assets from development. So we need to create
30+
# empty dirs and set right permissions inside the container.ADD
31+
32+
RUN mkdir app/runtime app/web/assets \
33+
&& chown www-data:www-data app/runtime app/web/assets
34+
35+
# Expose everything under the /var/www (vendor + html)
36+
# This is only required for the nginx setup
37+
VOLUME ["/var/www"]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ ant
7474
## Environment Variables
7575
Make a copy of `.env.sample` to `.env` in the env directory.
7676

77+
78+
## Docker
79+
80+
This project is dockerized using the LEMP stack. The stack consists of:
81+
- PHP 7
82+
- nginx
83+
84+
Inspired by [yii2-dockerized](https://github.com/codemix/yii2-dockerized/blob/master/Dockerfile)
85+
86+
### Installation
87+
[Mac](https://www.docker.com/docker-mac)
88+
[Windows](https://www.docker.com/docker-windows)
89+
[Ubuntu](https://www.docker.com/docker-ubuntu)
90+
91+
### Running Containers
92+
- Ensure docker is running
93+
- Change directory to project directory
94+
- Run the command `docker-compoose up`
95+
- To rebuild the containers after updates to docker config files, run `docker-composer up --build`
96+
97+
### Entering Container CLI
98+
- Run the command `docker ps`
99+
- Check the Container ID for container with image ending with "_web"
100+
- Run the command `docker exec -it [container_id] bash`
101+
77102
## Change log
78103

79104
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
"name": "cottacush/yii2-base-project",
33
"description": "A Yii 2 Base Project Template",
44
"keywords": ["yii2", "framework", "basic", "project template", "improved"],
5-
"version": "1.4.0",
65
"type": "project",
76
"license": "MIT",
87
"minimum-stability": "stable",
98
"require": {
10-
"php": ">=5.5.0",
9+
"php": "~5.5.0|~7.0",
1110
"yiisoft/yii2": ">=2.0.8",
1211
"yiisoft/yii2-bootstrap": "*",
1312
"yiisoft/yii2-swiftmailer": "*",
1413
"vlucas/phpdotenv": "^2.2",
1514
"lukasoppermann/http-status": "^2.0",
16-
"smilemd/yii2-htmlcompress": "^1.0"
15+
"smilemd/yii2-htmlcompress": "^1.0",
16+
"cottacush/yii2-utils": "~1.7.0"
1717
},
1818
"require-dev": {
1919
"yiisoft/yii2-codeception": "*",
@@ -26,8 +26,7 @@
2626
"phpmd/phpmd" : "@stable",
2727
"sebastian/phpcpd": "*",
2828
"theseer/phpdox": "*",
29-
"phpunit/phpunit": "4.8",
30-
"cottacush/yii2-utils": "~1.0.0"
29+
"phpunit/phpunit": "4.8"
3130
},
3231
"config": {
3332
"process-timeout": 1800,

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "2"
2+
3+
services:
4+
web:
5+
build: ./
6+
restart: always
7+
expose:
8+
- "9000"
9+
volumes:
10+
- ./:/var/www/html/
11+
environment:
12+
ENABLE_ENV_FILE: 1
13+
ENABLE_LOCALCONF: 1
14+
API_TOKEN: "<YOUR GITHUB API TOKEN>"
15+
16+
nginx:
17+
build: ./nginx
18+
restart: always
19+
ports:
20+
- "8080:80"
21+
links:
22+
- web
23+
volumes_from:
24+
- web

nginx/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx:1.13.0
2+
COPY nginx.conf /etc/nginx/nginx.conf

nginx/nginx.conf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
user nginx;
3+
worker_processes 1;
4+
5+
error_log /var/log/nginx/error.log warn;
6+
pid /var/run/nginx.pid;
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
#tcp_nopush on;
25+
26+
keepalive_timeout 65;
27+
28+
#gzip on;
29+
30+
server {
31+
charset utf-8;
32+
client_max_body_size 128M;
33+
34+
listen 80;
35+
36+
root /var/www/html/app/web;
37+
index index.php;
38+
39+
location / {
40+
# Redirect everything that isn't a real file to index.php
41+
try_files $uri $uri/ /index.php?$args;
42+
}
43+
44+
# uncomment to avoid processing of calls to non-existing static files by Yii
45+
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
46+
try_files $uri =404;
47+
}
48+
49+
location ~ \.php$ {
50+
include fastcgi_params;
51+
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
52+
fastcgi_pass web:9000;
53+
try_files $uri =404;
54+
}
55+
56+
location ~ /\.(ht|svn|git) {
57+
deny all;
58+
}
59+
}
60+
61+
}

0 commit comments

Comments
 (0)