Skip to content

Commit aee3b9f

Browse files
committed
allow default grpc and http port to be overridden by envvars
1 parent c233a28 commit aee3b9f

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

deploy/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
PGPORT: 5432
1616
PGSSLMODE: disable
1717
PGUSER: tinkerbell
18+
TINKERBELL_GRPC_AUTHORITY: 127.0.0.1:42113
19+
TINKERBELL_HTTP_AUTHORITY: :42114
1820
TINK_AUTH_USERNAME: ${TINKERBELL_TINK_USERNAME:-admin}
1921
TINK_AUTH_PASSWORD: ${TINKERBELL_TINK_PASSWORD:-admin}
2022
depends_on:
@@ -23,7 +25,7 @@ services:
2325
db:
2426
condition: service_healthy
2527
healthcheck:
26-
test: ["CMD-SHELL", "wget -qO- 127.0.0.1:42114/cert"]
28+
test: ["CMD-SHELL", "wget -qO- 127.0.0.1:42114/cert"] # port needs to match TINKERBELL_HTTP_AUTHORITY
2729
interval: 5s
2830
timeout: 2s
2931
retries: 30

grpc-server/grpc-server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
var (
2727
logger log.Logger
28-
grpcListenAddr = ":42113"
28+
grpcListenAddr = os.Getenv("TINKERBELL_GRPC_AUTHORITY")
2929
)
3030

3131
// Server is the gRPC server for tinkerbell
@@ -76,6 +76,9 @@ func SetupGRPC(ctx context.Context, log log.Logger, facility string, errCh chan<
7676

7777
go func() {
7878
logger.Info("serving grpc")
79+
if grpcListenAddr == "" {
80+
grpcListenAddr = ":42113"
81+
}
7982
lis, err := net.Listen("tcp", grpcListenAddr)
8083
if err != nil {
8184
err = errors.Wrap(err, "failed to listen")

http-server/http-server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
var (
2626
gitRev = "unknown"
2727
gitRevJSON []byte
28-
grpcListenAddr = "localhost:42113"
29-
httpListenAddr = ":42114"
28+
grpcListenAddr = os.Getenv("TINKERBELL_GRPC_AUTHORITY")
29+
httpListenAddr = os.Getenv("TINKERBELL_HTTP_AUTHORITY")
3030
authUsername = os.Getenv("TINK_AUTH_USERNAME")
3131
authPassword = os.Getenv("TINK_AUTH_PASSWORD")
3232
startTime = time.Now()
@@ -48,6 +48,10 @@ func SetupHTTP(ctx context.Context, lg log.Logger, certPEM []byte, modTime time.
4848
mux := grpcRuntime.NewServeMux()
4949

5050
dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(creds)}
51+
52+
if grpcListenAddr == "" {
53+
grpcListenAddr = "localhost:42113"
54+
}
5155
err := hardware.RegisterHardwareServiceHandlerFromEndpoint(ctx, mux, grpcListenAddr, dialOpts)
5256
if err != nil {
5357
logger.Error(err)
@@ -70,6 +74,9 @@ func SetupHTTP(ctx context.Context, lg log.Logger, certPEM []byte, modTime time.
7074
http.HandleFunc("/_packet/healthcheck", healthCheckHandler)
7175
http.Handle("/", BasicAuth(mux))
7276

77+
if httpListenAddr == "" {
78+
httpListenAddr = ":42114"
79+
}
7380
srv := &http.Server{
7481
Addr: httpListenAddr,
7582
}

0 commit comments

Comments
 (0)