Skip to content

Commit

Permalink
Replace Elasticsearch to OpenSearch, upgrade component versions, adde…
Browse files Browse the repository at this point in the history
…d varnish
  • Loading branch information
ityetti committed Aug 24, 2023
1 parent 9cc2cb1 commit 42e7eb4
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 35 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

# Magento 2 Docker to Development (For Apple Silicon)

### Nginx (1.8) + Redis (6.2) + PHP-FPM (8.1) + MySQL (8.0.27) + XDebug (3.1.5) + Mailhog + RabbitMQ (3.9) + Elasticsearch (7.16.3)
### 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
- redis
- rabbitmq
- elasticsearch
- opensearch
- opensearch dashboard
- mailhog
- php-fpm
- nginx
- mysql
- nginx-proxy
- varnish

### Container nginx
Builds from the nginx folder. <br>
Expand Down Expand Up @@ -60,9 +62,17 @@ Opens up port: `1025` and `8025`
Starts a rabbitmq container.<br>
Opens up port: `5672` and `15672`

### Container elasticsearch:
Starts a elasticsearch container.<br>
Opens up port: `9200` and `9300`
### 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:
Starts a varnish container.<br>
Opens up port: `6082`

## Setup
Edit your `.env` file in root folder, change `PROJECT_NAME` and `PROJECT_VIRTUAL_HOST`:<br>
Expand All @@ -74,7 +84,7 @@ For example:
PROJECT_VIRTUAL_HOST=magento2.test

Edit your `/etc/hosts` and add next line:<br>
`127.0.0.1 magento2.test mail.magento2.test elastic.magento2.test rabbit.magento2.test`<br>
`127.0.0.1 magento2.test mail.magento2.test search.magento2.test dashboard.magento2.test rabbit.magento2.test`<br>

To start/build the stack.<br>
Use - `docker-compose up` or `docker-compose up -d` to run the container on detached mode.<br>
Expand All @@ -86,25 +96,27 @@ 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.4 /home/magento
./scripts/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.6-p2 /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 --admin-email=admin@admin.test --admin-user=admin --admin-password=admin1! --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --elasticsearch-host=elasticsearch --elasticsearch-port=9200
./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 --admin-email=admin@admin.test --admin-user=admin --admin-password=admin1! --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --opensearch-host=opensearch --opensearch-port=9200

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

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

## Feature Updates
- v1.0.0 - Stable release
- v1.0.1 - Updated to PHP 7.4.x, added docker-sync for MacOS users
- v1.0.2 - Fix xDebug, add rabbitmq management, fix email sending
- v1.0.3 - Updated to PHP 8.1.x
- v1.0.4 - Fix xDebug for stable work
- v1.0.5 - Replace Elasticsearch to OpenSearch, upgrade component versions, added varnish

## Branches
- master (for magento 2.4.4 and higher)
- master (for magento 2.4.6 and higher)
83 changes: 64 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ services:
nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: ${PROJECT_NAME}-nginx-proxy
restart: always
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx/nginx-proxy.conf:/etc/nginx/nginx.conf
networks:
- magento
depends_on:
- nginx
- php-fpm

nginx:
platform: linux/x86_64
build: ./nginx
container_name: ${PROJECT_NAME}-nginx
volumes:
Expand All @@ -25,13 +22,13 @@ services:
- mysql
- redis
- php-fpm
- nginx-proxy
networks:
- magento
environment:
- VIRTUAL_HOST=${PROJECT_VIRTUAL_HOST}

php-fpm:
platform: linux/x86_64
build: ./php-fpm
container_name: ${PROJECT_NAME}-php-fpm
volumes:
Expand All @@ -41,24 +38,23 @@ services:
- mysql
- redis
- rabbitmq
- elasticsearch
- opensearch
networks:
- magento
environment:
XDEBUG_CONFIG: "client_host=host.docker.internal"
PHP_IDE_CONFIG: "serverName=Docker"


redis:
image: redis:6.2
image: arm64v8/redis:7.0
container_name: ${PROJECT_NAME}-redis
ports:
- "6379:6379"
networks:
- magento

mysql:
platform: linux/x86_64
image: mysql:8.0.27
image: arm64v8/mysql:8.0.34
container_name: ${PROJECT_NAME}-mysql
volumes:
- ./mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
Expand Down Expand Up @@ -89,7 +85,7 @@ services:
- 8025

rabbitmq:
image: rabbitmq:3.9-management
image: arm64v8/rabbitmq:3.11-management
container_name: ${PROJECT_NAME}-rabbitmq
environment:
- VIRTUAL_HOST=rabbit.${PROJECT_VIRTUAL_HOST}
Expand All @@ -103,23 +99,72 @@ services:
expose:
- 15672

elasticsearch:
image: elasticsearch:7.16.3
container_name: ${PROJECT_NAME}-elasticsearch
opensearch:
image: opensearchproject/opensearch:2.5.0
container_name: ${PROJECT_NAME}-opensearch
ports:
- "9200:9200"
- "9300:9300"
- "9600:9600"
restart: always
networks:
- magento
environment:
- "discovery.type=single-node"
## Set custom heap size to avoid memory errors
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
- VIRTUAL_HOST=elastic.${PROJECT_VIRTUAL_HOST}
- "bootstrap.memory_lock=true"
- "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
hard: -1
nofile:
soft: 65536
hard: 65536

opensearch-dashboard:
image: opensearchproject/opensearch-dashboards:2.5.0
container_name: ${PROJECT_NAME}-opensearch-dashboard
restart: always
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
ports:
- "5601:5601"
expose:
- 9200
- "5601"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
hard: 65536

varnish:
image: arm64v8/varnish:7.3
container_name: ${PROJECT_NAME}-varnish
restart: always
networks:
- magento
ports:
- "6082:6082"
depends_on:
- nginx
links:
- nginx
volumes:
- ./varnish/varnish.vcl:/etc/varnish/default.vcl
environment:
- CACHE_SIZE=1G

networks:
magento:
Expand Down
2 changes: 1 addition & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:1.8
FROM arm64v8/nginx:1.22

RUN groupadd -g 2000 magento \
&& useradd -d /home/magento -u 2000 -g 2000 magento
Expand Down
7 changes: 7 additions & 0 deletions opensearch/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
server.host: '0.0.0.0'
server.port: 5601
opensearch.hosts: [http://localhost:9200]
opensearch.ssl.verificationMode: none
opensearch.username: magento
opensearch.password: magento
opensearch.requestHeadersWhitelist: [authorization, securitytenant]
4 changes: 2 additions & 2 deletions php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN if [ $(uname -m) = "x86_64" ]; then mailhog_arch="amd64"; else mailhog_arch=
&& go get . \
&& GOOS=linux GOARCH=${mailhog_arch} go build -o mhsendmail .

FROM php:8.1-fpm
FROM arm64v8/php:8.2-fpm as php

ARG MAGENTO_ROOT=/home/magento

Expand Down Expand Up @@ -99,7 +99,7 @@ RUN pecl install -o -f \
pcov \
raphf \
redis \
xdebug-3.1.5 \
xdebug-3.2.2 \
xmlrpc-1.0.0RC3 \
yaml

Expand Down
5 changes: 3 additions & 2 deletions php-fpm/etc/php-xdebug.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
; Xdebug settings will only kick in if the Xdebug module is loaded
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20210902/xdebug.so
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
xdebug.mode = debug
xdebug.client_port = 9003
xdebug.start_with_request = trigger
xdebug.discover_client_host = false
xdebug.scream = false
xdebug.show_local_vars = 1
xdebug.idekey = PHPSTORM
xdebug.idekey = PHPSTORM
xdebug.client_host=host.docker.internal
Loading

0 comments on commit 42e7eb4

Please sign in to comment.