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

Commit 1dae8e1

Browse files
author
Matthieu Nottale
committed
Add support for loading URLs.
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
1 parent 32f58af commit 1dae8e1

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

e2e/commands_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ func TestSplitMergeBinary(t *testing.T) {
285285
assertCommand(t, dockerApp, "split", "split")
286286
}
287287

288+
func TestURLBinary(t *testing.T) {
289+
url := "https://raw.githubusercontent.com/docker/app/v0.4.1/examples/hello-world/hello-world.dockerapp"
290+
dockerApp, _ := getDockerAppBinary(t)
291+
assertCommandOutput(t, "helloworld-inspect.golden", dockerApp, "inspect", url)
292+
}
293+
288294
func TestImageBinary(t *testing.T) {
289295
dockerApp, _ := getDockerAppBinary(t)
290296
r := startRegistry(t)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
hello-world 0.1.0
2+
Maintained by: user <user@email.com>
3+
4+
Hello, World!
5+
6+
Setting Default
7+
------- -------
8+
port 8080
9+
text Hello, World!

internal/packager/extract.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package packager
33
import (
44
"fmt"
55
"io/ioutil"
6+
"net/url"
67
"os"
78
"os/exec"
89
"path/filepath"
@@ -104,6 +105,11 @@ func Extract(name string, ops ...func(*types.App) error) (*types.App, error) {
104105
appname := internal.DirNameFromAppName(name)
105106
s, err := os.Stat(appname)
106107
if err != nil {
108+
// URL or docker image
109+
u, err := url.Parse(name)
110+
if err == nil && (u.Scheme == "http" || u.Scheme == "https") {
111+
return loader.LoadFromURL(name, ops...)
112+
}
107113
// look for a docker image
108114
return extractImage(name, ops...)
109115
}

loader/loader.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package loader
33
import (
44
"io"
55
"io/ioutil"
6+
"net/http"
67
"os"
78
"path/filepath"
89
"strings"
@@ -13,6 +14,21 @@ import (
1314
"github.com/pkg/errors"
1415
)
1516

17+
// LoadFromURL loads a docker app from an URL that should return a single-file app.
18+
func LoadFromURL(url string, ops ...func(*types.App) error) (*types.App, error) {
19+
resp, err := http.Get(url)
20+
if err != nil {
21+
return nil, errors.Wrap(err, "failed to download "+url)
22+
}
23+
if resp.Body != nil {
24+
defer resp.Body.Close()
25+
}
26+
if resp.StatusCode != 200 {
27+
return nil, errors.Errorf("failed to download %s: %s", url, resp.Status)
28+
}
29+
return LoadFromSingleFile(url, resp.Body, ops...)
30+
}
31+
1632
// LoadFromSingleFile loads a docker app from a single-file format (as a reader)
1733
func LoadFromSingleFile(path string, r io.Reader, ops ...func(*types.App) error) (*types.App, error) {
1834
data, err := ioutil.ReadAll(r)

0 commit comments

Comments
 (0)