Skip to content

Commit 55a4fbf

Browse files
authored
Merge pull request #5785 from dtrudg/issue5782
Show correct web URL for detached builds
2 parents 5071b24 + 03dbee2 commit 55a4fbf

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ _The old changelog can be found in the `release-2.6` branch_
2222
when using plugins.
2323
- Remove spurious warning in parseTokenSection()
2424
- e2e test fixes for new kernels, new unsquashfs version.
25+
- Show correct web URI for detached builds against alternate remotes.
2526

2627

2728
# v3.7.0 - [2020-11-24]

cmd/internal/cli/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var buildArgs struct {
3333
builderURL string
3434
libraryURL string
3535
keyServerURL string
36+
webURL string
3637
detached bool
3738
encrypt bool
3839
fakeroot bool

cmd/internal/cli/build_darwin.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func runBuild(cmd *cobra.Command, args []string) {
4040
buildArgs.libraryURL = lc.BaseURL
4141
buildArgs.builderURL = bc.BaseURL
4242

43+
// To provide a web link to detached remote builds we need to know the web frontend URI.
44+
// We only know this working forward from a remote config, and not if the user has set custom
45+
// service URLs, since there is no straightforward foolproof way to work back from them to a
46+
// matching frontend URL.
47+
if !cmd.Flag("builder").Changed && !cmd.Flag("library").Changed {
48+
buildArgs.webURL = URI()
49+
}
50+
4351
// Submiting a remote build requires a valid authToken
4452
if bc.AuthToken == "" {
4553
sylog.Fatalf("Unable to submit build job: %v", remoteWarning)
@@ -50,7 +58,7 @@ func runBuild(cmd *cobra.Command, args []string) {
5058
sylog.Fatalf("Unable to build from %s: %v", spec, err)
5159
}
5260

53-
b, err := remotebuilder.New(dest, buildArgs.libraryURL, def, buildArgs.detached, forceOverwrite, buildArgs.builderURL, bc.AuthToken, buildArgs.arch)
61+
b, err := remotebuilder.New(dest, buildArgs.libraryURL, def, buildArgs.detached, forceOverwrite, buildArgs.builderURL, bc.AuthToken, buildArgs.arch, buildArgs.webURL)
5462
if err != nil {
5563
sylog.Fatalf("Failed to create builder: %v", err)
5664
}

cmd/internal/cli/build_linux.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ func runBuildRemote(ctx context.Context, cmd *cobra.Command, dst, spec string) {
133133
buildArgs.libraryURL = lc.BaseURL
134134
buildArgs.builderURL = bc.BaseURL
135135

136+
// To provide a web link to detached remote builds we need to know the web frontend URI.
137+
// We only know this working forward from a remote config, and not if the user has set custom
138+
// service URLs, since there is no straightforward foolproof way to work back from them to a
139+
// matching frontend URL.
140+
if !cmd.Flag("builder").Changed && !cmd.Flag("library").Changed {
141+
buildArgs.webURL = URI()
142+
}
143+
136144
// submitting a remote build requires a valid authToken
137145
if bc.AuthToken == "" {
138146
sylog.Fatalf("Unable to submit build job: %v", remoteWarning)
@@ -202,7 +210,7 @@ func runBuildRemote(ctx context.Context, cmd *cobra.Command, dst, spec string) {
202210
}()
203211
}
204212

205-
b, err := remotebuilder.New(rbDst, buildArgs.libraryURL, def, buildArgs.detached, forceOverwrite, buildArgs.builderURL, bc.AuthToken, buildArgs.arch)
213+
b, err := remotebuilder.New(rbDst, buildArgs.libraryURL, def, buildArgs.detached, forceOverwrite, buildArgs.builderURL, bc.AuthToken, buildArgs.arch, buildArgs.webURL)
206214
if err != nil {
207215
sylog.Fatalf("Failed to create builder: %v", err)
208216
}

internal/pkg/build/remotebuilder/remotebuilder.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import (
3131
useragent "github.com/sylabs/singularity/pkg/util/user-agent"
3232
)
3333

34-
// CloudURI holds the URI of the Library web front-end.
35-
const CloudURI = "https://cloud.sylabs.io"
36-
3734
// RemoteBuilder contains the build request and response
3835
type RemoteBuilder struct {
3936
BuildClient *buildclient.Client
@@ -45,10 +42,11 @@ type RemoteBuilder struct {
4542
Force bool
4643
IsDetached bool
4744
BuilderRequirements map[string]string
45+
WebURL string
4846
}
4947

5048
// New creates a RemoteBuilder with the specified details.
51-
func New(imagePath, libraryURL string, d types.Definition, isDetached, force bool, builderAddr, authToken, buildArch string) (rb *RemoteBuilder, err error) {
49+
func New(imagePath, libraryURL string, d types.Definition, isDetached, force bool, builderAddr, authToken, buildArch, webURL string) (rb *RemoteBuilder, err error) {
5250
bc, err := buildclient.New(&buildclient.Config{
5351
BaseURL: builderAddr,
5452
AuthToken: authToken,
@@ -73,6 +71,7 @@ func New(imagePath, libraryURL string, d types.Definition, isDetached, force boo
7371
BuilderRequirements: map[string]string{
7472
"arch": buildArch,
7573
},
74+
WebURL: webURL,
7675
}, nil
7776
}
7877

@@ -107,7 +106,9 @@ func (rb *RemoteBuilder) Build(ctx context.Context) (err error) {
107106
if rb.IsDetached {
108107
fmt.Printf("Build submitted! Once it is complete, the image can be retrieved by running:\n")
109108
fmt.Printf("\tsingularity pull --library %s library://%s\n\n", bi.LibraryURL, libraryRefRaw)
110-
fmt.Printf("Alternatively, you can access it from a browser at:\n\t%s/library/%s\n", CloudURI, libraryRefRaw)
109+
if rb.WebURL != "" {
110+
fmt.Printf("Alternatively, you can access it from a browser at:\n\t%s/library/%s\n", rb.WebURL, libraryRefRaw)
111+
}
111112
return nil
112113
}
113114

internal/pkg/build/remotebuilder/remotebuilder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestBuild(t *testing.T) {
3939
// Loop over test cases
4040
for _, tt := range tests {
4141
t.Run(tt.description, test.WithoutPrivilege(func(t *testing.T) {
42-
_, err := New("", "", types.Definition{}, false, false, tt.builderAddr, "", runtime.GOARCH)
42+
_, err := New("", "", types.Definition{}, false, false, tt.builderAddr, "", runtime.GOARCH, "")
4343
if tt.expectSuccess {
4444
// Ensure the handler returned no error, and the response is as expected
4545
if err != nil {

0 commit comments

Comments
 (0)