Skip to content

Commit c48c568

Browse files
committed
Merge pull request #48 from krancour/change-builder-url
chore(git): Make builder git remote use different hostname
2 parents 203fd0d + 67ae484 commit c48c568

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

pkg/git/git.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ func findRemote(host string) (string, error) {
9595

9696
// Strip off any trailing :port number after the host name.
9797
host = strings.Split(host, ":")[0]
98+
builderHost := getBuilderHostname(host)
9899

99100
for _, line := range strings.Split(cmd, "\n") {
100101
for _, remote := range strings.Split(line, " ") {
101-
if strings.Contains(remote, host) {
102+
if strings.Contains(remote, host) || strings.Contains(remote, builderHost) {
102103
return strings.Split(remote, "\t")[1], nil
103104
}
104105
}
@@ -111,5 +112,12 @@ func findRemote(host string) (string, error) {
111112
func RemoteURL(host, appID string) string {
112113
// Strip off any trailing :port number after the host name.
113114
host = strings.Split(host, ":")[0]
114-
return fmt.Sprintf("ssh://git@%s:2222/%s.git", host, appID)
115+
return fmt.Sprintf("ssh://git@%s:2222/%s.git", getBuilderHostname(host), appID)
116+
}
117+
118+
// getBuilderHostname derives the builder host name from the controller host name.
119+
func getBuilderHostname(host string) string {
120+
hostTokens := strings.Split(host, ".")
121+
hostTokens[0] = fmt.Sprintf("%s-builder", hostTokens[0])
122+
return strings.Join(hostTokens, ".")
115123
}

pkg/git/git_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
func TestRemoteURL(t *testing.T) {
88
t.Parallel()
99

10-
actual := RemoteURL("example.com", "app")
11-
expected := "ssh://git@example.com:2222/app.git"
10+
actual := RemoteURL("deis.example.com", "app")
11+
expected := "ssh://git@deis-builder.example.com:2222/app.git"
1212

1313
if actual != expected {
1414
t.Errorf("Expected %s, Got %s", expected, actual)
1515
}
1616

1717
actual = RemoteURL("deis.10.245.1.3.xip.io:31350", "velcro-underdog")
18-
expected = "ssh://git@deis.10.245.1.3.xip.io:2222/velcro-underdog.git"
18+
expected = "ssh://git@deis-builder.10.245.1.3.xip.io:2222/velcro-underdog.git"
1919

2020
if actual != expected {
2121
t.Errorf("Expected %s, Got %s", expected, actual)

0 commit comments

Comments
 (0)