Skip to content

Commit

Permalink
Merge pull request #298 from jolicode/traefik-ns
Browse files Browse the repository at this point in the history
Use only project container in traefik discovery
  • Loading branch information
pyrech authored Apr 11, 2024
2 parents 5da05c6 + 661f4d9 commit 95a0276
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
8 changes: 3 additions & 5 deletions .castor/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ function build(
$command[] = $profile;
}

$userId = variable('user_id');
$phpVersion = variable('php_version');

$command = [
...$command,
'build',
'--build-arg', "USER_ID={$userId}",
'--build-arg', "PHP_VERSION={$phpVersion}",
'--build-arg', 'USER_ID=' . variable('user_id'),
'--build-arg', 'PHP_VERSION=' . variable('php_version'),
'--build-arg', 'PROJECT_NAME=' . variable('project_name'),
];

if ($service) {
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ If you want to use Webpack Encore in a Symfony project,
command: "yarn run dev-server --hot --host 0.0.0.0 --allowed-hosts encore.${PROJECT_ROOT_DOMAIN} --allowed-hosts ${PROJECT_ROOT_DOMAIN} --client-web-socket-url-hostname encore.${PROJECT_ROOT_DOMAIN} --client-web-socket-url-port 443 --client-web-socket-url-protocol wss"
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-encore.rule=Host(`encore.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-encore.tls=true"
- "traefik.http.services.encore.loadbalancer.server.port=8080"
profiles:
- default
```
3. Update the webpack configuration to specify the asset location in **dev**:
Expand Down Expand Up @@ -296,17 +299,23 @@ services:
- "discovery.type=single-node"
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-elasticsearch.rule=Host(`elasticsearch.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-elasticsearch.tls=true"
profiles:
- default

kibana:
image: kibana:7.8.0
depends_on:
- elasticsearch
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-kibana.rule=Host(`kibana.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-kibana.tls=true"
profiles:
- default
```
Then, you will be able to browse:
Expand Down Expand Up @@ -391,9 +400,12 @@ services:
- rabbitmq-data:/var/lib/rabbitmq
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-rabbitmq.rule=Host(`rabbitmq.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-rabbitmq.tls=true"
- "traefik.http.services.rabbitmq.loadbalancer.server.port=15672"
profiles:
- default
```
In order to publish and consume messages with PHP, you need to install the
Expand Down Expand Up @@ -440,8 +452,11 @@ services:
- "redis-insight-data:/db"
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-redis.rule=Host(`redis.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-redis.tls=true"
profiles:
- default

```

Expand Down Expand Up @@ -477,9 +492,12 @@ services:
- MAILDEV_SMTP_PORT=25
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-maildev.rule=Host(`maildev.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-maildev.tls=true"
- "traefik.http.services.maildev.loadbalancer.server.port=80"
profiles:
- default
```
Then, you will be able to browse:
Expand Down Expand Up @@ -516,8 +534,11 @@ services:
- "CORS_ALLOWED_ORIGINS=*"
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-mercure.rule=Host(`mercure.${PROJECT_ROOT_DOMAIN}`)"
- "traefik.http.routers.${PROJECT_NAME}-mercure.tls=true"
profiles:
- default
```
If you are using Symfony, you must put the following configuration in the `.env` file:
Expand Down Expand Up @@ -631,6 +652,8 @@ services:
BLACKFIRE_SERVER_TOKEN: FIXME
BLACKFIRE_CLIENT_ID: FIXME
BLACKFIRE_CLIENT_TOKEN: FIXME
profiles:
- default
```

Expand Down Expand Up @@ -710,6 +733,8 @@ services:
target: cron
volumes:
- "../..:/var/www:cached"
profiles:
- default
```

</details>
Expand Down
2 changes: 2 additions & 0 deletions infrastructure/docker/docker-compose.builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ services:
- "builder-data:/home/app"
- "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache"
- "../..:/var/www:cached"
profiles:
- default
2 changes: 2 additions & 0 deletions infrastructure/docker/docker-compose.docker-for-x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ services:
- "80:80"
- "443:443"
- "8080:8080"
profiles:
- default
1 change: 1 addition & 0 deletions infrastructure/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
- default
labels:
- "traefik.enable=true"
- "project-name=${PROJECT_NAME}"
- "traefik.http.routers.${PROJECT_NAME}-frontend.rule=Host(${PROJECT_DOMAINS})"
- "traefik.http.routers.${PROJECT_NAME}-frontend.tls=true"
- "traefik.http.routers.${PROJECT_NAME}-frontend-unsecure.rule=Host(${PROJECT_DOMAINS})"
Expand Down
3 changes: 3 additions & 0 deletions infrastructure/docker/services/router/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ FROM traefik:v3.0

COPY traefik /etc/traefik

ARG PROJECT_NAME
RUN sed -i "s/{{ PROJECT_NAME }}/${PROJECT_NAME}/g" /etc/traefik/traefik.yaml

VOLUME [ "/etc/ssl/certs" ]
1 change: 1 addition & 0 deletions infrastructure/docker/services/router/traefik/traefik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ global:
providers:
docker:
exposedByDefault: false
constraints: "Label(`project-name`,`{{ PROJECT_NAME }}`)"
file:
filename: /etc/traefik/dynamic_conf.yaml

Expand Down

0 comments on commit 95a0276

Please sign in to comment.