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 repo: plugins/docker
tag: latest tag: latest
when: when:
branch: master branch: release/0.5
plugin: plugin:
name: Docker name: Docker

65
DOCS.md
View File

@ -1,5 +1,4 @@
Use the Docker plugin to build and push Docker images to a registry. Use the Docker plugin to build and push Docker images to a registry. The following parameters are used to configure this plugin:
The following parameters are used to configure this plugin:
* `registry` - authenticates to this registry * `registry` - authenticates to this registry
* `username` - authenticates with this username * `username` - authenticates with this username
@ -8,18 +7,13 @@ The following parameters are used to configure this plugin:
* `repo` - repository name for the image * `repo` - repository name for the image
* `tag` - repository tag for the image * `tag` - repository tag for the image
* `file` - dockerfile to be used, defaults to Dockerfile * `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 * `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 * `insecure` - enable insecure communication to this registry
* `mirror` - use a mirror registry instead of pulling images directly from the central Hub * `mirror` - use a mirror registry instead of pulling images directly from the central Hub
* `bip` - use for pass bridge ip * `bip` - use for pass bridge ip
* `dns` - set custom dns servers for the container * `dns` - set custom dns servers for the container
* `storage_driver` - use `aufs`, `devicemapper`, `btrfs` or `overlay` driver * `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/)) * `storage_path` - location of docker daemon storage on disk
* `destination` - absolute / relative destination path
* `tag` - cherry-pick tags to save (optional)
* `load` - restore image layers from the specified tar file
* `build_args` - [build arguments](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg) to pass to `docker build` * `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: The following is a sample Docker configuration in your .drone.yml file:
@ -36,19 +30,7 @@ publish:
insecure: false 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: Publish and image with multiple tags:
```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:
```yaml ```yaml
publish: publish:
@ -59,13 +41,11 @@ publish:
repo: foo/bar repo: foo/bar
tag: tag:
- latest - latest
- "1.0.1" - 1.0.1
- "1.0" - "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. Build an image with arguments:
It's also possible to pass build arguments to docker:
```yaml ```yaml
publish: publish:
@ -89,6 +69,7 @@ This is the preferred method when using the `overlay` or `aufs` storage drivers.
```yaml ```yaml
publish: publish:
docker: docker:
storage_path: /drone/docker
username: kevinbacon username: kevinbacon
password: pa55word password: pa55word
email: kevin.bacon@mail.com email: kevin.bacon@mail.com
@ -102,40 +83,6 @@ cache:
- /drone/docker - /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 ## Troubleshooting
For detailed output you can set the `DOCKER_LAUNCH_DEBUG` environment variable in your plugin configuration. This starts Docker with verbose logging enabled. 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_TAG=latest \
-e PLUGIN_REPO=octocat/hello-world \ -e PLUGIN_REPO=octocat/hello-world \
-e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \ -e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
-v $(pwd)/$(pwd) -v $(pwd)/$(pwd) \
-w $(pwd) -w $(pwd) \
--privileged \
plugins/docker --dry-run plugins/docker --dry-run
``` ```

22
main.go
View File

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

View File

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