Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

adding build image functionality #85

Closed
wants to merge 3 commits into from

Conversation

divideandconquer
Copy link
Contributor

fixes issue #62

usage:

docker, err := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
if err != nil {
    return err
}

image := dockerclient.BuildImage{}
image.Name = name
image.Files = make(map[string]string)
image.Files["Dockerfile"] = "FROM scratch"

config := &dockerclient.ConfigFile{}
config.Configs = make(map[string]dockerclient.AuthConfig)
config.Configs["<uri to quay>"] = auth

err = docker.BuildImage(image, config)
if err != nil {
    return err
}

@ehazlett
Copy link
Collaborator

ehazlett commented Apr 2, 2015

I'm not sure about the Configs and ConfigFile names but I've tested this and it works to build. Perhaps name them AuthConfigs and BuildConfig or ImageConfig?

@divideandconquer
Copy link
Contributor Author

ConfigFile is actually a copy of the docker ConfigFile object: https://github.com/docker/docker/blob/master/registry/auth.go#L37 just like AuthConfig is. Hence the name. Since AuthConfig is already copied from docker I figured I'd do the same instead of importing the package.

I had to go digging through the docker code for it since the api docs just say to send a base64 encoded config file and doesn't say what that is.

@ehazlett
Copy link
Collaborator

ehazlett commented Apr 4, 2015

@divideandconquer ah cool - that works for me :)

@jimmyxian
Copy link
Contributor

@divideandconquer Cool
In swarm, I also want use this interface.But want build in streaming. docker-archive/classicswarm#632

type BuildImage struct {
    Name           string
    Remote         string
    DockerfilePath string
    Tarfile          io.Reader    // use tarfile io.Reader instead of files
    NoCache        bool
    Pull           bool
    Remove         bool
    ForceRemove    bool
}

Also, add out io.Writer in interface
If you are busy, i can help you do this. thks

@divideandconquer
Copy link
Contributor Author

Seems like an easy enough change but I'm not sure what you mean by adding an out io.Writer If you want the response body I can just return that (io.ReadCloser).

@divideandconquer divideandconquer mentioned this pull request Apr 24, 2015
@jimmyxian
Copy link
Contributor

@divideandconquer Thanks very much
Yeah, just return r.Body. I modified locally as following, it works for me in swarm:


func (client *DockerClient) BuildImage(image BuildImage, config *ConfigFile) (io.ReadCloser, error) {
    v := url.Values{}
    if image.DockerfilePath != "" {
        v.Set("dockerfile", image.DockerfilePath)
    }
    if image.Name != "" {
        v.Set("t", image.Name)
    }
    if image.Remote != "" {
        v.Set("remote", image.Remote)
    }
    if image.NoCache {
        v.Set("nocache", "1")
    }
    if image.Pull {
        v.Set("pull", "1")
    }
    if image.Remove {
        v.Set("rm", "1")
    } else {
        v.Set("rm", "0")
    }
    if image.ForceRemove {
        v.Set("forcerm", "1")
    }
    v.Set("q", "1")
    uri := fmt.Sprintf("/%s/build?%s", APIVersion, v.Encode())

    req, err := http.NewRequest("POST", client.URL.String()+uri, image.Tarfile)
    if config != nil {
        req.Header.Add("X-Registry-Config", config.encode())
    }
    req.Header.Set("Content-Type", "application/tar")
    resp, err := client.HTTPClient.Do(req)
    if err != nil {
        return nil, err
    }
    return resp.Body, nil

Also, I think we should also add Registry-Auth config parameter, and put X-Registry-Auth in request header.

@aluzzardi
Copy link
Collaborator

Hey, didn't get a chance to look into this yet and I didn't follow the results of the comments, but just to make sure, will this provide full duplex streaming (context in, build output out)?

Basically, I'd like for BuildImage() to never touch the filesystem nor buffer anything in memory.

In order words, I should be able to BuildImage() 10GB of context on a machine with 32MB of memory and a filesystem backed by a floppy disk :)

@ehazlett
Copy link
Collaborator

Thanks for the contribution. Can this be closed now that #108 is merged?

@donhcd donhcd closed this Oct 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants