0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-22 10:10:39 +00:00

Merge pull request #23 from drone-plugins/buildargs

add support for build-args
This commit is contained in:
Nathan LaFreniere 2015-12-24 07:04:10 -08:00
commit 445933bc6e
2 changed files with 37 additions and 18 deletions

14
DOCS.md
View File

@ -16,6 +16,7 @@ The following parameters are used to configure this plugin:
* `destination` - absolute / relative destination path * `destination` - absolute / relative destination path
* `tag` - cherry-pick tags to save (optional) * `tag` - cherry-pick tags to save (optional)
* `load` - restore image layers from the specified tar file * `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`
The following is a sample Docker configuration in your .drone.yml file: The following is a sample Docker configuration in your .drone.yml file:
@ -59,6 +60,19 @@ publish:
``` ```
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. 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:
```yaml
publish:
docker:
username: kevinbacon
password: pa55word
email: kevin.bacon@mail.com
repo: foo/bar
build_args:
- HTTP_PROXY=http://yourproxy.com
```
## Layer Caching ## Layer Caching

41
main.go
View File

@ -20,23 +20,24 @@ type Save struct {
} }
type Docker struct { type Docker struct {
Storage string `json:"storage_driver"` Storage string `json:"storage_driver"`
Registry string `json:"registry"` Registry string `json:"registry"`
Mirror string `json:"mirror"` Mirror string `json:"mirror"`
Insecure bool `json:"insecure"` Insecure bool `json:"insecure"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
Email string `json:"email"` Email string `json:"email"`
Auth string `json:"auth"` Auth string `json:"auth"`
Repo string `json:"repo"` Repo string `json:"repo"`
ForceTag bool `json:"force_tag"` ForceTag bool `json:"force_tag"`
Tag StrSlice `json:"tag"` Tag StrSlice `json:"tag"`
File string `json:"file"` File string `json:"file"`
Context string `json:"context"` Context string `json:"context"`
Bip string `json:"bip"` Bip string `json:"bip"`
Dns []string `json:"dns"` Dns []string `json:"dns"`
Load string `json:"load"` Load string `json:"load"`
Save Save `json:"save"` Save Save `json:"save"`
BuildArgs []string `json:"build_args"`
} }
func main() { func main() {
@ -175,7 +176,11 @@ func main() {
// Build the container // Build the container
name := fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag.Slice()[0]) name := fmt.Sprintf("%s:%s", vargs.Repo, vargs.Tag.Slice()[0])
cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-f", vargs.File, "-t", name, vargs.Context) cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-f", vargs.File, "-t", name)
for _, value := range vargs.BuildArgs {
cmd.Args = append(cmd.Args, "--build-arg", value)
}
cmd.Args = append(cmd.Args, vargs.Context)
cmd.Dir = workspace.Path cmd.Dir = workspace.Path
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr