Skip to content

Commit

Permalink
SAVEPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Gągor committed Dec 27, 2024
1 parent 5b7bd1f commit 7df1f43
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/builder/buildx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ func (b *BuildxBuilder) SetDryRun(dryRun bool) {
func (b *BuildxBuilder) Build(dockerfile, imageName string, configSet map[string]interface{}, contextDir string, verbose bool) {
platforms := configSet["platforms"].([]string)
labels := configSet["labels"].(map[string]string)
buildArgs := configSet["args"].(map[string]interface{})
builder := cmd.New("docker").Arg("buildx").Arg("build")
if len(platforms) > 0 {
builder.Arg(platformsToArgs(platforms)...)
}
builder.Arg("-f", dockerfile).Arg("-t", imageName).Arg(labelsToArgs(labels)...).Arg(contextDir).SetVerbose(verbose)
builder.Arg("-f", dockerfile).Arg("-t", imageName).
Arg(labelsToArgs(labels)...).
Arg(argsToArgs(buildArgs)...).
Arg(contextDir).SetVerbose(verbose)
b.buildTasks.AddTask(builder)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/builder/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (b *DockerBuilder) Build(dockerfile, imageName string, configSet map[string
Arg("-f", dockerfile).
Arg("-t", imageName).
Arg(labelsToArgs(configSet["labels"].(map[string]string))...).
Arg(argsToArgs(configSet["args"].(map[string]interface{}))...).
Arg(contextDir).
PreInfo("Building " + imageName).
SetVerbose(verbose)
Expand Down
9 changes: 9 additions & 0 deletions pkg/builder/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package builder

import (
"encoding/json"
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -57,6 +58,14 @@ func labelsToArgs(labels map[string]string) []string {
return args
}

func argsToArgs(buildArgs map[string]interface{}) []string {
args := []string{}
for k, v := range buildArgs {
args = append(args, "--arg", fmt.Sprintf("%s=%s", k, v))
}
return args
}

func platformsToArgs(platforms []string) []string {
args := []string{}
args = append(args, "--platform", strings.Join(platforms, ","))
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ImageConfig struct {
Excludes []map[string]interface{} `yaml:"excludes"`
Tags []string `yaml:"tags"`
Labels map[string]string `yaml:"labels"`
Args map[string]string `yaml:"args"`
Platforms []string `yaml:"platforms"`
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func Run(workdir string, cfg *config.Config, flags config.Flags) error {
labels := collectOCILabels(configSet)
maps.Copy(labels, collectLabels(configSet))

// Collect build args
// buildArgs := collectBuildArgs(configSet)

var dockerfile string
if strings.HasSuffix(dockerfileTemplate, ".tpl") {
dockerfile = generateDockerfilePath(dockerfileTemplate, name, configSet)
Expand Down Expand Up @@ -189,6 +192,7 @@ func generateConfigSet(imageName string, cfg *config.Config, currentConfigSet ma

func collectLabels(configSet map[string]interface{}) map[string]string {
labels, err := templateLabels(configSet["labels"].(map[string]string), configSet)
// FIXME: return this error further
util.FailOnError(err)
if len(labels) > 0 {
log.Info().Interface("labels", labels).Msg("Generating")
Expand All @@ -198,6 +202,7 @@ func collectLabels(configSet map[string]interface{}) map[string]string {

func collectTags(img config.ImageConfig, configSet map[string]interface{}, name string) []string {
tags, err := templateTags(img.Tags, configSet)
// FIXME: return this error further
util.FailOnError(err)
if len(tags) > 0 {
log.Info().Interface("tags", tags).Msg("Generating")
Expand Down

0 comments on commit 7df1f43

Please sign in to comment.