Skip to content

Commit

Permalink
Merge pull request #5 from adnnor/traefik-integration
Browse files Browse the repository at this point in the history
Traefik Integration
  • Loading branch information
adnnor authored Nov 4, 2024
2 parents 18a650f + dc030aa commit b3c171e
Show file tree
Hide file tree
Showing 50 changed files with 1,105 additions and 41 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=mood
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down
Empty file added acme.json
Empty file.
110 changes: 70 additions & 40 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,38 +12,69 @@ 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
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"
- "./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
Expand All @@ -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"
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

phpinfo();
Empty file added standard-setup/backups/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions standard-setup/conf/.env-app.local
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions standard-setup/conf/nginx.default.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}

32 changes: 32 additions & 0 deletions standard-setup/conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit b3c171e

Please sign in to comment.