Skip to content

Commit

Permalink
Merge pull request #13 from ityetti/develop
Browse files Browse the repository at this point in the history
Add traefik, optimization for varnish, remove nginx-proxy, fix mysql config
  • Loading branch information
ityetti authored Nov 26, 2024
2 parents c41201e + 3ce46e3 commit 1e96ae1
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 115 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
![Magento 2](https://cdn.rawgit.com/rafaelstz/magento2-snippets-visualstudio/master/images/icon.png)

# Magento 2 Docker to Development (For Apple Silicon)
# Magento 2 Docker to Development (Apple Silicon)

### Nginx (1.22) + Redis (7.0) + PHP-FPM (8.2) + MySQL (8.0.34) + XDebug (3.2.2) + Mailhog + RabbitMQ (3.11) + OpenSearch (2.5.0) + Varnish (7.3)

The docker stack is composed of the following containers
- traefik
- nginx
- php-fpm
- redis
- mysql
- mailhog
- rabbitmq
- opensearch
- opensearch dashboard
- mailhog
- php-fpm
- nginx
- mysql
- nginx-proxy
- opensearch-dashboard
- varnish

### Container traefik
Starts a reverse proxy and load balancer for project<br>
Opens local port: `80`, `443`

### Container nginx
Builds from the nginx folder. <br>
Mounts the folder magento2 from the project main folder into the container volume `/home/magento`.<br>

### Container nginx-proxy
Starts a nginx-proxy container for use VIRTUAL_HOST.<br>
Opens local port: `80`

### Container php-fpm
Builds from the php-fpm folder.<br>
Mounts the folder magento2 from the project main folder into the container volume `/home/magento`.<br>
This container includes all dependencies for magento 2 (Also contain composer, code sniffer, xDebug etc.).<br>
This container includes all dependencies for Magento 2 (Also contain composer, code sniffer, xDebug etc.).<br>

### Container redis:
Starts a redis container.<br>
Opens up port: `6379`

### Container mysql:
Please change or set the mysql environment variables
Expand All @@ -56,23 +55,23 @@ Note: On your host, port 3306 might already be in use. So before running docker-

### Container mailhog:
Starts a mailhog container.<br>
Opens up port: `1025` and `8025`
Opens up port: `8025`

### Container rabbitmq:
Starts a rabbitmq container.<br>
Opens up port: `5672` and `15672`
Opens up port: `15672`

### Container opensearch:
Starts an opensearch container.<br>
Opens up port: `9200` and `9600`

### Container opensearch-dashboard:
Starts an opensearch dashboard container.<br>
Opens up port: `5601`

### Container varnish:
Builds from the varnish folder.
Starts a varnish container.<br>
Opens up port: `6082`
Opens up port: `6081`

## Setup
Edit your `.env` file in root folder, change `PROJECT_NAME` and `PROJECT_VIRTUAL_HOST`:<br>
Expand All @@ -96,19 +95,20 @@ You will check the latest version of Magento from link: https://magento.com/tech
To the run installation process use next commands.<br>
Create new project:

./scripts/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6-p2 /home/magento
./scripts/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7-p3 /home/magento
Install project:

./scripts/magento setup:install --base-url=http://magento2.test/ --db-host=mysql --db-name=magento_db --db-user=magento_user --db-password="PASSWD#" --admin-firstname=admin --admin-lastname=admin [email protected] --admin-user=admin --admin-password=admin1! --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --opensearch-host=opensearch --opensearch-port=9200
./scripts/magento setup:install --base-url=https://magento2.test/ --db-host=mysql --db-name=magento_db --db-user=magento_user --db-password="PASSWD#" --admin-firstname=admin --admin-lastname=admin [email protected] --admin-user=admin --admin-password=admin1! --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --opensearch-host=opensearch --opensearch-port=9200 --search-engine=opensearch

## Setting up Magento
To access the magento homepage, go to the following url: http://magento2.test<br>
To access the magento homepage, go to the following url: https://magento2.test<br>

Also, you can open:<br>
http://mail.magento2.test - **Mailhog**<br>
http://search.magento2.test - **OpenSearch**<br>
http://dashboard.magento2.test - **OpenSearch Dashboard**<br>
http://rabbit.magento2.test - **RabbitMQ** (guest/guest for access)<br>
https://traefik.magento2.test - **Traefik Dashboard** (traefik/traefik123 for access)<br>
https://mail.magento2.test - **Mailhog**<br>
https://search.magento2.test - **OpenSearch**<br>
https://dashboard.magento2.test - **OpenSearch Dashboard**<br>
https://rabbit.magento2.test - **RabbitMQ** (guest/guest for access)<br>

## Feature Updates
- v1.0.0 - Stable release
Expand All @@ -118,6 +118,7 @@ http://rabbit.magento2.test - **RabbitMQ** (guest/guest for access)<br>
- v1.0.4 - Fix xDebug for stable work
- v1.0.5 - Replace Elasticsearch to OpenSearch, upgrade component versions, added varnish
- v1.0.6 - Fix xDebug for correct stopping at point
- v1.0.7 - Add traefik, optimization for varnish, remove nginx-proxy

## Branches
- master (for magento 2.4.6 and higher)
Expand Down
122 changes: 80 additions & 42 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
version: '2'

services:
nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: ${PROJECT_NAME}-nginx-proxy
restart: always
reverse-proxy:
container_name: ${PROJECT_NAME}-traefik
image: arm64v8/traefik:3.2
command:
- "--api.insecure=false"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--log.level=DEBUG"
- "--providers.docker.exposedByDefault=false"
- "--providers.docker.network=magento"
- "--entrypoints.http.address=:80"
- "--entrypoints.https.address=:443"
- "--entrypoints.http.http.redirections.entrypoint.to=https"
- "--entrypoints.http.http.redirections.entrypoint.scheme=https"
- "--entrypoints.https.http.tls.certResolver=le"
- "--certificatesresolvers.le.acme.tlschallenge=true"
- "--certificatesresolvers.le.acme.email=admin@${PROJECT_VIRTUAL_HOST}"
- "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
- "traefik.http.routers.dashboard.rule=Host(`traefik.${PROJECT_VIRTUAL_HOST}`)"
- "traefik.http.routers.dashboard.entrypoints=https"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=traefik:$$apr1$$gNa7n0/R$$XOc09tOvpfv0FBWZ07upA1"
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx/nginx-proxy.conf:/etc/nginx/nginx.conf
- /var/run/docker.sock:/var/run/docker.sock
- ./letsencrypt:/letsencrypt
networks:
- magento

Expand All @@ -19,36 +40,33 @@ services:
volumes:
- ./magento2:/home/magento:cached
depends_on:
- mysql
- redis
- php-fpm
- nginx-proxy
networks:
- magento
environment:
- VIRTUAL_HOST=${PROJECT_VIRTUAL_HOST}
labels:
- "traefik.enable=false"

php-fpm:
build: ./php-fpm
container_name: ${PROJECT_NAME}-php-fpm
volumes:
- ./magento2:/home/magento:cached
- ./php-fpm/php.ini:/etc/php.ini
depends_on:
- mysql
- redis
- rabbitmq
- opensearch
networks:
- magento
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
environment:
PHP_IDE_CONFIG: "serverName=Docker"
XDEBUG_CONFIG: "client_host=host.docker.internal"


redis:
image: arm64v8/redis:7.0
container_name: ${PROJECT_NAME}-redis
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
ports:
- "6379:6379"
networks:
Expand All @@ -57,8 +75,11 @@ services:
mysql:
image: arm64v8/mysql:8.0.34
container_name: ${PROJECT_NAME}-mysql
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
volumes:
- ./mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
- ./mysql/mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf
environment:
MYSQL_DATABASE: 'magento_db'
MYSQL_ROOT_PASSWORD: 'root_pass'
Expand All @@ -74,39 +95,47 @@ services:
platform: linux/x86_64
image: mailhog/mailhog
container_name: ${PROJECT_NAME}-mailhog
environment:
- VIRTUAL_HOST=mail.${PROJECT_VIRTUAL_HOST}
- VIRTUAL_PORT=8025
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
- "traefik.http.routers.mailhog.rule=Host(`mail.${PROJECT_VIRTUAL_HOST}`)"
- "traefik.http.services.mailhog.loadbalancer.server.port=8025"
ports:
- "1025:1025"
- "8025:8025"
networks:
- magento
expose:
- 8025
- "8025"

rabbitmq:
image: arm64v8/rabbitmq:3.11-management
container_name: ${PROJECT_NAME}-rabbitmq
environment:
- VIRTUAL_HOST=rabbit.${PROJECT_VIRTUAL_HOST}
- VIRTUAL_PORT=15672
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
- "traefik.http.routers.rabbitmq.rule=Host(`rabbit.${PROJECT_VIRTUAL_HOST}`)"
- "traefik.http.routers.rabbitmq.middlewares=strip-docs"
- "traefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq"
- "traefik.http.services.rabbitmq.loadbalancer.server.port=15672"
ports:
- "15672:15672"
- "5672:5672"
restart: always
networks:
- magento
expose:
- 15672
- "15672"

opensearch:
image: opensearchproject/opensearch:2.5.0
container_name: ${PROJECT_NAME}-opensearch
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
- "traefik.http.routers.search.rule=Host(`search.${PROJECT_VIRTUAL_HOST}`)"
ports:
- "9200:9200"
- "9600:9600"
restart: always
networks:
- magento
environment:
Expand All @@ -115,8 +144,6 @@ services:
- "OPENSEARCH_JAVA_OPTS=-Xms2048m -Xmx2048m"
- "http.host=0.0.0.0"
- "DISABLE_SECURITY_PLUGIN=true"
- VIRTUAL_HOST=search.${PROJECT_VIRTUAL_HOST}
- VIRTUAL_PORT=9200
ulimits:
memlock:
soft: -1
Expand All @@ -128,16 +155,19 @@ services:
opensearch-dashboard:
image: opensearchproject/opensearch-dashboards:2.5.0
container_name: ${PROJECT_NAME}-opensearch-dashboard
restart: always
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
- "traefik.http.services.kibana-svc.loadbalancer.server.port=5601"
- "traefik.domain=dashboard.${PROJECT_VIRTUAL_HOST}"
- "traefik.http.routers.kibana-rtr.service=kibana-svc"
- "traefik.http.routers.kibana-rtr.entrypoints=https"
- "traefik.http.routers.kibana-rtr.rule=Host(`dashboard.${PROJECT_VIRTUAL_HOST}`)"
networks:
- magento
environment:
- VIRTUAL_HOST=dashboard.${PROJECT_VIRTUAL_HOST}
- VIRTUAL_PORT=5601
- "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true"
- "OPENSEARCH_HOSTS=http://opensearch:9200"
volumes:
- ./opensearch/opensearch_dashboards.yml:/usr/share/opensearch-dashboards/config/opensearch_dashboards.yml
- "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true"
ports:
- "5601:5601"
expose:
Expand All @@ -147,17 +177,22 @@ services:
soft: -1
hard: -1
nofile:
soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
soft: 65536
hard: 65536

varnish:
image: arm64v8/varnish:7.3
build: ./varnish
container_name: ${PROJECT_NAME}-varnish
restart: always
labels:
- "traefik.enable=true"
- "traefik.docker.network=magento"
- "traefik.http.routers.varnish.rule=Host(`${PROJECT_VIRTUAL_HOST}`)"
- "traefik.http.routers.varnish.entrypoints=https"
- "traefik.http.services.varnish.loadbalancer.server.port=6081"
networks:
- magento
ports:
- "6082:6082"
- "6081:6081"
depends_on:
- nginx
links:
Expand All @@ -166,6 +201,9 @@ services:
- ./varnish/varnish.vcl:/etc/varnish/default.vcl
environment:
- CACHE_SIZE=1G
expose:
- "6081"
command: ["varnishd", "-F", "-a", ":6081", "-b", "nginx:80"]

networks:
magento:
Expand Down
3 changes: 2 additions & 1 deletion mysql/mysqld.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_ALL_TABLES
symbolic-links=0

# Magento Settings #
auto_increment_increment=3
auto_increment_increment=3
log_bin_trust_function_creators=1
38 changes: 0 additions & 38 deletions nginx/nginx-proxy.conf

This file was deleted.

Loading

0 comments on commit 1e96ae1

Please sign in to comment.