Skip to content

Commit

Permalink
dedicated tag flag when building minified images from Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
kcq committed Nov 16, 2019
1 parent 6f727c1 commit 3c2956b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 12 additions & 2 deletions internal/app/master/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const (
FlagUseLocalMounts = "use-local-mounts"
FlagUseSensorVolume = "use-sensor-volume"
FlagKeepTmpArtifacts = "keep-tmp-artifacts"
FlagTag = "tag"
FlagTagFat = "tag-fat"
)

var app *cli.App
Expand Down Expand Up @@ -590,11 +592,17 @@ func init() {
doCopyMetaArtifactsFlag,
doRemoveFileArtifactsFlag,
cli.StringFlag{
Name: "tag",
Name: FlagTag,
Value: "",
Usage: "Custom tag for the generated image",
EnvVar: "DSLIM_TARGET_TAG",
},
cli.StringFlag{
Name: FlagTagFat,
Value: "",
Usage: "Custom tag for the fat image built from Dockerfile",
EnvVar: "DSLIM_TARGET_TAG_FAT",
},
cli.StringFlag{
Name: FlagImageOverrides,
Value: "",
Expand Down Expand Up @@ -683,7 +691,8 @@ func init() {

doShowContainerLogs := ctx.Bool(FlagShowContainerLogs)
doShowBuildLogs := ctx.Bool(FlagShowBuildLogs)
doTag := ctx.String("tag")
doTag := ctx.String(FlagTag)
doTagFat := ctx.String(FlagTagFat)

doImageOverrides := ctx.String(FlagImageOverrides)
overrides, err := getContainerOverrides(ctx)
Expand Down Expand Up @@ -761,6 +770,7 @@ func init() {
buildFromDockerfile,
imageRef,
doTag,
doTagFat,
doHTTPProbe,
httpProbeCmds,
httpProbeRetryCount,
Expand Down
10 changes: 8 additions & 2 deletions internal/app/master/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func OnBuild(
buildFromDockerfile string,
imageRef string,
customImageTag string,
fatImageTag string,
doHTTPProbe bool,
httpProbeCmds []config.HTTPProbeCmd,
httpProbeRetryCount int,
Expand Down Expand Up @@ -85,9 +86,14 @@ func OnBuild(

if buildFromDockerfile != "" {
fmt.Println("docker-slim[build]: state=building message='building basic image'")
//create a fat image name based on the user provided custom tag if it's available
//create a fat image name:
//* use the explicit fat image tag if provided
//* or create one based on the user provided (slim image) custom tag if it's available
//* otherwise auto-generate a name
var fatImageRepoNameTag string
if customImageTag != "" {
if fatImageTag != "" {
fatImageRepoNameTag = fatImageTag
} else if customImageTag != "" {
citParts := strings.Split(customImageTag, ":")
switch len(citParts) {
case 1:
Expand Down

0 comments on commit 3c2956b

Please sign in to comment.