diff --git a/.env b/.env new file mode 100644 index 0000000..cbaf9d7 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=mood diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a742e5..4ccf5b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,14 @@ # Changelog +## [1.1.0] +- Added Traefik to support multiple projects at a time +- Added Traefik instructions under traefik.md +- Added test directory to test Traefik for two projects +- Updated README for Traefik +- Moved standard docker setup under standard-setup directory + ## [1.0.3] -- Fixed TOC in READMe +- Fixed TOC in README - Fixed issues with PostGresQL ## [1.0.2] diff --git a/README.md b/README.md index 9e5f9a6..f70978a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This guide provides an overview of managing your docker setup that includes PHP, - [docker-compose.yml](#docker-composeyml) - [Services](#services) - [app](#app) + - [traefik](#traefik) - [phpfpm](#phpfpm) - [supervisor](#supervisor) - [postgres](#postgres) @@ -42,6 +43,8 @@ Contains configuration files for various services. - `nginx.default.conf`: Nginx configuration file. - `.env-app.local`: Environment file for Oro Commerce. - `supervisord.conf`: Supervisor configuration to manage background processes. +- `traefik.yml`: Traefik configuration for routing and services. +- `acme.json`: File for storing SSL certificates used by Traefik. #### src The base directory where the application source code is located. Mounted to `/var/www/html` within containers. @@ -89,6 +92,19 @@ Nginx is configured to serve PHP applications, utilizing FastCGI for processing 4. **Logs** Access and error logs are located at `/var/log/nginx/access.log` and `/var/log/nginx/error.log`, respectively. Monitor these logs for troubleshooting and performance analysis. +## traefik[↑](#table-of-contents) + +Traefik makes running multiple Docker projects easy with a few adjustments. By setting `COMPOSE_PROJECT_NAME` in a `.env` file, you assign unique project names, isolating container and network names to avoid conflicts. Setting unique hostnames in Traefik labels allows each instance to route traffic to its own services, ensuring projects run independently with separate configurations and customized routing. + +If you skip setting `COMPOSE_PROJECT_NAME`, Docker Compose defaults to the directory name as the project name. While this can prevent conflicts, explicitly defining project names provides more control and avoids potential confusion in complex directory setups. + +Traefik can be used for both single and multi-project setups. Traefik is great for handling automated routing, load balancing, and hostname management, but if you don’t need advanced routing, you can easily manage ports and networks manually. + +For simpler setup, check out the standard Docker guide [here](./standard-setup) if you’re working on a single project. + +For guidance on configuring multiple Docker projects with Traefik, refer to the [instructions here](./traefik.md). + + ## phpfpm[↑](#table-of-contents) Installed PHP extensions are: `bcmath`, `bz2`, `calendar`, `exif`, `ftp`, `gd`, `gettext`, `intl`, `mbstring`, `opcache`, `pcntl`, `soap`, `sockets`, `sodium`, `sysvmsg`, `sysvsem`, `sysvshm`, `xsl`, `zip` diff --git a/acme.json b/acme.json new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml index 864f24f..e203f05 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,6 @@ version: "3" services: app: image: adnnor/nginx:1.18 - ports: - - "80:8000" - - "443:8443" volumes: &appvolumes - ~/.composer:/var/www/.composer:cached - ~/.ssh:/var/www/.ssh:cached @@ -15,7 +12,13 @@ services: - ./conf/.env-app.local:/var/www/html/.env-app.local:cached - sockdata:/sock - ssldata:/etc/nginx/certs - + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.project1.rule=Host(`project1.local`)" + - "traefik.http.services.project1.loadbalancer.server.port=8000" + phpfpm: image: adnnor/php:8.3-fpm volumes: *appvolumes @@ -23,30 +26,55 @@ services: - oro env_file: env/phpfpm.env + traefik: + image: traefik:v2.5 + ports: + - "80:80" + - "443:443" + - "8080:8080" + - "8082:8082" + networks: + - oro + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "./traefik.yml:/etc/traefik/traefik.yml" + - "./acme.json:/acme.json" + labels: + - "traefik.enable=true" + # Web traffic routing for project1 + #- "traefik.http.routers.traefik-project1.rule=Host(`traefik.project1.local`)" + - "traefik.http.services.traefik-project1.loadbalancer.server.port=8000" + # Dashboard access + - "traefik.http.routers.traefik-dashboard.rule=Host(`traefik.project1.local`)" + - "traefik.http.routers.traefik-dashboard.service=api@internal" + - "traefik.http.services.traefik-dashboard.loadbalancer.server.port=8080" + +# supervisor: +# image: adnnor/supervisor +# volumes: +# - ./src:/var/www/html +# - ./conf/supervisord.conf:/etc/supervisord.conf +# depends_on: +# - phpfpm +# networks: +# - oro +# restart: always +# command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisord -n" + postgres: image: postgres:latest command: - "--max_connections=200" - "--shared_buffers=256MB" - ports: - - "5432:5432" env_file: env/postgres.env networks: - oro + labels: + - "traefik.enable=true" + - "traefik.tcp.routers.postgres-project1.rule=HostSNI(`postgres.project1.local`)" + - "traefik.tcp.services.postgres-project1.loadbalancer.server.port=5432" volumes: - postgres-data:/var/lib/postgresql/data - - supervisor: - image: adnnor/supervisor - volumes: - - ./src:/var/www/html - - ./conf/supervisord.conf:/etc/supervisord.conf - depends_on: - - phpfpm - networks: - - oro - restart: always - command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisord -n" pgadmin: image: dpage/pgadmin4 @@ -55,17 +83,20 @@ services: env_file: env/pgadmin.env networks: - oro - ports: - - "1435:80" + labels: + - "traefik.enable=true" + - "traefik.http.routers.pgadmin-project1.rule=Host(`pgadmin.project1.local`)" + - "traefik.http.services.pgadmin-project1.loadbalancer.server.port=80" volumes: - pgadmin-data:/var/lib/pgadmin restart: always elasticsearch: image: adnnor/elasticsearch:8.4 - ports: - - "9200:9200" - - "9300:9300" + labels: + - "traefik.enable=true" + - "traefik.http.routers.elasticsearch.rule=Host(`elasticsearch.project1.local`)" + - "traefik.http.services.elasticsearch.loadbalancer.server.port=9200" env_file: env/elasticsearch.env environment: - "discovery.type=single-node" @@ -78,25 +109,24 @@ services: ## Uncomment to increase the virtual memory map count - "max_map_count=262144" - redis: - image: redis:6.0-alpine - container_name: redis - ports: - - "6379:6379" +# redis: +# image: redis:6.0-alpine +# ports: +# - "6379:6379" - rabbitmq: - image: rabbitmq:3.11-management-alpine - ports: - - "15672:15672" - - "5672:5672" - volumes: - - rabbitmqdata:/var/lib/rabbitmq - env_file: env/rabbitmq.env +# rabbitmq: +# image: rabbitmq:3.11-management-alpine +# ports: +# - "15672:15672" +# - "5672:5672" +# volumes: +# - rabbitmqdata:/var/lib/rabbitmq +# env_file: env/rabbitmq.env - mailcatcher: - image: sj26/mailcatcher - ports: - - "1080:1080" +# mailcatcher: +# image: sj26/mailcatcher +# ports: +# - "1080:1080" networks: oro: diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 0000000..83f1549 --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,3 @@ + search engine config ### +ORO_SEARCH_URL=http://localhost:9200 +ORO_SEARCH_ENGINE_DSN=${ORO_SEARCH_URL}?prefix=oro_search +ORO_WEBSITE_SEARCH_ENGINE_DSN=${ORO_SEARCH_URL}?prefix=oro_website_search +###< search engine config ### + + +###> websocket config ### +ORO_WEBSOCKET_SERVER_DSN=//0.0.0.0:8080 +ORO_WEBSOCKET_FRONTEND_DSN=//*:8080/ws +ORO_WEBSOCKET_BACKEND_DSN=tcp://127.0.0.1:8080 +###< websocket config ### + +APP_DEBUG=1 diff --git a/standard-setup/conf/nginx.default.conf b/standard-setup/conf/nginx.default.conf new file mode 100644 index 0000000..cbb0d39 --- /dev/null +++ b/standard-setup/conf/nginx.default.conf @@ -0,0 +1,59 @@ +upstream fastcgi_backend { + server unix:/sock/docker.sock; +} + +server { + listen [::]:8000 ipv6only=on; + listen 8000; + + root /var/www/html/public; + + index index.php; + autoindex off; + charset off; + + fastcgi_buffer_size 64k; + fastcgi_buffers 8 128k; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + +server { + listen [::]:8443 ssl http2 ipv6only=on; + listen 8443 ssl http2; + + ssl_certificate /etc/nginx/certs/nginx.crt; + ssl_certificate_key /etc/nginx/certs/nginx.key; + + root /var/www/html/public; + + index index.php; + autoindex off; + charset off; + + fastcgi_buffer_size 64k; + fastcgi_buffers 8 128k; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + diff --git a/standard-setup/conf/supervisord.conf b/standard-setup/conf/supervisord.conf new file mode 100644 index 0000000..1cf440d --- /dev/null +++ b/standard-setup/conf/supervisord.conf @@ -0,0 +1,32 @@ +[unix_http_server] +file=/tmp/supervisor.sock + +[supervisord] +logfile=/var/log/supervisor/supervisord.log +loglevel=info +pidfile=/var/run/supervisor/supervisord.pid + +[supervisorctl] +serverurl=unix:///tmp/supervisor.sock + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[program:oro_web_socket] +command=/usr/local/bin/php /var/www/html/bin/console gos:websocket:server --env=prod +numprocs=1 +autostart=true +autorestart=true +directory=/var/www/html +user=app +redirect_stderr=true + +[program:oro_message_consumer] +command=/usr/local/bin/php /var/www/html/bin/console oro:message-queue:consume --env=prod +process_name=%(program_name)s_%(process_num)02d +numprocs=5 +autostart=true +autorestart=true +directory=/var/www/html +user=app +redirect_stderr=true diff --git a/standard-setup/docker-compose.yml b/standard-setup/docker-compose.yml new file mode 100644 index 0000000..864f24f --- /dev/null +++ b/standard-setup/docker-compose.yml @@ -0,0 +1,112 @@ +version: "3" + +services: + app: + image: adnnor/nginx:1.18 + ports: + - "80:8000" + - "443:8443" + volumes: &appvolumes + - ~/.composer:/var/www/.composer:cached + - ~/.ssh:/var/www/.ssh:cached + - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached + - ./src:/var/www/html:cached + - ./conf/nginx.default.conf:/etc/nginx/conf.d/default.conf:cached + - ./conf/.env-app.local:/var/www/html/.env-app.local:cached + - sockdata:/sock + - ssldata:/etc/nginx/certs + + phpfpm: + image: adnnor/php:8.3-fpm + volumes: *appvolumes + networks: + - oro + env_file: env/phpfpm.env + + postgres: + image: postgres:latest + command: + - "--max_connections=200" + - "--shared_buffers=256MB" + ports: + - "5432:5432" + env_file: env/postgres.env + networks: + - oro + volumes: + - postgres-data:/var/lib/postgresql/data + + supervisor: + image: adnnor/supervisor + volumes: + - ./src:/var/www/html + - ./conf/supervisord.conf:/etc/supervisord.conf + depends_on: + - phpfpm + networks: + - oro + restart: always + command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisord -n" + + pgadmin: + image: dpage/pgadmin4 + depends_on: + - postgres + env_file: env/pgadmin.env + networks: + - oro + ports: + - "1435:80" + volumes: + - pgadmin-data:/var/lib/pgadmin + restart: always + + elasticsearch: + image: adnnor/elasticsearch:8.4 + ports: + - "9200:9200" + - "9300:9300" + env_file: env/elasticsearch.env + environment: + - "discovery.type=single-node" + ## Avoid test failures due to small disks + ## More info at https://github.com/markshust/docker-magento/issues/488 + - "cluster.routing.allocation.disk.threshold_enabled=false" + - "index.blocks.read_only_allow_delete" + ## Uncomment to set custom heap size to avoid memory errors + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + ## Uncomment to increase the virtual memory map count + - "max_map_count=262144" + + redis: + image: redis:6.0-alpine + container_name: redis + ports: + - "6379:6379" + + rabbitmq: + image: rabbitmq:3.11-management-alpine + ports: + - "15672:15672" + - "5672:5672" + volumes: + - rabbitmqdata:/var/lib/rabbitmq + env_file: env/rabbitmq.env + + mailcatcher: + image: sj26/mailcatcher + ports: + - "1080:1080" + +networks: + oro: + driver: bridge + +volumes: + appdata: + dbdata: + rabbitmqdata: + pgadmin-data: + sockdata: + ssldata: + postgres-data: diff --git a/standard-setup/env/elasticsearch.env b/standard-setup/env/elasticsearch.env new file mode 100644 index 0000000..5856225 --- /dev/null +++ b/standard-setup/env/elasticsearch.env @@ -0,0 +1,2 @@ +ES_HOST=elasticsearch +ES_PORT=9200 diff --git a/standard-setup/env/mailtrap.env b/standard-setup/env/mailtrap.env new file mode 100644 index 0000000..394b769 --- /dev/null +++ b/standard-setup/env/mailtrap.env @@ -0,0 +1,8 @@ +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=587 +MAIL_USERNAME=60b0889ecafe2b +MAIL_PASSWORD=83c42e3c27db2d +MAIL_ENCRYPTION=tls +MAIL_FROM_ADDRESS=adnnor@gmail.com +MAIL_FROM_NAME="Adnan Shahzad" diff --git a/standard-setup/env/pgadmin.env b/standard-setup/env/pgadmin.env new file mode 100644 index 0000000..4c29e58 --- /dev/null +++ b/standard-setup/env/pgadmin.env @@ -0,0 +1,2 @@ +PGADMIN_DEFAULT_EMAIL=root@adnanshahzad.me +PGADMIN_DEFAULT_PASSWORD=root diff --git a/standard-setup/env/phpfpm.env b/standard-setup/env/phpfpm.env new file mode 100644 index 0000000..20c33e4 --- /dev/null +++ b/standard-setup/env/phpfpm.env @@ -0,0 +1 @@ +COMPOSER_DISABLE_XDEBUG_WARN=1 diff --git a/standard-setup/env/postgres.env b/standard-setup/env/postgres.env new file mode 100644 index 0000000..32a6d67 --- /dev/null +++ b/standard-setup/env/postgres.env @@ -0,0 +1,3 @@ +POSTGRES_USER=root +POSTGRES_PASSWORD=root +POSTGRES_DB=dev diff --git a/standard-setup/env/rabbitmq.env b/standard-setup/env/rabbitmq.env new file mode 100644 index 0000000..c83768a --- /dev/null +++ b/standard-setup/env/rabbitmq.env @@ -0,0 +1,5 @@ +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_DEFAULT_USER=rabbit +RABBITMQ_DEFAULT_PASS=rabbit +RABBITMQ_DEFAULT_VHOST=/ diff --git a/standard-setup/src/.gitkeep b/standard-setup/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/mood/.env b/test/mood/.env new file mode 100644 index 0000000..cbaf9d7 --- /dev/null +++ b/test/mood/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=mood diff --git a/test/mood/conf/.env-app.local b/test/mood/conf/.env-app.local new file mode 100644 index 0000000..882c70c --- /dev/null +++ b/test/mood/conf/.env-app.local @@ -0,0 +1,20 @@ +ORO_DB_URL=postgres://root:root@postgres:5432/dev?sslmode=disable&charset=utf8&serverVersion=13.7 +ORO_DB_DSN=${ORO_DB_URL} + +MESSENGER_TRANSPORT_DSN=rabbitmq://rabbit:rabbit@rabbitmq:5672/%2f/messages + + +###> search engine config ### +ORO_SEARCH_URL=http://localhost:9200 +ORO_SEARCH_ENGINE_DSN=${ORO_SEARCH_URL}?prefix=oro_search +ORO_WEBSITE_SEARCH_ENGINE_DSN=${ORO_SEARCH_URL}?prefix=oro_website_search +###< search engine config ### + + +###> websocket config ### +ORO_WEBSOCKET_SERVER_DSN=//0.0.0.0:8080 +ORO_WEBSOCKET_FRONTEND_DSN=//*:8080/ws +ORO_WEBSOCKET_BACKEND_DSN=tcp://127.0.0.1:8080 +###< websocket config ### + +APP_DEBUG=1 diff --git a/test/mood/conf/acme.json b/test/mood/conf/acme.json new file mode 100644 index 0000000..e69de29 diff --git a/test/mood/conf/nginx.default.conf b/test/mood/conf/nginx.default.conf new file mode 100644 index 0000000..cbb0d39 --- /dev/null +++ b/test/mood/conf/nginx.default.conf @@ -0,0 +1,59 @@ +upstream fastcgi_backend { + server unix:/sock/docker.sock; +} + +server { + listen [::]:8000 ipv6only=on; + listen 8000; + + root /var/www/html/public; + + index index.php; + autoindex off; + charset off; + + fastcgi_buffer_size 64k; + fastcgi_buffers 8 128k; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + +server { + listen [::]:8443 ssl http2 ipv6only=on; + listen 8443 ssl http2; + + ssl_certificate /etc/nginx/certs/nginx.crt; + ssl_certificate_key /etc/nginx/certs/nginx.key; + + root /var/www/html/public; + + index index.php; + autoindex off; + charset off; + + fastcgi_buffer_size 64k; + fastcgi_buffers 8 128k; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + diff --git a/test/mood/conf/supervisord.conf b/test/mood/conf/supervisord.conf new file mode 100644 index 0000000..1cf440d --- /dev/null +++ b/test/mood/conf/supervisord.conf @@ -0,0 +1,32 @@ +[unix_http_server] +file=/tmp/supervisor.sock + +[supervisord] +logfile=/var/log/supervisor/supervisord.log +loglevel=info +pidfile=/var/run/supervisor/supervisord.pid + +[supervisorctl] +serverurl=unix:///tmp/supervisor.sock + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[program:oro_web_socket] +command=/usr/local/bin/php /var/www/html/bin/console gos:websocket:server --env=prod +numprocs=1 +autostart=true +autorestart=true +directory=/var/www/html +user=app +redirect_stderr=true + +[program:oro_message_consumer] +command=/usr/local/bin/php /var/www/html/bin/console oro:message-queue:consume --env=prod +process_name=%(program_name)s_%(process_num)02d +numprocs=5 +autostart=true +autorestart=true +directory=/var/www/html +user=app +redirect_stderr=true diff --git a/test/mood/conf/traefik.yml b/test/mood/conf/traefik.yml new file mode 100644 index 0000000..2ed176d --- /dev/null +++ b/test/mood/conf/traefik.yml @@ -0,0 +1,28 @@ +entryPoints: + web: + address: ":80" + websecure: + address: ":443" + metrics: + address: ":8082" + +providers: + docker: + endpoint: "unix:///var/run/docker.sock" + exposedByDefault: false + +api: + dashboard: true + +accessLog: {} + +metrics: + prometheus: + entryPoint: metrics + buckets: + - 0.1 + - 0.3 + - 1.2 + - 5.0 + addEntryPointsLabels: true + addServicesLabels: true diff --git a/test/mood/docker-compose.yml b/test/mood/docker-compose.yml new file mode 100644 index 0000000..adbb391 --- /dev/null +++ b/test/mood/docker-compose.yml @@ -0,0 +1,155 @@ +version: "3" + +services: + app: + image: adnnor/nginx:1.18 + volumes: &appvolumes + - ~/.composer:/var/www/.composer:cached + - ~/.ssh:/var/www/.ssh:cached + - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached + - ./src:/var/www/html:cached + - ./conf/nginx.default.conf:/etc/nginx/conf.d/default.conf:cached + - ./conf/.env-app.local:/var/www/html/.env-app.local:cached + - sockdata:/sock + - ssldata:/etc/nginx/certs + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.mood.rule=Host(`mood.local`)" + - "traefik.http.services.mood.loadbalancer.server.port=8000" + + phpfpm: + image: adnnor/php:8.3-fpm + volumes: *appvolumes + networks: + - oro + env_file: env/phpfpm.env + + traefik: + image: traefik:v2.5 + ports: + - "80:80" + - "443:443" + - "8080:8080" + - "8082:8082" + networks: + - oro + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "./conf/traefik.yml:/etc/traefik/traefik.yml" + - "./conf/acme.json:/acme.json" + labels: + - "traefik.enable=true" + # Dashboard access + - "traefik.http.routers.traefik-dashboard-mood.rule=Host(`traefik.mood.local`)" + - "traefik.http.routers.traefik-dashboard-mood.service=api@internal" + #- "traefik.http.services.traefik-dashboard-mood.loadbalancer.server.port=8080" + + supervisor: + image: adnnor/supervisor + volumes: + - ./src:/var/www/html + - ./conf/supervisord.conf:/etc/supervisord.conf + depends_on: + - phpfpm + networks: + - oro + restart: always + command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisord -n" + + postgres: + image: postgres:latest + command: + - "--max_connections=200" + - "--shared_buffers=256MB" + env_file: env/postgres.env + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.tcp.routers.postgres-mood.rule=HostSNI(`postgres.mood.local`)" + - "traefik.tcp.services.postgres-mood.loadbalancer.server.port=5432" + volumes: + - postgres-data:/var/lib/postgresql/data + + pgadmin: + image: dpage/pgadmin4 + depends_on: + - postgres + env_file: env/pgadmin.env + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.pgadmin-mood.rule=Host(`pgadmin.mood.local`)" + - "traefik.http.services.pgadmin-mood.loadbalancer.server.port=80" + volumes: + - pgadmin-data:/var/lib/pgadmin + restart: always + + elasticsearch: + image: adnnor/elasticsearch:8.4 + labels: + - "traefik.enable=true" + - "traefik.http.routers.elasticsearch-mood.rule=Host(`elasticsearch.mood.local`)" + - "traefik.http.services.elasticsearch-mood.loadbalancer.server.port=9200" + env_file: env/elasticsearch.env + networks: + - oro + environment: + - "discovery.type=single-node" + ## Avoid test failures due to small disks + ## More info at https://github.com/markshust/docker-magento/issues/488 + - "cluster.routing.allocation.disk.threshold_enabled=false" + - "index.blocks.read_only_allow_delete" + ## Uncomment to set custom heap size to avoid memory errors + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + ## Uncomment to increase the virtual memory map count + - "max_map_count=262144" + ## Prefer to disable security features on local + - "xpack.security.enabled=false" + + redis: + image: redis:6.0-alpine + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.tcp.services.redis-mood.loadbalancer.server.port=6379" + + rabbitmq: + image: rabbitmq:3.11-management-alpine + volumes: + - rabbitmqdata:/var/lib/rabbitmq + env_file: env/rabbitmq.env + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.rabbitmq-ui-mood.rule=Host(`rabbitmq.mood.local`)" # UI access + - "traefik.http.services.rabbitmq-ui-mood.loadbalancer.server.port=15672" + - "traefik.tcp.services.rabbitmq-amqp-mood.loadbalancer.server.port=5672" + + mailcatcher: + image: sj26/mailcatcher + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.mailcatcher-mood.rule=Host(`mailcatcher.mood.local`)" + - "traefik.http.services.mailcatcher-mood.loadbalancer.server.port=1080" + + +networks: + oro: + driver: bridge + +volumes: + appdata: + dbdata: + rabbitmqdata: + pgadmin-data: + sockdata: + ssldata: + postgres-data: diff --git a/test/mood/env/elasticsearch.env b/test/mood/env/elasticsearch.env new file mode 100644 index 0000000..5856225 --- /dev/null +++ b/test/mood/env/elasticsearch.env @@ -0,0 +1,2 @@ +ES_HOST=elasticsearch +ES_PORT=9200 diff --git a/test/mood/env/mailtrap.env b/test/mood/env/mailtrap.env new file mode 100644 index 0000000..394b769 --- /dev/null +++ b/test/mood/env/mailtrap.env @@ -0,0 +1,8 @@ +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=587 +MAIL_USERNAME=60b0889ecafe2b +MAIL_PASSWORD=83c42e3c27db2d +MAIL_ENCRYPTION=tls +MAIL_FROM_ADDRESS=adnnor@gmail.com +MAIL_FROM_NAME="Adnan Shahzad" diff --git a/test/mood/env/pgadmin.env b/test/mood/env/pgadmin.env new file mode 100644 index 0000000..4c29e58 --- /dev/null +++ b/test/mood/env/pgadmin.env @@ -0,0 +1,2 @@ +PGADMIN_DEFAULT_EMAIL=root@adnanshahzad.me +PGADMIN_DEFAULT_PASSWORD=root diff --git a/test/mood/env/phpfpm.env b/test/mood/env/phpfpm.env new file mode 100644 index 0000000..20c33e4 --- /dev/null +++ b/test/mood/env/phpfpm.env @@ -0,0 +1 @@ +COMPOSER_DISABLE_XDEBUG_WARN=1 diff --git a/test/mood/env/postgres.env b/test/mood/env/postgres.env new file mode 100644 index 0000000..32a6d67 --- /dev/null +++ b/test/mood/env/postgres.env @@ -0,0 +1,3 @@ +POSTGRES_USER=root +POSTGRES_PASSWORD=root +POSTGRES_DB=dev diff --git a/test/mood/env/rabbitmq.env b/test/mood/env/rabbitmq.env new file mode 100644 index 0000000..c83768a --- /dev/null +++ b/test/mood/env/rabbitmq.env @@ -0,0 +1,5 @@ +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_DEFAULT_USER=rabbit +RABBITMQ_DEFAULT_PASS=rabbit +RABBITMQ_DEFAULT_VHOST=/ diff --git a/test/mood/src/.env-app.local b/test/mood/src/.env-app.local new file mode 100644 index 0000000..e69de29 diff --git a/test/mood/src/public/index.php b/test/mood/src/public/index.php new file mode 100644 index 0000000..83f1549 --- /dev/null +++ b/test/mood/src/public/index.php @@ -0,0 +1,3 @@ + search engine config ### +ORO_SEARCH_URL=http://localhost:9200 +ORO_SEARCH_ENGINE_DSN=${ORO_SEARCH_URL}?prefix=oro_search +ORO_WEBSITE_SEARCH_ENGINE_DSN=${ORO_SEARCH_URL}?prefix=oro_website_search +###< search engine config ### + + +###> websocket config ### +ORO_WEBSOCKET_SERVER_DSN=//0.0.0.0:8080 +ORO_WEBSOCKET_FRONTEND_DSN=//*:8080/ws +ORO_WEBSOCKET_BACKEND_DSN=tcp://127.0.0.1:8080 +###< websocket config ### + +APP_DEBUG=1 diff --git a/test/vibe/conf/acme.json b/test/vibe/conf/acme.json new file mode 100644 index 0000000..e69de29 diff --git a/test/vibe/conf/nginx.default.conf b/test/vibe/conf/nginx.default.conf new file mode 100644 index 0000000..cbb0d39 --- /dev/null +++ b/test/vibe/conf/nginx.default.conf @@ -0,0 +1,59 @@ +upstream fastcgi_backend { + server unix:/sock/docker.sock; +} + +server { + listen [::]:8000 ipv6only=on; + listen 8000; + + root /var/www/html/public; + + index index.php; + autoindex off; + charset off; + + fastcgi_buffer_size 64k; + fastcgi_buffers 8 128k; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + +server { + listen [::]:8443 ssl http2 ipv6only=on; + listen 8443 ssl http2; + + ssl_certificate /etc/nginx/certs/nginx.crt; + ssl_certificate_key /etc/nginx/certs/nginx.key; + + root /var/www/html/public; + + index index.php; + autoindex off; + charset off; + + fastcgi_buffer_size 64k; + fastcgi_buffers 8 128k; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_pass fastcgi_backend; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} + diff --git a/test/vibe/conf/supervisord.conf b/test/vibe/conf/supervisord.conf new file mode 100644 index 0000000..1cf440d --- /dev/null +++ b/test/vibe/conf/supervisord.conf @@ -0,0 +1,32 @@ +[unix_http_server] +file=/tmp/supervisor.sock + +[supervisord] +logfile=/var/log/supervisor/supervisord.log +loglevel=info +pidfile=/var/run/supervisor/supervisord.pid + +[supervisorctl] +serverurl=unix:///tmp/supervisor.sock + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[program:oro_web_socket] +command=/usr/local/bin/php /var/www/html/bin/console gos:websocket:server --env=prod +numprocs=1 +autostart=true +autorestart=true +directory=/var/www/html +user=app +redirect_stderr=true + +[program:oro_message_consumer] +command=/usr/local/bin/php /var/www/html/bin/console oro:message-queue:consume --env=prod +process_name=%(program_name)s_%(process_num)02d +numprocs=5 +autostart=true +autorestart=true +directory=/var/www/html +user=app +redirect_stderr=true diff --git a/test/vibe/conf/traefik.yml b/test/vibe/conf/traefik.yml new file mode 100644 index 0000000..8769dfc --- /dev/null +++ b/test/vibe/conf/traefik.yml @@ -0,0 +1,15 @@ +entryPoints: + web: + address: ":80" + websecure: + address: ":443" + +providers: + docker: + endpoint: "unix:///var/run/docker.sock" + exposedByDefault: false + +api: + dashboard: true + +accessLog: {} diff --git a/test/vibe/docker-compose.yml b/test/vibe/docker-compose.yml new file mode 100644 index 0000000..d0e4d63 --- /dev/null +++ b/test/vibe/docker-compose.yml @@ -0,0 +1,141 @@ +version: "3" + +services: + app: + image: adnnor/nginx:1.18 + volumes: &appvolumes + - ~/.composer:/var/www/.composer:cached + - ~/.ssh:/var/www/.ssh:cached + - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached + - ./src:/var/www/html:cached + - ./conf/nginx.default.conf:/etc/nginx/conf.d/default.conf:cached + - ./conf/.env-app.local:/var/www/html/.env-app.local:cached + - sockdata:/sock + - ssldata:/etc/nginx/certs + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.vibe.rule=Host(`vibe.local`)" + - "traefik.http.services.vibe.loadbalancer.server.port=8000" + + phpfpm: + image: adnnor/php:8.3-fpm + volumes: *appvolumes + networks: + - oro + env_file: env/phpfpm.env + + traefik: + image: traefik:v2.5 + ports: + - "8088:80" + - "8443:443" + - "8083:8080" + networks: + - oro + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "./conf/traefik.yml:/etc/traefik/traefik.yml" + - "./conf/acme.json:/acme.json" + labels: + - "traefik.enable=true" + # Dashboard access + - "traefik.http.routers.traefik-dashboard-vibe.rule=Host(`traefik.vibe.local`)" + - "traefik.http.routers.traefik-dashboard-vibe.service=api@internal" + #- "traefik.http.services.traefik-dashboard-vibe.loadbalancer.server.port=8083" + + supervisor: + image: adnnor/supervisor + volumes: + - ./src:/var/www/html + - ./conf/supervisord.conf:/etc/supervisord.conf + depends_on: + - phpfpm + networks: + - oro + restart: always + command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisoro2network -n" + + postgres: + image: postgres:latest + command: + - "--max_connections=200" + - "--shared_buffers=256MB" + env_file: env/postgres.env + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.tcp.routers.postgres-vibe.rule=HostSNI(`postgres.vibe.local`)" + - "traefik.tcp.services.postgres-vibe.loadbalancer.server.port=5432" + volumes: + - postgres-data:/var/lib/postgresql/data + + pgadmin: + image: dpage/pgadmin4 + depends_on: + - postgres + env_file: env/pgadmin.env + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.pgadmin-vibe.rule=Host(`pgadmin.vibe.local`)" + - "traefik.http.services.pgadmin-vibe.loadbalancer.server.port=80" + volumes: + - pgadmin-data:/var/lib/pgadmin + restart: always + + elasticsearch: + image: adnnor/elasticsearch:8.4 + labels: + - "traefik.enable=true" + - "traefik.http.routers.elasticsearch-vibe.rule=Host(`elasticsearch.vibe.local`)" + - "traefik.http.services.elasticsearch-vibe.loadbalancer.server.port=9200" + env_file: env/elasticsearch.env + environment: + - "discovery.type=single-node" + ## Avoid test failures due to small disks + ## More info at https://github.com/markshust/docker-magento/issues/488 + - "cluster.routing.allocation.disk.threshold_enabled=false" + - "index.blocks.read_only_allow_delete" + ## Uncomment to set custom heap size to avoid memory errors + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + ## Uncomment to increase the virtual memory map count + - "max_map_count=262144" + + rabbitmq: + image: rabbitmq:3.11-management-alpine + volumes: + - rabbitmqdata:/var/lib/rabbitmq + env_file: env/rabbitmq.env + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.rabbitmq-ui-vibe.rule=Host(`rabbitmq.vibe.local`)" # UI access + - "traefik.http.services.rabbitmq-ui-vibe.loadbalancer.server.port=15672" + - "traefik.tcp.services.rabbitmq-amqp-vibe.loadbalancer.server.port=5672" + + mailcatcher: + image: sj26/mailcatcher + networks: + - oro + labels: + - "traefik.enable=true" + - "traefik.http.routers.mailcatcher-vibe.rule=Host(`mailcatcher.vibe.local`)" + - "traefik.http.services.mailcatcher-vibe.loadbalancer.server.port=1080" + +networks: + oro: + driver: bridge + +volumes: + appdata: + dbdata: + rabbitmqdata: + pgadmin-data: + sockdata: + ssldata: + postgres-data: diff --git a/test/vibe/env/elasticsearch.env b/test/vibe/env/elasticsearch.env new file mode 100644 index 0000000..5856225 --- /dev/null +++ b/test/vibe/env/elasticsearch.env @@ -0,0 +1,2 @@ +ES_HOST=elasticsearch +ES_PORT=9200 diff --git a/test/vibe/env/mailtrap.env b/test/vibe/env/mailtrap.env new file mode 100644 index 0000000..394b769 --- /dev/null +++ b/test/vibe/env/mailtrap.env @@ -0,0 +1,8 @@ +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=587 +MAIL_USERNAME=60b0889ecafe2b +MAIL_PASSWORD=83c42e3c27db2d +MAIL_ENCRYPTION=tls +MAIL_FROM_ADDRESS=adnnor@gmail.com +MAIL_FROM_NAME="Adnan Shahzad" diff --git a/test/vibe/env/pgadmin.env b/test/vibe/env/pgadmin.env new file mode 100644 index 0000000..4c29e58 --- /dev/null +++ b/test/vibe/env/pgadmin.env @@ -0,0 +1,2 @@ +PGADMIN_DEFAULT_EMAIL=root@adnanshahzad.me +PGADMIN_DEFAULT_PASSWORD=root diff --git a/test/vibe/env/phpfpm.env b/test/vibe/env/phpfpm.env new file mode 100644 index 0000000..20c33e4 --- /dev/null +++ b/test/vibe/env/phpfpm.env @@ -0,0 +1 @@ +COMPOSER_DISABLE_XDEBUG_WARN=1 diff --git a/test/vibe/env/postgres.env b/test/vibe/env/postgres.env new file mode 100644 index 0000000..32a6d67 --- /dev/null +++ b/test/vibe/env/postgres.env @@ -0,0 +1,3 @@ +POSTGRES_USER=root +POSTGRES_PASSWORD=root +POSTGRES_DB=dev diff --git a/test/vibe/env/rabbitmq.env b/test/vibe/env/rabbitmq.env new file mode 100644 index 0000000..c83768a --- /dev/null +++ b/test/vibe/env/rabbitmq.env @@ -0,0 +1,5 @@ +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_DEFAULT_USER=rabbit +RABBITMQ_DEFAULT_PASS=rabbit +RABBITMQ_DEFAULT_VHOST=/ diff --git a/test/vibe/src/.env-app.local b/test/vibe/src/.env-app.local new file mode 100644 index 0000000..e69de29 diff --git a/test/vibe/src/public/index.php b/test/vibe/src/public/index.php new file mode 100644 index 0000000..83f1549 --- /dev/null +++ b/test/vibe/src/public/index.php @@ -0,0 +1,3 @@ + labels` section, set the Traefik dashboard port to `8083` for accessibility: + +```yaml +labels: + - "traefik.http.services.traefik-dashboard-vibe.loadbalancer.server.port=8083" +``` + +If there are any issues accessing the dashboard, you can comment out this line to troubleshoot: + +```yaml + # - "traefik.http.services.traefik-dashboard-vibe.loadbalancer.server.port=8083" +``` + +Note that while `nginx.conf` supports secure URLs, SSL is not yet set up here. You can add an SSL certificate if possible; otherwise, SSL support will be added soon. + +Add the following URLs to your `/etc/hosts` file: + +- 127.0.0.1 vibe.local +- 127.0.0.1 pgadmin.vibe.local +- 127.0.0.1 traefik.vibe.local +- 127.0.0.1 rabbitmq.vibe.local +- 127.0.0.1 mailcatcher.vibe.local +- 127.0.0.1 elasticsearch.vibe.local + +After making these changes, start the project by running: + +```bash +docker-compose up -d +``` + +This will set up `vibe` as a separate project with the following URLs: + +- `vibe.local:8088` +- `pgadmin.vibe.local:8088` +- `traefik.vibe.local:8088` +- `rabbitmq.vibe.local:8088` +- `mailcatcher.vibe.local:8088` +- `elasticsearch.vibe.local:8088` + diff --git a/traefik.yml b/traefik.yml new file mode 100644 index 0000000..b619aae --- /dev/null +++ b/traefik.yml @@ -0,0 +1,15 @@ +entryPoints: + web: + address: ":80" + websecure: + address: ":443" + +providers: + docker: + endpoint: "unix:///var/run/docker.sock" + exposedByDefault: false + +api: + dashboard: true + +accessLog: {}