mirror of
https://github.com/drone-plugins/drone-docker.git
synced 2026-06-04 18:24:24 +08:00
Use random string as temporary tag
This commit is contained in:
@@ -45,6 +45,7 @@ type (
|
||||
Build struct {
|
||||
Remote string // Git remote URL
|
||||
Name string // Docker build using default named tag
|
||||
TempTag string // Temporary tag used during docker build
|
||||
Dockerfile string // Docker build Dockerfile
|
||||
Context string // Docker build context
|
||||
Tags []string // Docker build tags
|
||||
@@ -195,11 +196,10 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
}
|
||||
|
||||
buildName := getUniqueBuildName(p.Build.Repo, p.Build.Name)
|
||||
cmds = append(cmds, commandBuild(p.Build, buildName)) // docker build
|
||||
cmds = append(cmds, commandBuild(p.Build)) // docker build
|
||||
|
||||
for _, tag := range p.Build.Tags {
|
||||
cmds = append(cmds, commandTag(p.Build, tag, buildName)) // docker tag
|
||||
cmds = append(cmds, commandTag(p.Build, tag)) // docker tag
|
||||
|
||||
if !p.Dryrun {
|
||||
cmds = append(cmds, commandPush(p.Build, tag)) // docker push
|
||||
@@ -225,12 +225,12 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
|
||||
// output the adaptive card
|
||||
if err := p.writeCard(buildName); err != nil {
|
||||
if err := p.writeCard(); err != nil {
|
||||
fmt.Printf("Could not create adaptive card. %s\n", err)
|
||||
}
|
||||
|
||||
if p.ArtifactFile != "" {
|
||||
if digest, err := getDigest(buildName); err == nil {
|
||||
if digest, err := getDigest(p.Build.TempTag); err == nil {
|
||||
if err = drone.WritePluginArtifactFile(p.Daemon.RegistryType, p.ArtifactFile, p.Daemon.Registry, p.Build.Repo, digest, p.Build.Tags); err != nil {
|
||||
fmt.Printf("failed to write plugin artifact file at path: %s with error: %s\n", p.ArtifactFile, err)
|
||||
}
|
||||
@@ -244,8 +244,8 @@ func (p Plugin) Exec() error {
|
||||
// clear the slice
|
||||
cmds = nil
|
||||
|
||||
cmds = append(cmds, commandRmi(buildName)) // docker rmi
|
||||
cmds = append(cmds, commandPrune()) // docker system prune -f
|
||||
cmds = append(cmds, commandRmi(p.Build.TempTag)) // docker rmi
|
||||
cmds = append(cmds, commandPrune()) // docker system prune -f
|
||||
|
||||
for _, cmd := range cmds {
|
||||
cmd.Stdout = os.Stdout
|
||||
@@ -300,12 +300,12 @@ func commandInfo() *exec.Cmd {
|
||||
}
|
||||
|
||||
// helper function to create the docker build command.
|
||||
func commandBuild(build Build, buildName string) *exec.Cmd {
|
||||
func commandBuild(build Build) *exec.Cmd {
|
||||
args := []string{
|
||||
"build",
|
||||
"--rm=true",
|
||||
"-f", build.Dockerfile,
|
||||
"-t", buildName,
|
||||
"-t", build.TempTag,
|
||||
}
|
||||
|
||||
args = append(args, build.Context)
|
||||
@@ -462,9 +462,9 @@ func hasProxyBuildArg(build *Build, key string) bool {
|
||||
}
|
||||
|
||||
// helper function to create the docker tag command.
|
||||
func commandTag(build Build, tag, buildName string) *exec.Cmd {
|
||||
func commandTag(build Build, tag string) *exec.Cmd {
|
||||
var (
|
||||
source = buildName
|
||||
source = build.TempTag
|
||||
target = fmt.Sprintf("%s:%s", build.Repo, tag)
|
||||
)
|
||||
return exec.Command(
|
||||
|
||||
Reference in New Issue
Block a user