mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use pointers for the object methods
This commit is contained in:
parent
0d2fb29537
commit
f35f084059
1 changed files with 14 additions and 12 deletions
|
@ -31,7 +31,7 @@ type builderClient struct {
|
||||||
needCommit bool
|
needCommit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) clearTmp(containers, images map[string]struct{}) {
|
func (b *builderClient) clearTmp(containers, images map[string]struct{}) {
|
||||||
for c := range containers {
|
for c := range containers {
|
||||||
if _, _, err := b.cli.call("DELETE", "/containers/"+c, nil); err != nil {
|
if _, _, err := b.cli.call("DELETE", "/containers/"+c, nil); err != nil {
|
||||||
utils.Debugf("%s", err)
|
utils.Debugf("%s", err)
|
||||||
|
@ -46,7 +46,7 @@ func (b builderClient) clearTmp(containers, images map[string]struct{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdFrom(name string) error {
|
func (b *builderClient) CmdFrom(name string) error {
|
||||||
obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil)
|
obj, statusCode, err := b.cli.call("GET", "/images/"+name+"/json", nil)
|
||||||
if statusCode == 404 {
|
if statusCode == 404 {
|
||||||
if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil {
|
if err := b.cli.hijack("POST", "/images/create?fromImage="+name, false); err != nil {
|
||||||
|
@ -66,16 +66,17 @@ func (b builderClient) CmdFrom(name string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.image = img.Id
|
b.image = img.Id
|
||||||
|
utils.Debugf("Using image %s", b.image)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdMaintainer(name string) error {
|
func (b *builderClient) CmdMaintainer(name string) error {
|
||||||
b.needCommit = true
|
b.needCommit = true
|
||||||
b.maintainer = name
|
b.maintainer = name
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdRun(args string) error {
|
func (b *builderClient) CmdRun(args string) error {
|
||||||
if b.image == "" {
|
if b.image == "" {
|
||||||
return fmt.Errorf("Please provide a source image with `from` prior to run")
|
return fmt.Errorf("Please provide a source image with `from` prior to run")
|
||||||
}
|
}
|
||||||
|
@ -111,7 +112,7 @@ func (b builderClient) CmdRun(args string) error {
|
||||||
return b.commit(cid)
|
return b.commit(cid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdEnv(args string) error {
|
func (b *builderClient) CmdEnv(args string) error {
|
||||||
b.needCommit = true
|
b.needCommit = true
|
||||||
tmp := strings.SplitN(args, " ", 2)
|
tmp := strings.SplitN(args, " ", 2)
|
||||||
if len(tmp) != 2 {
|
if len(tmp) != 2 {
|
||||||
|
@ -130,10 +131,11 @@ func (b builderClient) CmdEnv(args string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdCmd(args string) error {
|
func (b *builderClient) CmdCmd(args string) error {
|
||||||
b.needCommit = true
|
b.needCommit = true
|
||||||
var cmd []string
|
var cmd []string
|
||||||
if err := json.Unmarshal([]byte(args), &cmd); err != nil {
|
if err := json.Unmarshal([]byte(args), &cmd); err != nil {
|
||||||
|
utils.Debugf("Error unmarshalling: %s, using /bin/sh -c", err)
|
||||||
b.config.Cmd = []string{"/bin/sh", "-c", args}
|
b.config.Cmd = []string{"/bin/sh", "-c", args}
|
||||||
} else {
|
} else {
|
||||||
b.config.Cmd = cmd
|
b.config.Cmd = cmd
|
||||||
|
@ -141,19 +143,19 @@ func (b builderClient) CmdCmd(args string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdExpose(args string) error {
|
func (b *builderClient) CmdExpose(args string) error {
|
||||||
ports := strings.Split(args, " ")
|
ports := strings.Split(args, " ")
|
||||||
b.config.PortSpecs = append(ports, b.config.PortSpecs...)
|
b.config.PortSpecs = append(ports, b.config.PortSpecs...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) CmdInsert(args string) error {
|
func (b *builderClient) CmdInsert(args string) error {
|
||||||
// FIXME: Reimplement this once the remove_hijack branch gets merged.
|
// FIXME: Reimplement this once the remove_hijack branch gets merged.
|
||||||
// We need to retrieve the resulting Id
|
// We need to retrieve the resulting Id
|
||||||
return fmt.Errorf("INSERT not implemented")
|
return fmt.Errorf("INSERT not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) run() (string, error) {
|
func (b *builderClient) run() (string, error) {
|
||||||
if b.image == "" {
|
if b.image == "" {
|
||||||
return "", fmt.Errorf("Please provide a source image with `from` prior to run")
|
return "", fmt.Errorf("Please provide a source image with `from` prior to run")
|
||||||
}
|
}
|
||||||
|
@ -194,7 +196,7 @@ func (b builderClient) run() (string, error) {
|
||||||
return apiRun.Id, nil
|
return apiRun.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) commit(id string) error {
|
func (b *builderClient) commit(id string) error {
|
||||||
if b.image == "" {
|
if b.image == "" {
|
||||||
return fmt.Errorf("Please provide a source image with `from` prior to run")
|
return fmt.Errorf("Please provide a source image with `from` prior to run")
|
||||||
}
|
}
|
||||||
|
@ -230,7 +232,7 @@ func (b builderClient) commit(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b builderClient) Build(dockerfile io.Reader) (string, error) {
|
func (b *builderClient) Build(dockerfile io.Reader) (string, error) {
|
||||||
// defer b.clearTmp(tmpContainers, tmpImages)
|
// defer b.clearTmp(tmpContainers, tmpImages)
|
||||||
file := bufio.NewReader(dockerfile)
|
file := bufio.NewReader(dockerfile)
|
||||||
for {
|
for {
|
||||||
|
@ -253,7 +255,7 @@ func (b builderClient) Build(dockerfile io.Reader) (string, error) {
|
||||||
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
||||||
arguments := strings.Trim(tmp[1], " ")
|
arguments := strings.Trim(tmp[1], " ")
|
||||||
|
|
||||||
fmt.Printf("%s %s\n", strings.ToUpper(instruction), arguments)
|
fmt.Printf("%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
|
||||||
|
|
||||||
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
||||||
if !exists {
|
if !exists {
|
||||||
|
|
Loading…
Reference in a new issue