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

Support for building images #62

Open
advdv opened this issue Jan 7, 2015 · 2 comments
Open

Support for building images #62

advdv opened this issue Jan 7, 2015 · 2 comments

Comments

@advdv
Copy link

advdv commented Jan 7, 2015

Hey, I am working with this client after seeing it being used by Docker swarm and the client feels solid. I'm currently missing a way to build images though: https://docs.docker.com/reference/api/docker_remote_api_v1.16/#build-an-image-from-dockerfile-via-stdin
Is this feature planned? Having looked around a bit it seems quite trivial to implement as long as we don't do any client trickery (.dockerignore etc), I can help out ofcourse.

@divideandconquer
Copy link
Contributor

I too am looking for an easy way to do this.

@advdv
Copy link
Author

advdv commented Mar 31, 2015

I use the following right now (https://github.com/dockpit/pit/blob/master/client/docker.go#L146):

Basicly sending a post request with tar bytes in the request body, d.client is the samalba/dockerclient:

    // fall back to streaming ourselves for building the image
    // implement image building: https://github.com/samalba/dockerclient/issues/62
    req, err := http.NewRequest("POST", fmt.Sprintf("%s/build?t=%s", d.client.URL, iname), in)
    if err != nil {
        return "", errwrap.Wrapf(fmt.Sprintf("Failed to create Docker build request for '%s'::'%s': {{err}}", dep.Name, state.Name), err)
    }

    req.Header.Set("Content-Type", "application/tar")

    b.IsRunning = true
    resp, err := d.client.HTTPClient.Do(req)
    if err != nil {
        return "", errwrap.Wrapf(fmt.Sprintf("Docker build request failed for '%s'::'%s': {{err}}", dep.Name, state.Name), err)
    }

    b.IsRunning = false

    defer resp.Body.Close()
    defer io.Copy(out, resp.Body)
    if resp.StatusCode > 200 {
        return "", fmt.Errorf("Unexpected response while building Docker image for '%s'::'%s': %s", dep.Name, state.Name, resp.Status)
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants