Skip to content

Commit 9f42269

Browse files
committed
initial port
1 parent 21ac2bf commit 9f42269

15 files changed

Lines changed: 915 additions & 44 deletions

File tree

.dockerignore

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
!app.py
1+
# env file
2+
*.env
3+
4+
# Exclude git folders
5+
.git*
6+
!.github
7+
8+
# Ignore yml files
9+
*.yaml
10+
*.yml
11+
12+
# Markdown files
13+
*.md
14+
15+
# Include data/
16+
!data/*
Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,113 @@
1+
<div align="center">
2+
<a href="https://github.com/codeshelldev/servdiscovery/releases">
3+
<img
4+
src="https://img.shields.io/github/v/release/codeshelldev/servdiscovery?sort=semver&logo=github&label=Release"
5+
alt="GitHub release"
6+
>
7+
</a>
8+
<a href="https://github.com/codeshelldev/servdiscovery/stargazers">
9+
<img
10+
src="https://img.shields.io/github/stars/codeshelldev/servdiscovery?style=flat&logo=github&label=Stars"
11+
alt="GitHub stars"
12+
>
13+
</a>
14+
<a href="https://github.com/codeshelldev/servdiscovery/pkgs/container/servdiscovery">
15+
<img
16+
src="https://ghcr-badge.egpl.dev/codeshelldev/servdiscovery/size?color=%2344cc11&tag=latest&label=Image+Size&trim="
17+
alt="Docker image size"
18+
>
19+
</a>
20+
<a href="https://github.com/codeshelldev/servdiscovery/pkgs/container/servdiscovery">
21+
<img
22+
src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fghcr-badge.elias.eu.org%2Fapi%2Fcodeshelldev%2Fservdiscovery%2Fservdiscovery&query=downloadCount&label=Downloads&color=2344cc11"
23+
alt="Docker image Pulls"
24+
>
25+
</a>
26+
<a href="./LICENSE">
27+
<img
28+
src="https://img.shields.io/badge/License-MIT-green.svg"
29+
alt="License: MIT"
30+
>
31+
</a>
32+
</div>
33+
134
# ServDiscovery
235

3-
ServDiscovery is a Discovery Service that keeps an Endpoint updated with active Hosts (of Services).
36+
**ServDiscovery** is a dynamic **Discovery Service** that keeps your endpoints in sync with active hosts of your services—perfect for modern, containerized environments. Think of it as the bridge between your services and your reverse proxy, ensuring traffic always finds the right destination.
437

538
## Installation
639

7-
> [!NOTE]
8-
> ServDiscovery only works with Traefik and not with **any** other Reverse Proxy due to `discover.enable` lable
40+
> [!IMPORTANT]
41+
> ServDiscovery works **only with Traefik**. It will **not** work with other reverse proxies due to the `discover.enable` label requirement.
942
10-
Get the latest `docker-compose.yaml` file:
43+
Get the latest `docker-compose.yaml`:
1144

1245
```yaml
13-
{ { file.docker-compose.yaml } }
46+
{{{ #://docker-compose.yaml }}}
1447
```
1548

49+
Then spin it up:
50+
1651
```bash
1752
docker compose up -d
1853
```
1954

55+
Your discovery service is now live! 🎉
56+
2057
## Usage
2158

22-
Take this little `whoami` Container as an Example:
59+
Let`s take a simple `whoami` container as an example:
2360

2461
```yaml
25-
{ { file.examples/whoami.docker-compose.yaml } }
62+
{{{ #://examples/whoami.docker-compose.yaml } }
2663
```
2764

28-
Whenever a new **Host-Rule** gets added / modified ServDiscovery will update the set Endpoint to notify of any new changes.
29-
This way the Endpoint can correctly route to different Hosts based on **SNI / Hostnames**.
65+
Whenever a new **Host-Rule** is added or updated, ServDiscovery will **automatically notify the configured endpoint**.
66+
This ensures the endpoint can correctly route traffic based on **SNI / Hostnames**.
3067

31-
## Endpoint
68+
## Endpoint Integration
3269

33-
ServDiscovery sends requests to the Endpoint as a **JSON HTTP Request**:
70+
ServDiscovery communicates with your endpoint via **JSON HTTP Requests**:
3471

3572
```json
36-
{ { file.examples/payload.json } }
73+
{{{ #://examples/payload.json }}}
3774
```
3875

39-
This example tells the Endpoint that...
76+
Example explanation:
4077

41-
| Available | Unavailable |
78+
| Available | ❌ Unavailable |
4279
| -------------------- | --------------------------- |
4380
| whoami.mydomain.com | whoami-backup.mydomain.com |
4481
| website.mydomain.com | website-backup.mydomain.com |
4582
| auth.mydomain.com | auth-backup.mydomain.com |
4683

47-
... is (un)available
84+
This allows the endpoint (e.g., a load balancer) to remove `\*-backup` records from your registry and **update routable containers/services automatically**.
4885

49-
This way (if the Endpoint is used by a LoadBalancer) the Owner of the Endpoint can now delete the `*-backup.mydomain.com` records from a Registry,
50-
thus updating the list of routable Containers / Services.
86+
### Integrations
5187

52-
## Configuration
88+
You can find example integrations inside of [examples/](./examples).
5389

54-
### ENDPOINT_KEY
55-
56-
The Endpoint Key is provided in the Authorization Header (via Bearer) during the POST request between the Endpoint and ServDiscovery.
57-
If no Key is provided ServDiscovery will leave out the Authorization Header.
58-
59-
### DISCOVERY_INTERVAL
90+
## Configuration
6091

61-
The Discovery Interval sets the Interval (in seconds) of which ServDiscovery will update the provided Endpoint.
92+
### `ENDPOINT_KEY`
6293

63-
Default: `60`
94+
The endpoint key is used in the `Authorization` header (Bearer token) when ServDiscovery sends POST requests.
95+
If no key is provided, the header is omitted.
6496

65-
### FULL_DISCOVERY_INTERVAL
97+
### `DISCOVERY_INTERVAL`
6698

67-
Sets the Interval for Full Disoveries.
68-
This tells ServDiscovery to send a Full Update of all the activate Containers in the `added` JSON Key.
99+
Time (in seconds) between updates to your endpoint.
100+
**Default:** `60` seconds
69101

70-
> [!IMPORTANT]
71-
> Must be set to a **fraction of** DISCOVERY_INTERVAL.
72-
> (example: `DISCOVERY_INTERVAL * 2`)
73-
> `FULL_DISCOVERY_INTERVAL / DISCOVERY_INTERVAL` must result in an int.
74-
> `FULL_DISCOVERY_INTERVAL` must be bigger than `DISCOVERY_INTERVAL`.
102+
### `ALIVE_INTERVAL`
75103

76-
Default: **Disabled**
104+
Time (in seconds) between full alive discoveries. ServDiscovery sends a **complete update** of all active containers in the `added` JSON key.
105+
**Default:** `120` seconds
77106

78107
## Contributing
79108

80-
Found a bug or have new ideas or enhancements for this Project?
81-
Feel free to open up an issue or create a Pull Request!
109+
Found a bug or have a brilliant idea? Contributions are welcome! Open an **issue** or create a **pull request** — your help makes this project better.
82110

83111
## License
84112

85-
[MIT](https://choosealicense.com/licenses/mit/)
113+
This project is licensed under the [MIT License](./LICENSE).

.gitignore

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1-
.env
2-
.venv
3-
*.lua
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Code coverage profiles and other test artifacts
12+
*.out
13+
coverage.*
14+
*.coverprofile
15+
profile.cov
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
*.env
26+
27+
# Editor/IDE
28+
# .idea/
29+
.vscode/
30+
31+
# Exclude git folders
32+
.git*
33+
!.github

examples/haproxy/haproxy.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
global
2+
lua-prepend-path /tmp/haproxy/lua/?.lua
3+
# Load discovery script
4+
lua-load /tmp/haproxy/lua/snidiscovery.lua
5+
# Load json helper script
6+
# Download here: https://github.com/rxi/json.lua/blob/master/json.lua
7+
lua-load /tmp/haproxy/lua/json.lua
8+
9+
frontend sni-discovery_frontend
10+
bind *:4676
11+
mode http
12+
option http-keep-alive
13+
14+
acl is_private_range src 192.168.0.0/16 172.16.0.0/12
15+
acl is_authenticated hdr(Authorization) -i "Bearer ENDPOINT_KEY"
16+
17+
http-request deny if !is_private_range || !is_authenticated
18+
19+
# Apply discovery routing
20+
http-request use-service lua.update_mapping

0 commit comments

Comments
 (0)