Skip to content

Commit

Permalink
Create image tags at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxity committed Apr 24, 2019
1 parent ebce953 commit 94de5c3
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ func (p Plugin) Exec() error {

cmds = append(cmds, commandBuild(p.Build)) // docker build

for _, tag := range p.Build.Tags {
cmds = append(cmds, commandTag(p.Build, tag)) // docker tag

if p.Dryrun == false {
if p.Dryrun == false {
for _, tag := range p.Build.Tags {
cmds = append(cmds, commandPush(p.Build, tag)) // docker push
}
}
Expand Down Expand Up @@ -205,10 +203,14 @@ func commandBuild(build Build) *exec.Cmd {
"build",
"--rm=true",
"-f", build.Dockerfile,
"-t", build.Name,
}

for _, tag := range build.Tags {
args = append(args, "-t", tag)
}

args = append(args, build.Context)

if build.Squash {
args = append(args, "--squash")
}
Expand Down Expand Up @@ -301,17 +303,6 @@ func hasProxyBuildArg(build *Build, key string) bool {
return false
}

// helper function to create the docker tag command.
func commandTag(build Build, tag string) *exec.Cmd {
var (
source = build.Name
target = fmt.Sprintf("%s:%s", build.Repo, tag)
)
return exec.Command(
dockerExe, "tag", source, target,
)
}

// helper function to create the docker push command.
func commandPush(build Build, tag string) *exec.Cmd {
target := fmt.Sprintf("%s:%s", build.Repo, tag)
Expand Down

0 comments on commit 94de5c3

Please sign in to comment.