Skip to content

Commit 7b6fdf6

Browse files
Update browser windows to allow specifying a path
1 parent 841f3b0 commit 7b6fdf6

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

ChangeLog.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
# Change Log
22

3+
## version 0.0.11
4+
5+
### Browser windows
6+
Change `OpenInBrowser` to a string so that the user can specify the path
7+
8+
### Version check
9+
Check the latest verison on startup
10+
11+
```
12+
########################################################
13+
SHIPYARD UPDATE
14+
########################################################
15+
16+
The current version of shipyard is "0.0.10", you have "841f3b0445cc01f44ea2728dd5113f6b0f611e1f".
17+
18+
To upgrade Shipyard please use your package manager or,
19+
see the documentation at:
20+
https://shipyard.run/docs/install for other options.
21+
```
22+
23+
324
## version 0.0.9
425

5-
## Browser windows
26+
### Browser windows
627
Ensure that browser windows are openened correctly on Windows platforms.
728

8-
## Preflight
29+
### Preflight
930
Check that Docker is installed and running
1031

1132

1233
## version 0.0.8
1334

14-
## Bugfixes
35+
### Bugfixes
1536

1637
* Fix problem with home folder resolution on Windows
1738
* Add ipv6 DNS entries for resources
1839

1940
## version 0.0.7
2041

21-
## Ingress
42+
### Ingress
2243
Add three new ingress types `nomad_ingress`, `k8s_ingress`, `container_ingress`, these new type have cluster specific options
2344
rather than trying to shoehorn all into `ingress`. For now `ingress` exists and is backward compatible.
2445

cmd/run.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"strconv"
67
"sync"
78
"time"
89

@@ -119,42 +120,42 @@ func newRunCmdFunc(e shipyard.Engine, bp clients.Blueprints, hc clients.HTTP, bc
119120
case config.TypeContainer:
120121
c := r.(*config.Container)
121122
for _, p := range c.Ports {
122-
if p.Host != "" && p.OpenInBrowser {
123-
browserList = append(browserList, fmt.Sprintf("http://localhost:%s", p.Host))
123+
if p.Host != "" && p.OpenInBrowser != "" {
124+
browserList = append(browserList, buildBrowserPath(r.Info().Name, p.Host, r.Info().Type, p.OpenInBrowser))
124125
}
125126
}
126127
case config.TypeIngress:
127128
c := r.(*config.Ingress)
128129
for _, p := range c.Ports {
129-
if p.Host != "" && p.OpenInBrowser {
130-
browserList = append(browserList, fmt.Sprintf("http://localhost:%s", p.Host))
130+
if p.Host != "" && p.OpenInBrowser != "" {
131+
browserList = append(browserList, buildBrowserPath(r.Info().Name, p.Host, r.Info().Type, p.OpenInBrowser))
131132
}
132133
}
133134
case config.TypeContainerIngress:
134135
c := r.(*config.ContainerIngress)
135136
for _, p := range c.Ports {
136-
if p.Host != "" && p.OpenInBrowser {
137-
browserList = append(browserList, fmt.Sprintf("http://localhost:%s", p.Host))
137+
if p.Host != "" && p.OpenInBrowser != "" {
138+
browserList = append(browserList, buildBrowserPath(r.Info().Name, p.Host, r.Info().Type, p.OpenInBrowser))
138139
}
139140
}
140141
case config.TypeNomadIngress:
141142
c := r.(*config.NomadIngress)
142143
for _, p := range c.Ports {
143-
if p.Host != "" && p.OpenInBrowser {
144-
browserList = append(browserList, fmt.Sprintf("http://localhost:%s", p.Host))
144+
if p.Host != "" && p.OpenInBrowser != "" {
145+
browserList = append(browserList, buildBrowserPath(r.Info().Name, p.Host, r.Info().Type, p.OpenInBrowser))
145146
}
146147
}
147148
case config.TypeK8sIngress:
148149
c := r.(*config.K8sIngress)
149150
for _, p := range c.Ports {
150-
if p.Host != "" && p.OpenInBrowser {
151-
browserList = append(browserList, fmt.Sprintf("http://localhost:%s", p.Host))
151+
if p.Host != "" && p.OpenInBrowser != "" {
152+
browserList = append(browserList, buildBrowserPath(r.Info().Name, p.Host, r.Info().Type, p.OpenInBrowser))
152153
}
153154
}
154155
case config.TypeDocs:
155156
c := r.(*config.Docs)
156157
if c.OpenInBrowser {
157-
browserList = append(browserList, fmt.Sprintf("http://localhost:%d", c.Port))
158+
browserList = append(browserList, buildBrowserPath(r.Info().Name, strconv.Itoa(c.Port), r.Info().Type, ""))
158159
}
159160
}
160161
}
@@ -205,6 +206,15 @@ func newRunCmdFunc(e shipyard.Engine, bp clients.Blueprints, hc clients.HTTP, bc
205206
}
206207
}
207208

209+
func buildBrowserPath(n, p string, t config.ResourceType, path string) string {
210+
ty := t
211+
if t == config.TypeNomadIngress || t == config.TypeContainerIngress || t == config.TypeK8sIngress {
212+
ty = config.TypeIngress
213+
}
214+
215+
return fmt.Sprintf("http://%s.%s.shipyard.run:%s%s", n, ty, p, path)
216+
}
217+
208218
func bluePrintInState() bool {
209219
//load the state
210220
sc := config.New()

cmd/run_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,19 @@ func TestRunOpensBrowserWindowForResources(t *testing.T) {
107107
d.OpenInBrowser = true
108108

109109
i := config.NewIngress("test")
110-
i.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: true}}
110+
i.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: "/"}}
111111

112112
c := config.NewContainer("test")
113-
c.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: true}}
113+
c.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: "/"}}
114114

115+
// should not be opened
115116
d2 := config.NewDocs("test")
116117

117118
i2 := config.NewIngress("test")
118-
i2.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: false}}
119+
i2.Ports = []config.Port{config.Port{Host: "8080", OpenInBrowser: ""}}
119120

120-
c2 := config.NewContainer("test")
121-
c2.Ports = []config.Port{config.Port{OpenInBrowser: true}}
121+
c2 := config.NewContainer("test2")
122+
c2.Ports = []config.Port{config.Port{OpenInBrowser: ""}}
122123

123124
me.On("Apply", mock.Anything).Return(
124125
[]config.Resource{d, i, c, d2, i2, c2},

functional_tests/test_fixtures/nomad/ingress.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ nomad_ingress "nomad-http" {
2222
local = 4646
2323
remote = 4646
2424
host = 14646
25-
open_in_browser = true
25+
open_in_browser = "/"
2626
}
2727

2828
network {

pkg/config/port.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ type Port struct {
66
Remote string `hcl:"remote" json:"remote"` // Remote port of the service
77
Host string `hcl:"host,optional" json:"host,omitempty"` // Host port
88
Protocol string `hcl:"protocol,optional" json:"protocol,omitempty"` // Protocol tcp, udp
9-
OpenInBrowser bool `hcl:"open_in_browser,optional" json:"open_in_browser" mapstructure:"open_in_browser"` // When a host port is defined open the location in a browser
9+
OpenInBrowser string `hcl:"open_in_browser,optional" json:"open_in_browser" mapstructure:"open_in_browser"` // When a host port is defined open this port with the given path in a browser
1010
}

0 commit comments

Comments
 (0)