2019-10-29 20:54:47 +00:00
|
|
|
package main
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
import (
|
|
|
|
"github.com/clems4ever/authelia/utils"
|
|
|
|
)
|
|
|
|
|
2019-10-29 20:54:47 +00:00
|
|
|
// Docker a docker object
|
|
|
|
type Docker struct{}
|
|
|
|
|
|
|
|
// Build build a docker image
|
2019-11-08 23:57:39 +00:00
|
|
|
func (d *Docker) Build(tag, dockerfile, target string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("docker", "build", "-t", tag, "-f", dockerfile, target).Run()
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tag tag a docker image.
|
|
|
|
func (d *Docker) Tag(image, tag string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("docker", "tag", image, tag).Run()
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Login login to the dockerhub registry.
|
|
|
|
func (d *Docker) Login(username, password string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("docker", "login", "-u", username, "-p", password).Run()
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push push a docker image to dockerhub.
|
|
|
|
func (d *Docker) Push(tag string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("docker", "push", tag).Run()
|
2019-10-29 20:54:47 +00:00
|
|
|
}
|
2019-11-07 00:59:24 +00:00
|
|
|
|
|
|
|
// Manifest push a docker manifest to dockerhub.
|
2019-11-08 23:57:39 +00:00
|
|
|
func (d *Docker) Manifest(tag, amd64tag, arm32v7tag, arm64v8tag string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
err := utils.CommandWithStdout("docker", "manifest", "create", tag, amd64tag, arm32v7tag, arm64v8tag).Run()
|
2019-11-07 00:59:24 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
err = utils.CommandWithStdout("docker", "manifest", "annotate", tag, arm32v7tag, "--os", "linux", "--arch", "arm").Run()
|
2019-11-07 00:59:24 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
err = utils.CommandWithStdout("docker", "manifest", "annotate", tag, arm64v8tag, "--os", "linux", "--arch", "arm64", "--variant", "v8").Run()
|
2019-11-07 00:59:24 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("docker", "manifest", "push", "--purge", tag).Run()
|
2019-11-08 23:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CleanTag remove a tag from dockerhub.
|
2019-11-09 18:42:36 +00:00
|
|
|
func (d *Docker) CleanTag(tag string) error {
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("bash", "-c", "curl -s -o /dev/null -u $DOCKER_USERNAME:$DOCKER_PASSWORD -X DELETE https://cloud.docker.com/v2/repositories/"+DockerImageName+"/tags/"+tag+"/").Run()
|
2019-11-09 18:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PublishReadme push README.md to dockerhub.
|
|
|
|
func (d *Docker) PublishReadme() error {
|
2019-11-02 14:32:58 +00:00
|
|
|
return utils.CommandWithStdout("bash", "-c", `jq -n --arg msg "$(<README.md)" '{"registry":"registry-1.docker.io","full_description": $msg }' | curl -s -o /dev/null -u $DOCKER_USERNAME:$DOCKER_PASSWORD -X "PATCH" -H "Content-Type: application/json" -d @- https://cloud.docker.com/v2/repositories/clems4ever/authelia/`).Run()
|
2019-11-08 23:57:39 +00:00
|
|
|
}
|