Skip to content

Commit

Permalink
build with auth configs
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 18, 2019
1 parent abcf58a commit ec49d62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
27 changes: 13 additions & 14 deletions cluster/calcium/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ func (c *Calcium) BuildDockerImage(ctx context.Context, opts *types.BuildOptions
if err != nil {
return nil, err
}
// tag of image, later this will be used to push image to hub
tags := []string{}
for i := range opts.Tags {
if opts.Tags[i] != "" {
tag := createImageTag(c.config.Docker, opts.Name, opts.Tags[i])
tags = append(tags, tag)
}
}
// use latest
if len(tags) == 0 {
tags = append(tags, createImageTag(c.config.Docker, opts.Name, utils.DefaultVersion))
}
// support raw build
buildContext := opts.Tar
if opts.Builds != nil {
Expand All @@ -98,8 +86,19 @@ func (c *Calcium) BuildDockerImage(ctx context.Context, opts *types.BuildOptions
return nil, err
}
}

log.Infof("[BuildImage] Building image %v:%v", node.Podname, node.Name)
// tag of image, later this will be used to push image to hub
tags := []string{}
for i := range opts.Tags {
if opts.Tags[i] != "" {
tag := createImageTag(c.config.Docker, opts.Name, opts.Tags[i])
tags = append(tags, tag)
}
}
// use latest
if len(tags) == 0 {
tags = append(tags, createImageTag(c.config.Docker, opts.Name, utils.DefaultVersion))
}
log.Infof("[BuildImage] Building image at pod %s node %s", node.Podname, node.Name)
return c.doBuildImage(ctx, buildContext, node, tags)
}

Expand Down
15 changes: 15 additions & 0 deletions engine/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,28 @@ func (e *Engine) ImagePush(ctx context.Context, ref string) (io.ReadCloser, erro

// ImageBuild build image
func (e *Engine) ImageBuild(ctx context.Context, input io.Reader, refs []string) (io.ReadCloser, error) {
authConfigs := map[string]dockertypes.AuthConfig{}
for domain, conf := range e.config.Docker.AuthConfigs {
b64auth, err := encodeAuthToBase64(conf)
if err != nil {
return nil, err
}
if _, ok := authConfigs[domain]; !ok {
authConfigs[domain] = dockertypes.AuthConfig{
Username: conf.Username,
Password: conf.Password,
Auth: b64auth,
}
}
}
buildOptions := dockertypes.ImageBuildOptions{
Tags: refs,
SuppressOutput: false,
NoCache: true,
Remove: true,
ForceRemove: true,
PullParent: true,
AuthConfigs: authConfigs,
}
resp, err := e.client.ImageBuild(ctx, input, buildOptions)
if err != nil {
Expand Down

0 comments on commit ec49d62

Please sign in to comment.