Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit 861c373

Browse files
committed
fix: set URLs correctly when customizing the port
1 parent 3467797 commit 861c373

4 files changed

Lines changed: 76 additions & 21 deletions

File tree

dockercompose/auth.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ func auth( //nolint:funlen
3232
httpPort uint,
3333
useTLS bool,
3434
nhostFolder string,
35-
port uint,
35+
exposePort uint,
3636
) (*Service, error) {
37+
if exposePort != 0 {
38+
httpPort = exposePort
39+
}
40+
3741
envars, err := appconfig.HasuraAuthEnv(
3842
cfg,
3943
"http://graphql:8080/v1/graphql",
@@ -94,7 +98,7 @@ func auth( //nolint:funlen
9498
},
9599
},
96100
}.Labels(),
97-
Ports: ports(port, authPort),
101+
Ports: ports(exposePort, authPort),
98102
Restart: "always",
99103
Volumes: []Volume{
100104
{

dockercompose/auth_test.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,18 @@ func TestAuth(t *testing.T) {
207207
t.Parallel()
208208

209209
cases := []struct {
210-
name string
211-
cfg func() *model.ConfigConfig
212-
useTlS bool
213-
expected func() *Service
210+
name string
211+
cfg func() *model.ConfigConfig
212+
useTlS bool
213+
exposePort uint
214+
expected func() *Service
214215
}{
215216
{
216-
name: "default",
217-
cfg: getConfig,
218-
useTlS: false,
219-
expected: expectedAuth,
217+
name: "default",
218+
cfg: getConfig,
219+
useTlS: false,
220+
exposePort: 0,
221+
expected: expectedAuth,
220222
},
221223
{
222224
name: "pre-0.22.0",
@@ -225,7 +227,8 @@ func TestAuth(t *testing.T) {
225227
cfg.Auth.Version = ptr("0.21.3")
226228
return cfg
227229
},
228-
useTlS: false,
230+
useTlS: false,
231+
exposePort: 0,
229232
expected: func() *Service {
230233
svc := expectedAuth()
231234
svc.Image = "nhost/hasura-auth:0.21.3"
@@ -237,13 +240,34 @@ func TestAuth(t *testing.T) {
237240
return svc
238241
},
239242
},
243+
{
244+
name: "custom port",
245+
cfg: getConfig,
246+
useTlS: false,
247+
exposePort: 8080,
248+
expected: func() *Service {
249+
svc := expectedAuth()
250+
251+
svc.Environment["AUTH_SERVER_URL"] = "http://dev.auth.local.nhost.run:8080/v1"
252+
svc.Ports = []Port{
253+
{
254+
Mode: "ingress",
255+
Target: 4000,
256+
Published: "8080",
257+
Protocol: "tcp",
258+
},
259+
}
260+
261+
return svc
262+
},
263+
},
240264
}
241265

242266
for _, tc := range cases {
243267
t.Run(tc.name, func(t *testing.T) {
244268
t.Parallel()
245269

246-
got, err := auth(tc.cfg(), "dev", 1336, tc.useTlS, "/tmp/nhost", 0)
270+
got, err := auth(tc.cfg(), "dev", 1336, tc.useTlS, "/tmp/nhost", tc.exposePort)
247271
if err != nil {
248272
t.Errorf("got error: %v", err)
249273
}

dockercompose/storage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func storage( //nolint:funlen
2222
httpPort uint,
2323
exposePort uint,
2424
) (*Service, error) {
25+
if exposePort != 0 {
26+
httpPort = exposePort
27+
}
28+
2529
envars, err := appconfig.HasuraStorageEnv(
2630
cfg,
2731
"http://graphql:8080/v1",

dockercompose/storage_test.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,47 @@ func TestStorage(t *testing.T) {
6868
t.Parallel()
6969

7070
cases := []struct {
71-
name string
72-
cfg func() *model.ConfigConfig
73-
useTlS bool
74-
expected func() *Service
71+
name string
72+
cfg func() *model.ConfigConfig
73+
useTlS bool
74+
exposePort uint
75+
expected func() *Service
7576
}{
7677
{
77-
name: "success",
78-
cfg: getConfig,
79-
useTlS: false,
80-
expected: expectedStorage,
78+
name: "success",
79+
cfg: getConfig,
80+
useTlS: false,
81+
exposePort: 0,
82+
expected: expectedStorage,
83+
},
84+
{
85+
name: "custom port",
86+
cfg: getConfig,
87+
useTlS: false,
88+
exposePort: 8080,
89+
expected: func() *Service {
90+
svc := expectedStorage()
91+
svc.Environment["PUBLIC_URL"] = "http://dev.storage.local.nhost.run:8080"
92+
93+
svc.Ports = []Port{
94+
{
95+
Mode: "ingress",
96+
Target: 5000,
97+
Published: "8080",
98+
Protocol: "tcp",
99+
},
100+
}
101+
102+
return svc
103+
},
81104
},
82105
}
83106

84107
for _, tc := range cases {
85108
t.Run(tc.name, func(t *testing.T) {
86109
t.Parallel()
87110

88-
got, err := storage(tc.cfg(), "dev", tc.useTlS, 444, 0)
111+
got, err := storage(tc.cfg(), "dev", tc.useTlS, 444, tc.exposePort)
89112
if err != nil {
90113
t.Errorf("got error: %v", err)
91114
}

0 commit comments

Comments
 (0)