Skip to content

Commit c5d8692

Browse files
committed
First Commit with first version of docker setup and readme instructions
0 parents  commit c5d8692

File tree

17 files changed

+688
-0
lines changed

17 files changed

+688
-0
lines changed

Diff for: .gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
README.md export-ignore
4+
CHANGELOG.md export-ignore
5+
/docs export-ignore

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.DS_Store

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Version](http://semver.org/spec/v2.0.0.html).
6+
7+
## [version] - date
8+
### Added
9+
10+
### Changed
11+
12+
### Removed

Diff for: README.md

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Magento 2 Dockergento
2+
3+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)]([email protected])
4+
5+
## Motivation
6+
7+
This project aims to offer a good performance solution for MAC users that want to use docker on development.
8+
This is a docker setup optimised for Magento2 on Mac. It has same performance as Linux or local setups.
9+
10+
## Main Features
11+
12+
### Overcome Docker for Mac performance issues on Magento 2
13+
14+
* Use docker volumens for following directories:
15+
16+
* vendor
17+
* generated
18+
* var
19+
* pub/static
20+
* pub/media
21+
22+
* Sincronise `vendor` and `generated` using a specific `sync` container. See [Sync vendor & generated section](#sync)
23+
24+
<details>
25+
<summary>Docker for Mac performance issues</summary>
26+
From [docker for mac documentation:](https://docs.docker.com/docker-for-mac/troubleshoot/#known-issues)
27+
28+
There are a number of issues with the performance of directories bind-mounted with osxfs. In particular, writes of small blocks, and traversals of large directories are currently slow. Additionally, containers that perform large numbers of directory operations, such as repeated scans of large directory trees, may suffer from poor performance. Applications that behave in this way include:
29+
30+
rake
31+
ember build
32+
Symfony
33+
Magento
34+
Zend Framework
35+
PHP applications that use Composer to install dependencies in a vendor folder
36+
37+
As a work-around for this behavior, you can put vendor or third-party library directories in Docker volumes, perform temporary file system operations outside of osxfs mounts, and use third-party tools like Unison or rsync to synchronize between container directories and bind-mounted directories. We are actively working on osxfs performance using a number of different techniques. To learn more, see the topic on Performance issues, solutions, and roadmap.
38+
39+
</details>
40+
41+
## Preconditions
42+
43+
0. Configure your docker `File Sharing` settings
44+
45+
![File Sharing Configuration](docs/img/file_sharing.png)
46+
47+
0. Optionally apply these performance tweaks
48+
49+
* [http://markshust.com/2018/01/30/performance-tuning-docker-mac](http://markshust.com/2018/01/30/performance-tuning-docker-mac)
50+
51+
## Installation
52+
53+
0. Copy this docker configuration repository in your project
54+
55+
`git archive --format=tar --remote=https://github.com/ModestCoders/magento2-dockergento.git HEAD | tar -xf -`
56+
57+
0. Edit your magento paths or nginx configuration if needed
58+
59+
60+
## Usage
61+
62+
### Start Application
63+
64+
```
65+
docker-compose up app
66+
docker-compose exec phpfpm composer install
67+
sudo vim /etc/hosts
68+
// Add -> 127.0.0.1 <your-domain>
69+
```
70+
71+
### Execute Magento commands
72+
73+
Magento commands must be executed inside the `php` container
74+
75+
```
76+
docker-compose exec phpfpm bash
77+
```
78+
79+
### <a name="sync"></a> Sync vendor and generated
80+
81+
There are 2 options to sync the volumes `vendor` and `generated`
82+
83+
#### Option 1: One time sync
84+
85+
This option must be used most of the times. You should only need to sync `vendor` and `generated` from time to time for debugging purposes
86+
87+
```
88+
docker-compose exec sync "sync -path <path_to_sync>"
89+
```
90+
91+
**NOTE:** `<path_to_sync>` should be `vendor` or `generated`. For faster and more specific syncs, you can include the subfolder path inside `vendor` like `sync -path vendor/<company_name>`.
92+
93+
#### Option 2: Watch
94+
95+
This option is only recommended if you are implementing code in a vendor module.
96+
97+
```
98+
docker-compose exec sync "watch -path <path_to_sync>"
99+
```
100+
101+
Example: `docker-compose exec sync "watch -path vendor/<company_name>/<module_name>"`
102+
103+
### Frontend
104+
105+
0. Start node container
106+
107+
```
108+
docker-compose up node
109+
```
110+
111+
0. NPM config setup (Only first time)
112+
113+
```
114+
docker-compose exec node bash
115+
cd magento && cp package.json.sample package.json && cp Gruntfile.js.sample Gruntfile.js
116+
npm install
117+
```
118+
119+
0. Grunt watch
120+
121+
```
122+
docker-compose exec node bash
123+
grunt exec:<theme>
124+
grunt watch
125+
```
126+
127+
## ChangeLog
128+
129+
[CHANGELOG.md](CHANGELOG.md)
130+
131+
## Developers
132+
133+
* [Juan Alonso](https://github.com/jalogut)
134+
* [Daniel Lozano](https://github.com/danielozano)
135+
* [Contributors](https://github.com/ModestCoders/magento2-dockergento/graphs/contributors)
136+
137+
Licence
138+
-------
139+
[GNU General Public License, version 3 (GPLv3)](http://opensource.org/licenses/gpl-3.0)
140+
141+
Copyright
142+
---------
143+
(c) ModestCoders

Diff for: config/docker/image/app-volumes/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM alpine:latest
2+
3+
RUN mkdir -p /var/www/html/vendor \
4+
/var/www/html/generated \
5+
/var/www/html/var \
6+
/var/www/html/pub/static \
7+
/var/www/html/pub/media
8+
9+
RUN chown -R 1000:1000 /var/www/html/vendor \
10+
/var/www/html/generated \
11+
/var/www/html/var \
12+
/var/www/html/pub/static \
13+
/var/www/html/pub/media

Diff for: config/docker/image/nginx/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM markoshust/magento-nginx:1.13-3
2+
3+
COPY ./conf/default.conf /etc/nginx/conf.d/

Diff for: config/docker/image/nginx/conf/default.conf

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# WEBSITES MAPPING
2+
map $http_host $MAGE_RUN_CODE {
3+
4+
default base;
5+
## For multi-store configuration add here your "domains <> website codes"
6+
# dominio-es.lo es;
7+
# dominio-ch.lo ch;
8+
# dominio-de.lo de;
9+
}
10+
11+
upstream fastcgi_backend {
12+
server unix:/sock/docker.sock;
13+
}
14+
15+
server {
16+
listen 8000;
17+
## Add here your domains or leave "localhost" wildcard
18+
server_name localhost;
19+
20+
set $MAGE_ROOT /var/www/html;
21+
set $MAGE_MODE developer;
22+
set $MAGE_RUN_TYPE website;
23+
24+
root $MAGE_ROOT/pub;
25+
26+
index index.php;
27+
autoindex off;
28+
charset off;
29+
30+
add_header 'X-Content-Type-Options' 'nosniff';
31+
32+
location /setup {
33+
root $MAGE_ROOT;
34+
35+
location ~ ^/setup/index.php {
36+
fastcgi_pass fastcgi_backend;
37+
fastcgi_index index.php;
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
include fastcgi_params;
40+
}
41+
42+
location ~ ^/setup/(?!pub/). {
43+
deny all;
44+
}
45+
46+
location ~ ^/setup/pub/ {
47+
add_header X-Frame-Options "SAMEORIGIN";
48+
}
49+
}
50+
51+
location /update {
52+
root $MAGE_ROOT;
53+
54+
location ~ ^/update/index.php {
55+
fastcgi_split_path_info ^(/update/index.php)(/.+)$;
56+
fastcgi_pass fastcgi_backend;
57+
fastcgi_index index.php;
58+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
59+
fastcgi_param PATH_INFO $fastcgi_path_info;
60+
include fastcgi_params;
61+
}
62+
63+
# deny everything but index.php
64+
location ~ ^/update/(?!pub/). {
65+
deny all;
66+
}
67+
68+
location ~ ^/update/pub/ {
69+
add_header X-Frame-Options "SAMEORIGIN";
70+
}
71+
}
72+
73+
location / {
74+
try_files $uri $uri/ /index.php?$args;
75+
}
76+
77+
location /pub {
78+
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
79+
deny all;
80+
}
81+
82+
alias $MAGE_ROOT/pub;
83+
add_header X-Frame-Options "SAMEORIGIN";
84+
}
85+
86+
location /static/ {
87+
if ($MAGE_MODE = "production") {
88+
expires max;
89+
}
90+
91+
# remove signature of static files used to overcome browser cache
92+
location ~ ^/static/version {
93+
rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
94+
}
95+
96+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
97+
add_header Cache-Control "public";
98+
add_header X-Frame-Options "SAMEORIGIN";
99+
expires +1y;
100+
101+
if (!-f $request_filename) {
102+
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
103+
}
104+
}
105+
106+
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
107+
add_header Cache-Control "no-store";
108+
add_header X-Frame-Options "SAMEORIGIN";
109+
expires off;
110+
111+
if (!-f $request_filename) {
112+
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
113+
}
114+
}
115+
116+
if (!-f $request_filename) {
117+
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
118+
}
119+
120+
add_header X-Frame-Options "SAMEORIGIN";
121+
}
122+
123+
location /media/ {
124+
try_files $uri $uri/ /get.php?$args;
125+
126+
location ~ ^/media/theme_customization/.*\.xml {
127+
deny all;
128+
}
129+
130+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
131+
add_header Cache-Control "public";
132+
add_header X-Frame-Options "SAMEORIGIN";
133+
expires +1y;
134+
try_files $uri $uri/ /get.php?$args;
135+
}
136+
137+
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
138+
add_header Cache-Control "no-store";
139+
add_header X-Frame-Options "SAMEORIGIN";
140+
expires off;
141+
try_files $uri $uri/ /get.php?$args;
142+
}
143+
144+
add_header X-Frame-Options "SAMEORIGIN";
145+
}
146+
147+
location /media/customer/ {
148+
deny all;
149+
}
150+
151+
location /media/downloadable/ {
152+
deny all;
153+
}
154+
155+
location /media/import/ {
156+
deny all;
157+
}
158+
159+
location ~ /media/theme_customization/.*\.xml$ {
160+
deny all;
161+
}
162+
163+
location /errors/ {
164+
try_files $uri =404;
165+
}
166+
167+
location ~ ^/errors/.*\.(xml|phtml)$ {
168+
deny all;
169+
}
170+
171+
location ~ cron\.php {
172+
deny all;
173+
}
174+
175+
location ~ (index|get|static|report|404|503)\.php$ {
176+
try_files $uri =404;
177+
fastcgi_pass fastcgi_backend;
178+
179+
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
180+
fastcgi_param PHP_VALUE "max_execution_time=600";
181+
fastcgi_read_timeout 600s;
182+
fastcgi_connect_timeout 600s;
183+
fastcgi_param MAGE_MODE $MAGE_MODE;
184+
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
185+
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
186+
187+
fastcgi_index index.php;
188+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
189+
include fastcgi_params;
190+
}
191+
}

0 commit comments

Comments
 (0)