@@ -46,9 +46,35 @@ func findApp() (string, error) {
46
46
return filepath .Join (cwd , hit ), nil
47
47
}
48
48
49
+ // extractImage extracts a docker application in a docker image to a temporary directory
50
+ func extractImage (appname string ) (string , func (), error ) {
51
+ var imagename string
52
+ if strings .Contains (appname , ":" ) {
53
+ nametag := strings .SplitN (appname , ":" , 2 )
54
+ nametag [0 ] = utils .DirNameFromAppName (nametag [0 ])
55
+ appname = filepath .Base (nametag [0 ])
56
+ imagename = strings .Join (nametag , ":" )
57
+ } else {
58
+ imagename = utils .DirNameFromAppName (appname )
59
+ appname = filepath .Base (imagename )
60
+ }
61
+ tempDir , err := ioutil .TempDir ("" , "dockerapp" )
62
+ if err != nil {
63
+ return "" , noop , err
64
+ }
65
+ defer os .RemoveAll (tempDir )
66
+ err = Load (imagename , tempDir )
67
+ if err != nil {
68
+ return "" , noop , fmt .Errorf ("could not locate application in either filesystem or docker image" )
69
+ }
70
+ // this gave us a compressed app, run through extract again
71
+ return Extract (filepath .Join (tempDir , appname ))
72
+ }
73
+
49
74
// Extract extracts the app content if argument is an archive, or does nothing if a dir.
50
75
// It returns effective app name, and cleanup function
51
76
// If appname is empty, it looks into cwd, and all subdirs for a single matching .dockerapp
77
+ // If nothing is found, it looks for an image and loads it
52
78
func Extract (appname string ) (string , func (), error ) {
53
79
if appname == "" {
54
80
var err error
@@ -62,6 +88,7 @@ func Extract(appname string) (string, func(), error) {
62
88
return "" , nil , errors .Wrap (err , "cannot resolve current working directory" )
63
89
}
64
90
}
91
+ originalAppname := appname
65
92
// try verbatim first
66
93
s , err := os .Stat (appname )
67
94
if err != nil {
@@ -70,7 +97,8 @@ func Extract(appname string) (string, func(), error) {
70
97
s , err = os .Stat (appname )
71
98
}
72
99
if err != nil {
73
- return "" , noop , err
100
+ // look for a docker image
101
+ return extractImage (originalAppname )
74
102
}
75
103
if s .IsDir () {
76
104
// directory: already decompressed
0 commit comments