Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify router configuration #313

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .castor/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,7 @@ function create_default_context(): Context
$platform = strtolower(php_uname('s'));
if (str_contains($platform, 'darwin')) {
$data['macos'] = true;
$data['docker_compose_files'][] = 'docker-compose.docker-for-x.yml';
} elseif (\in_array($platform, ['win32', 'win64', 'windows nt'])) {
$data['docker_compose_files'][] = 'docker-compose.docker-for-x.yml';
$data['power_shell'] = true;
}

Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,55 @@ services:

</details>

### How to connect networks of two projects

Let's say you have two projects `foo` and `bar`. You want to run both projects a
the same time. And containers from `foo` project should be able to dialog with
`bar` project via public network (host network).

In the `foo` project, you'll need to declare the `bar_default` network in
`docker-compose.yml`:

```yaml
networks:
bar_default:
external: true
```

Then, attach it to the the `foo` router:

```yaml
services:
router:
networks:
- default
- bar_default
```

Finally, you must remove the constraints on the router so it'll be able to
discover containers from another docker compose project:

```diff
--- a/infrastructure/docker/services/router/traefik/traefik.yaml
+++ b/infrastructure/docker/services/router/traefik/traefik.yaml
providers:
docker:
exposedByDefault: false
- constraints: "Label(`project-name`,`{{ PROJECT_NAME }}`)"
file:
```

Finally, you must :

1. build the project `foo`
1. build the project `bar`
1. Create the network `bar_default` (first time only)
```
docker network create bar_default
```
1. start the project `foo`
1. start the project `bar`

## Credits

- Created at [JoliCode](https://jolicode.com/)
Expand Down
13 changes: 0 additions & 13 deletions infrastructure/docker/docker-compose.docker-for-x.yml

This file was deleted.

7 changes: 6 additions & 1 deletion infrastructure/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ services:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./services/router/certs:/etc/ssl/certs"
network_mode: host
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- default
profiles:
- default

Expand Down