mirror of
https://github.com/thegeeklab/drone-docker-buildx.git
synced 2024-11-05 04:20:41 +00:00
Merge remote-tracking branch 'origin'
This commit is contained in:
commit
7d9dd5cac7
@ -7,7 +7,7 @@
|
||||
|
||||
Drone plugin can be used to build and publish Docker images to a container
|
||||
registry. For the usage information and a listing of the available options
|
||||
please take a look at [the docs](DOCS.md).
|
||||
please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-docker/).
|
||||
|
||||
## Build
|
||||
|
||||
|
20
main.go
20
main.go
@ -118,6 +118,16 @@ func main() {
|
||||
Usage: "squash the layers at build time",
|
||||
EnvVar: "PLUGIN_SQUASH",
|
||||
},
|
||||
cli.BoolTFlag{
|
||||
Name: "pull-image",
|
||||
Usage: "force pull base image at build time",
|
||||
EnvVar: "PLUGIN_PULL_IMAGE",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "compress",
|
||||
Usage: "compress the build context using gzip",
|
||||
EnvVar: "PLUGIN_COMPRESS",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo",
|
||||
Usage: "docker repository",
|
||||
@ -127,22 +137,22 @@ func main() {
|
||||
Name: "docker.registry",
|
||||
Usage: "docker registry",
|
||||
Value: defaultRegistry,
|
||||
EnvVar: "DOCKER_REGISTRY,PLUGIN_REGISTRY",
|
||||
EnvVar: "PLUGIN_REGISTRY,DOCKER_REGISTRY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.username",
|
||||
Usage: "docker username",
|
||||
EnvVar: "DOCKER_USERNAME,PLUGIN_USERNAME",
|
||||
EnvVar: "PLUGIN_USERNAME,DOCKER_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.password",
|
||||
Usage: "docker password",
|
||||
EnvVar: "DOCKER_PASSWORD,PLUGIN_PASSWORD",
|
||||
EnvVar: "PLUGIN_PASSWORD,DOCKER_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.email",
|
||||
Usage: "docker email",
|
||||
EnvVar: "DOCKER_EMAIL,PLUGIN_EMAIL",
|
||||
EnvVar: "PLUGIN_EMAIL,DOCKER_EMAIL",
|
||||
},
|
||||
}
|
||||
|
||||
@ -167,6 +177,8 @@ func run(c *cli.Context) error {
|
||||
Tags: c.StringSlice("tags"),
|
||||
Args: c.StringSlice("args"),
|
||||
Squash: c.Bool("squash"),
|
||||
Pull: c.BoolT("pull-image"),
|
||||
Compress: c.Bool("compress"),
|
||||
Repo: c.String("repo"),
|
||||
},
|
||||
Daemon: Daemon{
|
||||
|
32
plugin.go
32
plugin.go
@ -47,6 +47,8 @@ type (
|
||||
Tags []string // Docker build tags
|
||||
Args []string // Docker build args
|
||||
Squash bool // Docker build squash
|
||||
Pull bool // Docker build pull
|
||||
Compress bool // Docker build compress
|
||||
Repo string // Docker build repository
|
||||
}
|
||||
|
||||
@ -61,17 +63,6 @@ type (
|
||||
|
||||
// Exec executes the plugin step
|
||||
func (p Plugin) Exec() error {
|
||||
|
||||
// TODO execute code remove dangling images
|
||||
// this is problematic because we are running docker in scratch which does
|
||||
// not have bash, so we need to hack something together
|
||||
// docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
|
||||
|
||||
/*
|
||||
cmd = exec.Command("docker", "images", "-q", "-f", "dangling=true")
|
||||
cmd = exec.Command("docker", append([]string{"rmi"}, images...)...)
|
||||
*/
|
||||
|
||||
// start the Docker daemon server
|
||||
if !p.Daemon.Disabled {
|
||||
cmd := commandDaemon(p.Daemon)
|
||||
@ -121,6 +112,7 @@ func (p Plugin) Exec() error {
|
||||
var cmds []*exec.Cmd
|
||||
cmds = append(cmds, commandVersion()) // docker version
|
||||
cmds = append(cmds, commandInfo()) // docker info
|
||||
cmds = append(cmds, commandDockerPrune()) // cleanup docker
|
||||
cmds = append(cmds, commandBuild(p.Build)) // docker build
|
||||
|
||||
for _, tag := range p.Build.Tags {
|
||||
@ -147,6 +139,7 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
|
||||
const dockerExe = "/usr/local/bin/docker"
|
||||
const dockerdExe = "/usr/local/bin/dockerd"
|
||||
|
||||
// helper function to create the docker login command.
|
||||
func commandLogin(login Login) *exec.Cmd {
|
||||
@ -183,9 +176,8 @@ func commandInfo() *exec.Cmd {
|
||||
|
||||
// helper function to create the docker build command.
|
||||
func commandBuild(build Build) *exec.Cmd {
|
||||
args := []string {
|
||||
args := []string{
|
||||
"build",
|
||||
"--pull=true",
|
||||
"--rm=true",
|
||||
"-f", build.Dockerfile,
|
||||
"-t", build.Name,
|
||||
@ -195,6 +187,12 @@ func commandBuild(build Build) *exec.Cmd {
|
||||
if build.Squash {
|
||||
args = append(args, "--squash")
|
||||
}
|
||||
if build.Compress {
|
||||
args = append(args, "--compress")
|
||||
}
|
||||
if build.Pull {
|
||||
args = append(args, "--pull=true")
|
||||
}
|
||||
for _, arg := range build.Args {
|
||||
args = append(args, "--build-arg", arg)
|
||||
}
|
||||
@ -264,7 +262,7 @@ func commandPush(build Build, tag string) *exec.Cmd {
|
||||
|
||||
// helper function to create the docker daemon command.
|
||||
func commandDaemon(daemon Daemon) *exec.Cmd {
|
||||
args := []string{"daemon", "-g", daemon.StoragePath}
|
||||
args := []string{"-g", daemon.StoragePath}
|
||||
|
||||
if daemon.StorageDriver != "" {
|
||||
args = append(args, "-s", daemon.StorageDriver)
|
||||
@ -290,7 +288,11 @@ func commandDaemon(daemon Daemon) *exec.Cmd {
|
||||
if daemon.Experimental {
|
||||
args = append(args, "--experimental")
|
||||
}
|
||||
return exec.Command(dockerExe, args...)
|
||||
return exec.Command(dockerdExe, args...)
|
||||
}
|
||||
|
||||
func commandDockerPrune() *exec.Cmd {
|
||||
return exec.Command(dockerExe, "system", "prune", "-f")
|
||||
}
|
||||
|
||||
// trace writes each command to stdout with the command wrapped in an xml
|
||||
|
Loading…
Reference in New Issue
Block a user