Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 2e0e0dd

Browse files
authored
Possible fix for #28 (#30)
1 parent a6cc96f commit 2e0e0dd

File tree

2 files changed

+9
-65
lines changed

2 files changed

+9
-65
lines changed

plugin/docker.go

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ func commandBuildx() *exec.Cmd {
6161
}
6262

6363
// helper function to create the docker build command.
64-
func commandBuild(build Build) *exec.Cmd {
64+
func commandBuild(build Build, dryrun bool) *exec.Cmd {
6565
args := []string{
6666
"buildx",
6767
"build",
6868
"--rm=true",
6969
"-f", build.Dockerfile,
70-
"-t", build.Name,
7170
}
7271

7372
defaultBuildArgs := []string{
7473
fmt.Sprintf("DOCKER_IMAGE_CREATED=%s", time.Now().Format(time.RFC3339)),
7574
}
7675

7776
args = append(args, build.Context)
77+
if ! dryrun {
78+
args = append(args, "--push")
79+
}
7880
if build.Squash {
7981
args = append(args, "--squash")
8082
}
@@ -106,16 +108,14 @@ func commandBuild(build Build) *exec.Cmd {
106108
args = append(args, "--quiet")
107109
}
108110

109-
if len(build.Platforms.Value()) > 1 {
110-
args = append(args, "--push")
111-
} else {
112-
args = append(args, "--load")
113-
}
114-
115111
if len(build.Platforms.Value()) > 0 {
116112
args = append(args, "--platform", strings.Join(build.Platforms.Value()[:], ","))
117113
}
118114

115+
for _, arg := range build.Tags.Value() {
116+
args = append(args, "-t", fmt.Sprintf("%s:%s", build.Repo, arg))
117+
}
118+
119119
return exec.Command(dockerExe, args...)
120120
}
121121

@@ -162,23 +162,6 @@ func hasProxyBuildArg(build *Build, key string) bool {
162162
return false
163163
}
164164

165-
// helper function to create the docker tag command.
166-
func commandTag(build Build, tag string) *exec.Cmd {
167-
var (
168-
source = build.Name
169-
target = fmt.Sprintf("%s:%s", build.Repo, tag)
170-
)
171-
return exec.Command(
172-
dockerExe, "tag", source, target,
173-
)
174-
}
175-
176-
// helper function to create the docker push command.
177-
func commandPush(build Build, tag string) *exec.Cmd {
178-
target := fmt.Sprintf("%s:%s", build.Repo, tag)
179-
return exec.Command(dockerExe, "push", target)
180-
}
181-
182165
// helper function to create the docker daemon command.
183166
func commandDaemon(daemon Daemon) *exec.Cmd {
184167
args := []string{
@@ -216,24 +199,6 @@ func commandDaemon(daemon Daemon) *exec.Cmd {
216199
return exec.Command(dockerdExe, args...)
217200
}
218201

219-
// helper to check if args match "docker prune"
220-
func isCommandPrune(args []string) bool {
221-
return len(args) > 3 && args[2] == "prune"
222-
}
223-
224-
func commandPrune() *exec.Cmd {
225-
return exec.Command(dockerExe, "system", "prune", "-f")
226-
}
227-
228-
// helper to check if args match "docker rmi"
229-
func isCommandRmi(args []string) bool {
230-
return len(args) > 2 && args[1] == "rmi"
231-
}
232-
233-
func commandRmi(tag string) *exec.Cmd {
234-
return exec.Command(dockerExe, "rmi", tag)
235-
}
236-
237202
// trace writes each command to stdout with the command wrapped in an xml
238203
// tag so that it can be extracted and displayed in the logs.
239204
func trace(cmd *exec.Cmd) {

plugin/impl.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ func (p *Plugin) Validate() error {
8383
p.settings.Build.Ref = p.pipeline.Commit.Ref
8484
p.settings.Daemon.Registry = p.settings.Login.Registry
8585

86-
if len(p.settings.Build.Platforms.Value()) > 1 && p.settings.Dryrun {
87-
return fmt.Errorf("dryrun is not supported on multi-platform builds")
88-
}
89-
9086
if p.settings.Build.TagsAuto {
9187
// return true if tag event or default branch
9288
if UseDefaultTag(
@@ -177,20 +173,7 @@ func (p *Plugin) Execute() error {
177173
cmds = append(cmds, commandPull(img))
178174
}
179175

180-
cmds = append(cmds, commandBuild(p.settings.Build)) // docker build
181-
182-
for _, tag := range p.settings.Build.Tags.Value() {
183-
cmds = append(cmds, commandTag(p.settings.Build, tag)) // docker tag
184-
185-
if !p.settings.Dryrun {
186-
cmds = append(cmds, commandPush(p.settings.Build, tag)) // docker push
187-
}
188-
}
189-
190-
if p.settings.Cleanup {
191-
cmds = append(cmds, commandRmi(p.settings.Build.Name)) // docker rmi
192-
cmds = append(cmds, commandPrune()) // docker system prune -f
193-
}
176+
cmds = append(cmds, commandBuild(p.settings.Build, p.settings.Dryrun)) // docker build
194177

195178
// execute all commands in batch mode.
196179
for _, cmd := range cmds {
@@ -201,10 +184,6 @@ func (p *Plugin) Execute() error {
201184
err := cmd.Run()
202185
if err != nil && isCommandPull(cmd.Args) {
203186
fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2])
204-
} else if err != nil && isCommandPrune(cmd.Args) {
205-
fmt.Printf("Could not prune system containers. Ignoring...\n")
206-
} else if err != nil && isCommandRmi(cmd.Args) {
207-
fmt.Printf("Could not remove image %s. Ignoring...\n", cmd.Args[2])
208187
} else if err != nil {
209188
return err
210189
}

0 commit comments

Comments
 (0)