update plugin for 0.5 release

This commit is contained in:
Brad Rydzewski 2016-05-03 16:34:08 -07:00
parent 5825a3d797
commit 7a1e6b2766
6 changed files with 20 additions and 86 deletions

View File

@ -1 +1 @@
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.G6Nny2XGFBtLfgrL0cPtC35a5yZkANTXmCQNlV4d91wNW1FSZWdHhTC9uwn5OaGq8TaeSlg3SLdt02ypmx38WenTc1zFbSjElfVWm8nQJP689ggy5EL0vTIXczbzwKk3Y7KVFAH0g4Xi_Lr6SdJJTIZREACkKcVDWVod44e32bFF7iF-u9vhIQ0GpB76d-WFJgSzBlh4ojBrCA_un2ItjJ3rVPfJi00VbTkh8fiovOsiTWg1MhgcTDyh78tqlD-f9fdeP4W5a88-v7l6H45ttrmhfPFyT46Xju7uhtdLX5MwtqZ_augSelw8qkXmUVM_yNqBDA04HGJBSGxT8rKWKg.QuQsEmFZNiVkEwAJ.XuYkMZlmfeQRaHFpRCg0Y6Ynkj7bxHyPLQ1Okmnk-F7HGogeaS4zxrbc9GQK_EKe5mEaDE_NkS76tAABChSnsXONmTezeRakyatc00PZYykARf2dwodwENI9rrHqZFJqnC0l5moFQyC9iFICeLP9RVdQ9DZhc0t-GU2hCK_CglZ09Ag2eHtvi8x75483_x_ZtVkpF1vsMXOxUMCDO_wCVcWy6o-Fkx7gPBR6AR56qD-MRBGeNn975IQ3bV1fxRTYnvRC3tX6xslZoQ6M-lIZTWFTTvZkEWYe3FSwD2HYUbm7rI4iivoNsFzmsMl38SqSQ_s_MyLcju9CcJsVmXokixKk-TcVCoDDG62gUQWTXEG4jz2sMxfwU4H2Fgg7AlFh2_At3gSVr2GXdgMtB1TYr0e1KQIVW_3DbNtYi6_neHg.k_x3SoJ2TUSAx_awKAYQWw
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.FfwnPUF8FCShz3ATEQvcWR2tTmdU8O-KvxK5APYiusOEP6y9CyRbkXsjIYGKTCcO3ZsfKyJwhZ_ljP0M1WRqXo90OF53-o-gJs359Zpa-3buxKrsSX_8IUvlA62y15uMS0KLuiS-h-78k8CannuSl2afVsHtwYOT0sVx20dYk3-E0Qw_P-E3jUmUTNDMJbG6FjB4UM2Q7pPh8jHx-lN9nkI6tz9M3gchZpfzPVSgm2EJlZ66iobvuLgLmpSA6VS4a9zhijgry5sb_2KW0IGzXsYIW9mYPk3uXGzZyT__Lcmck0nf1yed5ATzaGyoI4EmogLu5sVNzq-xDbBDzyuDiQ.H5viJYEJ76XkzfFu.JU6vKDHJFye0CEFqLhcQu9ZmK0yBJF-WvpZuk-wH-lnLS8DlygL4arAHT_1rTAdWdHfM5dNbx5lt0EUJ_-0ibWsilSEOtBmjP61Ryc-1HNaqeeXFXzo8dU6JKGwc0AanZiuL1N8QP4sNgMMGJoloIhzfVJz8VDw1uQ7NtmpUY9_vFJBZGeYTbhkpEmijTdTcM9HuXkYqQqoueILWRhK6YlxyU0SUrLYAAXqlX_D42zoI_kP42qWQYTCKz2QF0TU.tfBboktLMAa9E1r1T-m2Rg

View File

@ -20,7 +20,7 @@ publish:
repo: plugins/docker
tag: latest
when:
branch: master
branch: release/0.5
plugin:
name: Docker

65
DOCS.md
View File

@ -1,5 +1,4 @@
Use the Docker plugin to build and push Docker images to a registry.
The following parameters are used to configure this plugin:
Use the Docker plugin to build and push Docker images to a registry. The following parameters are used to configure this plugin:
* `registry` - authenticates to this registry
* `username` - authenticates with this username
@ -8,18 +7,13 @@ The following parameters are used to configure this plugin:
* `repo` - repository name for the image
* `tag` - repository tag for the image
* `file` - dockerfile to be used, defaults to Dockerfile
* `auth` - auth token for the registry
* `context` - the context path to use, defaults to root of the git repo
* `force_tag` - replace existing matched image tags
* `insecure` - enable insecure communication to this registry
* `mirror` - use a mirror registry instead of pulling images directly from the central Hub
* `bip` - use for pass bridge ip
* `dns` - set custom dns servers for the container
* `storage_driver` - use `aufs`, `devicemapper`, `btrfs` or `overlay` driver
* `save` - save image layers to the specified tar file (see [docker save](https://docs.docker.com/engine/reference/commandline/save/))
* `destination` - absolute / relative destination path
* `tag` - cherry-pick tags to save (optional)
* `load` - restore image layers from the specified tar file
* `storage_path` - location of docker daemon storage on disk
* `build_args` - [build arguments](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg) to pass to `docker build`
The following is a sample Docker configuration in your .drone.yml file:
@ -36,19 +30,7 @@ publish:
insecure: false
```
You may want to dynamically tag your image. Use the `$$BRANCH`, `$$COMMIT` and `$$BUILD_NUMBER` variables to tag your image with the branch, commit sha or build number:
```yaml
publish:
docker:
username: kevinbacon
password: pa55word
email: kevin.bacon@mail.com
repo: foo/bar
tag: $$BRANCH
```
Or you may prefer to build an image with multiple tags:
Publish and image with multiple tags:
```yaml
publish:
@ -59,13 +41,11 @@ publish:
repo: foo/bar
tag:
- latest
- "1.0.1"
- 1.0.1
- "1.0"
```
Note that in the above example we quote the version numbers. If the yaml parser interprets the value as a number it will cause a parsing error.
It's also possible to pass build arguments to docker:
Build an image with arguments:
```yaml
publish:
@ -89,6 +69,7 @@ This is the preferred method when using the `overlay` or `aufs` storage drivers.
```yaml
publish:
docker:
storage_path: /drone/docker
username: kevinbacon
password: pa55word
email: kevin.bacon@mail.com
@ -102,40 +83,6 @@ cache:
- /drone/docker
```
NOTE: This probably won't work correctly with the `btrfs` driver, and it will be very inefficient with the `devicemapper` driver. Please make sure to use the `overlay` or `aufs` storage driver with this method.
### Layer Caching
The below example combines Drone's caching feature and Docker's `save` and `load` capabilities to cache and restore image layers between builds:
```yaml
publish:
docker:
username: kevinbacon
password: pa55word
email: kevin.bacon@mail.com
repo: foo/bar
tag:
- latest
- "1.0.1"
load: docker/image.tar
save:
destination: docker/image.tar
tag: latest
cache:
mount:
- docker/image.tar
```
You might also want to create a `.dockerignore` file in your repo to exclude `image.tar` from Docker build context:
```
docker/*
```
In some cases caching will greatly improve build performance, however, the tradeoff is that caching Docker image layers may consume very large amounts of disk space.
## Troubleshooting
For detailed output you can set the `DOCKER_LAUNCH_DEBUG` environment variable in your plugin configuration. This starts Docker with verbose logging enabled.

View File

@ -37,7 +37,8 @@ docker run --rm \
-e PLUGIN_TAG=latest \
-e PLUGIN_REPO=octocat/hello-world \
-e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
-v $(pwd)/$(pwd)
-w $(pwd)
-v $(pwd)/$(pwd) \
-w $(pwd) \
--privileged \
plugins/docker --dry-run
```

22
main.go
View File

@ -17,8 +17,8 @@ const defaultRegistry = "https://index.docker.io/v1/"
func main() {
app := cli.NewApp()
app.Name = "my plugin"
app.Usage = "my plugin usage"
app.Name = "docker plugin"
app.Usage = "docker plugin"
app.Action = run
app.Version = version
app.Flags = []cli.Flag{
@ -33,6 +33,7 @@ func main() {
Name: "commit.sha",
Usage: "git commit sha",
EnvVar: "DRONE_COMMIT_SHA",
Value: "00000000",
},
// daemon parameters
@ -47,7 +48,7 @@ func main() {
EnvVar: "PLUGIN_STORAGE_DRIVER",
},
cli.StringFlag{
Name: "daemon.storage-driver",
Name: "daemon.storage-path",
Usage: "docker daemon storage path",
Value: "/tmp/docker",
EnvVar: "PLUGIN_STORAGE_PATH",
@ -67,11 +68,6 @@ func main() {
Usage: "docker daemon allows insecure registries",
EnvVar: "PLUGIN_INSECURE",
},
cli.BoolFlag{
Name: "daemon.debug",
Usage: "docker daemon executes in debug mode",
EnvVar: "PLUGIN_DEBUG",
},
cli.BoolFlag{
Name: "daemon.debug",
Usage: "docker daemon executes in debug mode",
@ -103,15 +99,10 @@ func main() {
Value: &cli.StringSlice{"latest"},
EnvVar: "PLUGIN_TAG,PLUGIN_TAGS",
},
cli.BoolFlag{
Name: "force",
Usage: "build tags are forced",
EnvVar: "PLUGIN_FORCE",
},
cli.StringSliceFlag{
Name: "args",
Usage: "build args",
EnvVar: "PLUGIN_ARGS",
EnvVar: "PLUGIN_BUILD_ARGS",
},
cli.StringFlag{
Name: "repo",
@ -162,7 +153,6 @@ func run(c *cli.Context) {
Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"),
Repo: c.String("repo"),
Force: c.Bool("force"),
},
Daemon: Daemon{
Registry: c.String("docker.registry"),
@ -171,7 +161,7 @@ func run(c *cli.Context) {
StoragePath: c.String("daemon.storage-path"),
Insecure: c.Bool("daemon.insecure"),
Disabled: c.Bool("daemon.off"),
Debug: c.Bool("deamon.debug"),
Debug: c.Bool("daemon.debug"),
Bip: c.String("daemon.bip"),
DNS: c.StringSlice("daemon.dns"),
},

View File

@ -39,7 +39,6 @@ type (
Tags []string // Docker build tags
Args []string // Docker build args
Repo string // Docker build repository
Force bool // Docker build forces image tag creation
}
// Plugin defines the Docker plugin parameters.
@ -160,14 +159,11 @@ func commandBuild(build Build) *exec.Cmd {
// helper function to create the docker tag command.
func commandTag(build Build, tag string) *exec.Cmd {
var (
force = fmt.Sprintf("--force=%v", build.Force)
from = build.Name
to = fmt.Sprintf("%s:%s", build.Repo, tag)
source = build.Name
target = fmt.Sprintf("%s:%s", build.Repo, tag)
)
return exec.Command(
"/usr/bin/docker", "tag",
force,
from, to,
"/usr/bin/docker", "tag", source, target,
)
}