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 pathconfig.go
More file actions
73 lines (65 loc) · 2.14 KB
/
config.go
File metadata and controls
73 lines (65 loc) · 2.14 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
65
66
67
68
69
70
71
72
73
package config
import (
"time"
"github.com/docker/docker/api/types/container"
)
// Config is a basic configuration of an image at each step. It is kept in sync
// by commit routines in the executor. Setting properties here will propogate
// them to various image-manipulating commands when needed.
type Config struct {
Image string // Image Identifier, may be different across executors.
User string // the currently configured user for this image.
WorkDir string // the current working directory on entering a container
Cmd []string // the secondary execution form, it is provided to images if given to docker run, otherwise this is used.
Entrypoint []string // the primary execution form, the first arguments and the exec() jumping-off point.
Env []string
}
// NewConfig initializes a new configuration.
func NewConfig() *Config {
return &Config{
Env: []string{},
Cmd: []string{"/bin/sh"},
User: "root",
WorkDir: "/",
Image: "",
}
}
// ToDocker outputs a docker configuration suitable for running images.
func (c *Config) ToDocker(tty, stdin bool) *container.Config {
return &container.Config{
Tty: tty,
AttachStderr: true,
AttachStdout: true,
AttachStdin: stdin,
OpenStdin: stdin,
Image: c.Image,
Env: c.Env,
Entrypoint: c.Entrypoint,
Cmd: c.Cmd,
User: c.User,
WorkingDir: c.WorkDir,
}
}
// FromDocker sets *Config properties from a docker *container.Config
func (c *Config) FromDocker(cont *container.Config) {
c.Image = cont.Image
c.Env = cont.Env
c.Entrypoint = cont.Entrypoint
c.Cmd = cont.Cmd
c.User = cont.User
c.WorkDir = cont.WorkingDir
}
// ToImage returns the config as an image manifest.
func (c *Config) ToImage(layers []string) map[string]interface{} {
fields := map[string]interface{}{}
fields["config"] = c.ToDocker(false, false)
fields["created"] = time.Now().Format("2006-01-02T15:04:05Z07:00")
fields["architecture"] = "amd64"
fields["os"] = "linux"
fields["history"] = []map[string]interface{}{{}}
fields["rootfs"] = map[string]interface{}{
"diff_ids": layers,
"type": "layers",
}
return fields
}