Remove unnecessary tags from DockerHub after publishing a manifest

This commit is contained in:
Amir Zarrinkafsh 2019-11-09 10:57:39 +11:00 committed by Clément Michaud
parent e7816d7028
commit 175ac50888
2 changed files with 24 additions and 3 deletions

View File

@ -159,6 +159,22 @@ func deployManifest(docker *Docker, tag string, amd64tag string, arm32v7tag stri
if err != nil { if err != nil {
panic(err) panic(err)
} }
tags := []string{amd64tag, arm32v7tag, arm64v8tag}
for _, t := range tags {
username := os.Getenv("DOCKER_USERNAME")
password := os.Getenv("DOCKER_PASSWORD")
fmt.Println("===================================================")
fmt.Println("Docker removing tag for " + dockerImagePrefix + t + " on Dockerhub.")
fmt.Println("===================================================")
err = docker.CleanTag(username, password, t)
if err != nil {
panic(err)
}
}
} }
func publishDockerImage(arch string) { func publishDockerImage(arch string) {

View File

@ -4,7 +4,7 @@ package main
type Docker struct{} type Docker struct{}
// Build build a docker image // Build build a docker image
func (d *Docker) Build(tag string, dockerfile string, target string) error { func (d *Docker) Build(tag, dockerfile, target string) error {
return CommandWithStdout("docker", "build", "-t", tag, "-f", dockerfile, target).Run() return CommandWithStdout("docker", "build", "-t", tag, "-f", dockerfile, target).Run()
} }
@ -24,7 +24,7 @@ func (d *Docker) Push(tag string) error {
} }
// Manifest push a docker manifest to dockerhub. // Manifest push a docker manifest to dockerhub.
func (d *Docker) Manifest(tag string, amd64tag string, arm32v7tag string, arm64v8tag string) error { func (d *Docker) Manifest(tag, amd64tag, arm32v7tag, arm64v8tag string) error {
err := CommandWithStdout("docker", "manifest", "create", tag, amd64tag, arm32v7tag, arm64v8tag).Run() err := CommandWithStdout("docker", "manifest", "create", tag, amd64tag, arm32v7tag, arm64v8tag).Run()
if err != nil { if err != nil {
@ -44,4 +44,9 @@ func (d *Docker) Manifest(tag string, amd64tag string, arm32v7tag string, arm64v
} }
return CommandWithStdout("docker", "manifest", "push", "--purge", tag).Run() return CommandWithStdout("docker", "manifest", "push", "--purge", tag).Run()
} }
// CleanTag remove a tag from dockerhub.
func (d *Docker) CleanTag(username, password, tag string) error {
return CommandWithStdout("curl", "-u", username+":"+password, "-X", "DELETE", "https://cloud.docker.com/v2/repositories/"+DockerImageName+"/tags/"+tag+"/").Run()
}