Skip to content

Commit

Permalink
identifiable replicas in docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Jun 16, 2024
1 parent fbf9bef commit 42fe294
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
context: .
environment:
- COUNTER_FILENAME=/appdata/my.gcounter
deploy:
replicas: 3
labels:
- "traefik.http.routers.inventory-api-service.rule=PathPrefix(`/`)"
- "traefik.http.services.mermaidlive.loadbalancer.server.port=8080"
8 changes: 6 additions & 2 deletions fly_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ func getCounterFilename() string {

func GetReplicasEvent(count int) Event {
return NewEventWithParam("ReplicasActive",
fmt.Sprintf("%d (you are on '%s')", count, getFlyPublicReplicaId()))
fmt.Sprintf("%d (you are on '%s')", count, getPublicReplicaId()))
}

func getFlyPublicReplicaId() string {
func getPublicReplicaId() string {
if id, ok := os.LookupEnv("FLY_MACHINE_ID"); ok && len(id) > 5 {
// do not show the full machine ID
return id[len(id)-5:]
}
hostname, err := os.Hostname()
if err == nil {
return hostname
}
return "local"
}

0 comments on commit 42fe294

Please sign in to comment.