2021-03-18 03:30:54 -04:00
|
|
|
package provider
|
2015-02-17 11:28:33 -05:00
|
|
|
|
|
|
|
|
import (
|
2020-12-02 06:06:39 -05:00
|
|
|
"bytes"
|
2018-07-03 11:30:53 -04:00
|
|
|
"context"
|
2020-12-02 06:06:39 -05:00
|
|
|
"encoding/base64"
|
|
|
|
|
"encoding/json"
|
2015-02-17 11:28:33 -05:00
|
|
|
"fmt"
|
2020-10-07 14:06:13 -04:00
|
|
|
"io"
|
2018-07-03 11:30:53 -04:00
|
|
|
"log"
|
2021-05-11 04:00:02 -04:00
|
|
|
"path/filepath"
|
2015-02-17 11:28:33 -05:00
|
|
|
"strings"
|
|
|
|
|
|
2020-10-07 14:06:13 -04:00
|
|
|
"github.com/docker/cli/cli/command/image/build"
|
2018-07-03 11:30:53 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
|
"github.com/docker/docker/client"
|
2020-10-07 14:06:13 -04:00
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2021-03-18 03:30:54 -04:00
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
2020-10-07 14:06:13 -04:00
|
|
|
"github.com/mitchellh/go-homedir"
|
2015-02-17 11:28:33 -05:00
|
|
|
)
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func resourceDockerImageCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
|
2017-11-21 04:14:07 -05:00
|
|
|
client := meta.(*ProviderConfig).DockerClient
|
2019-05-26 05:42:53 -04:00
|
|
|
imageName := d.Get("name").(string)
|
2020-10-07 14:06:13 -04:00
|
|
|
|
|
|
|
|
if value, ok := d.GetOk("build"); ok {
|
|
|
|
|
for _, rawBuild := range value.(*schema.Set).List() {
|
|
|
|
|
rawBuild := rawBuild.(map[string]interface{})
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
err := buildDockerImage(ctx, rawBuild, imageName, client)
|
2020-10-07 14:06:13 -04:00
|
|
|
if err != nil {
|
2021-03-18 03:30:54 -04:00
|
|
|
return diag.FromErr(err)
|
2020-10-07 14:06:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-18 03:30:54 -04:00
|
|
|
apiImage, err := findImage(ctx, imageName, client, meta.(*ProviderConfig).AuthConfigs)
|
2015-02-17 11:28:33 -05:00
|
|
|
if err != nil {
|
2021-03-18 03:30:54 -04:00
|
|
|
return diag.Errorf("Unable to read Docker image into resource: %s", err)
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.SetId(apiImage.ID + d.Get("name").(string))
|
2021-03-18 03:30:54 -04:00
|
|
|
return resourceDockerImageRead(ctx, d, meta)
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func resourceDockerImageRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
|
2017-11-21 04:14:07 -05:00
|
|
|
client := meta.(*ProviderConfig).DockerClient
|
2016-07-26 11:18:38 -04:00
|
|
|
var data Data
|
2021-03-18 03:30:54 -04:00
|
|
|
if err := fetchLocalImages(ctx, &data, client); err != nil {
|
|
|
|
|
return diag.Errorf("Error reading docker image list: %s", err)
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
2019-11-23 08:42:05 -05:00
|
|
|
for id := range data.DockerImages {
|
|
|
|
|
log.Printf("[DEBUG] local images data: %v", id)
|
|
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2021-03-29 05:23:48 -04:00
|
|
|
imageName := d.Get("name").(string)
|
|
|
|
|
|
|
|
|
|
foundImage := searchLocalImages(ctx, client, data, imageName)
|
2019-11-23 08:42:05 -05:00
|
|
|
if foundImage == nil {
|
2016-07-26 11:18:38 -04:00
|
|
|
d.SetId("")
|
2019-11-23 08:42:05 -05:00
|
|
|
return nil
|
2016-07-26 11:18:38 -04:00
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2019-11-23 08:42:05 -05:00
|
|
|
d.SetId(foundImage.ID + d.Get("name").(string))
|
|
|
|
|
d.Set("latest", foundImage.ID)
|
2015-02-17 11:28:33 -05:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func resourceDockerImageUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
|
2015-02-17 11:28:33 -05:00
|
|
|
// We need to re-read in case switching parameters affects
|
|
|
|
|
// the value of "latest" or others
|
2017-11-21 04:14:07 -05:00
|
|
|
client := meta.(*ProviderConfig).DockerClient
|
2019-05-26 05:42:53 -04:00
|
|
|
imageName := d.Get("name").(string)
|
2021-03-18 03:30:54 -04:00
|
|
|
apiImage, err := findImage(ctx, imageName, client, meta.(*ProviderConfig).AuthConfigs)
|
2016-07-26 11:18:38 -04:00
|
|
|
if err != nil {
|
2021-03-18 03:30:54 -04:00
|
|
|
return diag.Errorf("Unable to read Docker image into resource: %s", err)
|
2016-07-26 11:18:38 -04:00
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2016-07-26 11:18:38 -04:00
|
|
|
d.Set("latest", apiImage.ID)
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
return resourceDockerImageRead(ctx, d, meta)
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func resourceDockerImageDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
|
2017-11-21 04:14:07 -05:00
|
|
|
client := meta.(*ProviderConfig).DockerClient
|
2021-03-18 03:30:54 -04:00
|
|
|
err := removeImage(ctx, d, client)
|
2016-03-23 00:56:51 -04:00
|
|
|
if err != nil {
|
2021-03-18 03:30:54 -04:00
|
|
|
return diag.Errorf("Unable to remove Docker image: %s", err)
|
2016-03-23 00:56:51 -04:00
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
d.SetId("")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 09:33:13 -04:00
|
|
|
// Helpers
|
2021-03-29 05:23:48 -04:00
|
|
|
func searchLocalImages(ctx context.Context, client *client.Client, data Data, imageName string) *types.ImageSummary {
|
|
|
|
|
imageInspect, _, err := client.ImageInspectWithRaw(ctx, imageName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
2016-03-23 00:56:51 -04:00
|
|
|
}
|
2021-03-29 05:23:48 -04:00
|
|
|
|
|
|
|
|
if apiImage, ok := data.DockerImages[imageInspect.ID]; ok {
|
|
|
|
|
log.Printf("[DEBUG] found local image via imageName: %v", imageName)
|
2016-03-23 00:56:51 -04:00
|
|
|
return apiImage
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func removeImage(ctx context.Context, d *schema.ResourceData, client *client.Client) error {
|
2016-03-23 00:56:51 -04:00
|
|
|
var data Data
|
2016-04-27 12:18:02 -04:00
|
|
|
|
|
|
|
|
if keepLocally := d.Get("keep_locally").(bool); keepLocally {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
if err := fetchLocalImages(ctx, &data, client); err != nil {
|
2016-03-23 00:56:51 -04:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imageName := d.Get("name").(string)
|
|
|
|
|
if imageName == "" {
|
|
|
|
|
return fmt.Errorf("Empty image name is not allowed")
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 05:23:48 -04:00
|
|
|
foundImage := searchLocalImages(ctx, client, data, imageName)
|
2016-03-23 00:56:51 -04:00
|
|
|
|
|
|
|
|
if foundImage != nil {
|
2021-03-18 03:30:54 -04:00
|
|
|
imageDeleteResponseItems, err := client.ImageRemove(ctx, imageName, types.ImageRemoveOptions{
|
2020-12-29 02:03:40 -05:00
|
|
|
Force: d.Get("force_remove").(bool),
|
|
|
|
|
})
|
2016-03-23 00:56:51 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
log.Printf("[INFO] Deleted image items: %v", imageDeleteResponseItems)
|
2016-03-23 00:56:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func fetchLocalImages(ctx context.Context, data *Data, client *client.Client) error {
|
|
|
|
|
images, err := client.ImageList(ctx, types.ImageListOptions{All: false})
|
2015-02-17 11:28:33 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Unable to list Docker images: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-28 21:37:20 -04:00
|
|
|
if data.DockerImages == nil {
|
2018-07-03 11:30:53 -04:00
|
|
|
data.DockerImages = make(map[string]*types.ImageSummary)
|
2015-03-28 21:37:20 -04:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 11:28:33 -05:00
|
|
|
// Docker uses different nomenclatures in different places...sometimes a short
|
|
|
|
|
// ID, sometimes long, etc. So we store both in the map so we can always find
|
2018-10-12 02:43:28 -04:00
|
|
|
// the same image object. We store the tags and digests, too.
|
2015-02-17 11:28:33 -05:00
|
|
|
for i, image := range images {
|
|
|
|
|
data.DockerImages[image.ID[:12]] = &images[i]
|
|
|
|
|
data.DockerImages[image.ID] = &images[i]
|
|
|
|
|
for _, repotag := range image.RepoTags {
|
|
|
|
|
data.DockerImages[repotag] = &images[i]
|
|
|
|
|
}
|
2018-10-12 02:43:28 -04:00
|
|
|
for _, repodigest := range image.RepoDigests {
|
|
|
|
|
data.DockerImages[repodigest] = &images[i]
|
|
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func pullImage(ctx context.Context, data *Data, client *client.Client, authConfig *AuthConfigs, image string) error {
|
2016-07-26 11:18:38 -04:00
|
|
|
pullOpts := parseImageOptions(image)
|
2017-11-21 04:14:07 -05:00
|
|
|
|
|
|
|
|
// If a registry was specified in the image name, try to find auth for it
|
2018-07-03 11:30:53 -04:00
|
|
|
auth := types.AuthConfig{}
|
2017-11-21 04:14:07 -05:00
|
|
|
if pullOpts.Registry != "" {
|
|
|
|
|
if authConfig, ok := authConfig.Configs[normalizeRegistryAddress(pullOpts.Registry)]; ok {
|
|
|
|
|
auth = authConfig
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Try to find an auth config for the public docker hub if a registry wasn't given
|
|
|
|
|
if authConfig, ok := authConfig.Configs["https://registry.hub.docker.com"]; ok {
|
|
|
|
|
auth = authConfig
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-26 11:18:38 -04:00
|
|
|
|
2018-07-03 11:30:53 -04:00
|
|
|
encodedJSON, err := json.Marshal(auth)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating auth config: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
out, err := client.ImagePull(ctx, image, types.ImagePullOptions{
|
2018-07-03 11:30:53 -04:00
|
|
|
RegistryAuth: base64.URLEncoding.EncodeToString(encodedJSON),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error pulling image %s: %s", image, err)
|
2016-07-26 11:18:38 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
defer out.Close()
|
|
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
2020-12-20 05:04:51 -05:00
|
|
|
if _, err := buf.ReadFrom(out); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
s := buf.String()
|
|
|
|
|
log.Printf("[DEBUG] pulled image %v: %v", image, s)
|
2016-07-26 11:18:38 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
return nil
|
2016-07-26 11:18:38 -04:00
|
|
|
}
|
|
|
|
|
|
2018-07-03 11:30:53 -04:00
|
|
|
type internalPullImageOptions struct {
|
|
|
|
|
Repository string `qs:"fromImage"`
|
|
|
|
|
Tag string
|
|
|
|
|
|
|
|
|
|
// Only required for Docker Engine 1.9 or 1.10 w/ Remote API < 1.21
|
|
|
|
|
// and Docker Engine < 1.9
|
|
|
|
|
// This parameter was removed in Docker Engine 1.11
|
|
|
|
|
Registry string
|
|
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2018-07-03 11:30:53 -04:00
|
|
|
func parseImageOptions(image string) internalPullImageOptions {
|
|
|
|
|
pullOpts := internalPullImageOptions{}
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2018-03-23 05:58:14 -04:00
|
|
|
// Pre-fill with image by default, update later if tag found
|
|
|
|
|
pullOpts.Repository = image
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2018-03-23 05:58:14 -04:00
|
|
|
firstSlash := strings.Index(image, "/")
|
|
|
|
|
|
|
|
|
|
// Detect the registry name - it should either contain port, be fully qualified or be localhost
|
|
|
|
|
// If the image contains more than 2 path components, or at least one and the prefix looks like a hostname
|
|
|
|
|
if strings.Count(image, "/") > 1 || firstSlash != -1 && (strings.ContainsAny(image[:firstSlash], ".:") || image[:firstSlash] == "localhost") {
|
|
|
|
|
// registry/repo/image
|
|
|
|
|
pullOpts.Registry = image[:firstSlash]
|
|
|
|
|
}
|
2015-02-17 11:28:33 -05:00
|
|
|
|
2018-03-23 05:58:14 -04:00
|
|
|
prefixLength := len(pullOpts.Registry)
|
|
|
|
|
tagIndex := strings.Index(image[prefixLength:], ":")
|
|
|
|
|
|
|
|
|
|
if tagIndex != -1 {
|
|
|
|
|
// we have the tag, strip it
|
|
|
|
|
pullOpts.Repository = image[:prefixLength+tagIndex]
|
|
|
|
|
pullOpts.Tag = image[prefixLength+tagIndex+1:]
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2021-01-06 13:54:31 -05:00
|
|
|
if pullOpts.Tag == "" {
|
|
|
|
|
pullOpts.Tag = "latest"
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-26 11:18:38 -04:00
|
|
|
return pullOpts
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func findImage(ctx context.Context, imageName string, client *client.Client, authConfig *AuthConfigs) (*types.ImageSummary, error) {
|
2015-02-17 11:28:33 -05:00
|
|
|
if imageName == "" {
|
|
|
|
|
return nil, fmt.Errorf("Empty image name is not allowed")
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
var data Data
|
|
|
|
|
// load local images into the data structure
|
2021-03-18 03:30:54 -04:00
|
|
|
if err := fetchLocalImages(ctx, &data, client); err != nil {
|
2019-05-26 05:42:53 -04:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 05:23:48 -04:00
|
|
|
foundImage := searchLocalImages(ctx, client, data, imageName)
|
2019-05-26 05:42:53 -04:00
|
|
|
if foundImage != nil {
|
|
|
|
|
return foundImage, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
if err := pullImage(ctx, &data, client, authConfig, imageName); err != nil {
|
2017-01-03 11:10:39 -05:00
|
|
|
return nil, fmt.Errorf("Unable to pull image %s: %s", imageName, err)
|
2015-02-17 11:28:33 -05:00
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
// update the data structure of the images
|
2021-03-18 03:30:54 -04:00
|
|
|
if err := fetchLocalImages(ctx, &data, client); err != nil {
|
2019-05-26 05:42:53 -04:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 05:23:48 -04:00
|
|
|
foundImage = searchLocalImages(ctx, client, data, imageName)
|
2015-02-17 11:28:33 -05:00
|
|
|
if foundImage != nil {
|
|
|
|
|
return foundImage, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("Unable to find or pull image %s", imageName)
|
|
|
|
|
}
|
2020-10-07 14:06:13 -04:00
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
func buildDockerImage(ctx context.Context, rawBuild map[string]interface{}, imageName string, client *client.Client) error {
|
2020-10-07 14:06:13 -04:00
|
|
|
buildOptions := types.ImageBuildOptions{}
|
|
|
|
|
|
|
|
|
|
buildOptions.Version = types.BuilderV1
|
|
|
|
|
buildOptions.Dockerfile = rawBuild["dockerfile"].(string)
|
|
|
|
|
|
|
|
|
|
tags := []string{imageName}
|
|
|
|
|
for _, t := range rawBuild["tag"].([]interface{}) {
|
|
|
|
|
tags = append(tags, t.(string))
|
|
|
|
|
}
|
|
|
|
|
buildOptions.Tags = tags
|
|
|
|
|
|
|
|
|
|
buildOptions.ForceRemove = rawBuild["force_remove"].(bool)
|
|
|
|
|
buildOptions.Remove = rawBuild["remove"].(bool)
|
|
|
|
|
buildOptions.NoCache = rawBuild["no_cache"].(bool)
|
|
|
|
|
buildOptions.Target = rawBuild["target"].(string)
|
|
|
|
|
|
|
|
|
|
buildArgs := make(map[string]*string)
|
|
|
|
|
for k, v := range rawBuild["build_arg"].(map[string]interface{}) {
|
|
|
|
|
val := v.(string)
|
|
|
|
|
buildArgs[k] = &val
|
|
|
|
|
}
|
|
|
|
|
buildOptions.BuildArgs = buildArgs
|
|
|
|
|
log.Printf("[DEBUG] Build Args: %v\n", buildArgs)
|
|
|
|
|
|
|
|
|
|
labels := make(map[string]string)
|
|
|
|
|
for k, v := range rawBuild["label"].(map[string]interface{}) {
|
|
|
|
|
labels[k] = v.(string)
|
|
|
|
|
}
|
|
|
|
|
buildOptions.Labels = labels
|
|
|
|
|
log.Printf("[DEBUG] Labels: %v\n", labels)
|
|
|
|
|
|
|
|
|
|
contextDir := rawBuild["path"].(string)
|
|
|
|
|
excludes, err := build.ReadDockerignore(contextDir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
excludes = build.TrimBuildFilesFromExcludes(excludes, buildOptions.Dockerfile, false)
|
|
|
|
|
|
|
|
|
|
var response types.ImageBuildResponse
|
2021-03-18 03:30:54 -04:00
|
|
|
response, err = client.ImageBuild(ctx, getBuildContext(contextDir, excludes), buildOptions)
|
2020-10-07 14:06:13 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer response.Body.Close()
|
|
|
|
|
|
|
|
|
|
buildResult, err := decodeBuildMessages(response)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("%s\n\n%s", err, buildResult)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-04-19 09:33:13 -04:00
|
|
|
|
|
|
|
|
func getBuildContext(filePath string, excludes []string) io.Reader {
|
|
|
|
|
filePath, _ = homedir.Expand(filePath)
|
2021-05-11 04:00:02 -04:00
|
|
|
//TarWithOptions works only with absolute paths in Windows.
|
|
|
|
|
filePath, err := filepath.Abs(filePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Invalid build directory: %s", filePath)
|
|
|
|
|
}
|
2021-04-19 09:33:13 -04:00
|
|
|
ctx, _ := archive.TarWithOptions(filePath, &archive.TarOptions{
|
|
|
|
|
ExcludePatterns: excludes,
|
|
|
|
|
})
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func decodeBuildMessages(response types.ImageBuildResponse) (string, error) {
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
buildErr := error(nil)
|
|
|
|
|
|
|
|
|
|
dec := json.NewDecoder(response.Body)
|
|
|
|
|
for dec.More() {
|
|
|
|
|
var m jsonmessage.JSONMessage
|
|
|
|
|
err := dec.Decode(&m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return buf.String(), fmt.Errorf("Problem decoding message from docker daemon: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := m.Display(buf, false); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if m.Error != nil {
|
|
|
|
|
buildErr = fmt.Errorf("Unable to build image")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.Printf("[DEBUG] %s", buf.String())
|
|
|
|
|
|
|
|
|
|
return buf.String(), buildErr
|
|
|
|
|
}
|