This repository was archived by the owner on Sep 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathfetcher.go
More file actions
64 lines (53 loc) · 1.4 KB
/
fetcher.go
File metadata and controls
64 lines (53 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package fetcher
import (
"context"
"fmt"
"io"
"io/ioutil"
"github.com/box-builder/box/builder/config"
"github.com/box-builder/box/logger"
"github.com/box-builder/box/pull"
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
)
// Docker does stuff
func Docker(context context.Context, logger *logger.Logger, client *client.Client, tty bool, config *config.Config, name string) (string, []string, error) {
inspect, _, err := client.ImageInspectWithRaw(context, name)
if err != nil {
reader, err := client.ImagePull(context, name, types.ImagePullOptions{})
if err != nil {
return "", nil, err
}
if !tty {
logger.Print(fmt.Sprintf("Pulling %q... ", name))
if _, err := io.Copy(ioutil.Discard, reader); err != io.EOF && err != nil {
return "", nil, err
}
fmt.Fprintln(logger.Output(), "done.")
} else {
pull.NewProgress(tty, reader).Process()
}
select {
case <-context.Done():
if context.Err() != nil {
return "", nil, context.Err()
}
default:
}
// this will fallthrough to the assignment below
inspect, _, err = client.ImageInspectWithRaw(context, name)
if err != nil {
return "", nil, err
}
select {
case <-context.Done():
if context.Err() != nil {
return "", nil, context.Err()
}
default:
}
}
config.FromDocker(inspect.Config)
config.Image = inspect.ID
return inspect.ID, inspect.RootFS.Layers, nil
}