diff --git a/docs/packages.md b/docs/packages.md index a4330ebbd..8f3231afd 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -151,3 +151,27 @@ linuxkit pkg build -org=wombat -disable-content-trust -hash=foo push and this will create `wombat/:foo-` and `wombat/:foo` for use in your YAML files. + +### Proxies + +If you are building packages from behind a proxy, `linuxkit pkg build` respects +the following environment variables, and will set them as `--build-arg` to +`docker build` when building a package. + +* `http_proxy` / `HTTP_PROXY` +* `https_proxy` / `HTTPS_PROXY` +* `ftp_proxy` / `FTP_PROXY` +* `no_proxy` / `NO_PROXY` +* `all_proxy` / `ALL_PROXY` + +Note that the first four of these are the standard built-in `build-arg` options available +for `docker build`; see the [docker build documentation](https://docs.docker.com/v17.09/engine/reference/builder/#arg). +The last, `all_proxy`, is a standard var used for socks proxying. Since it is not built into `docker build`, +if you want to use it, you will need to add the following line to the dockerfile: + +```dockerfile +ARG all_proxy +``` + +Linuxkit does not judge between lower-cased or upper-cased variants of these options, e.g. `http_proxy` vs `HTTP_PROXY`, +as `docker build` does not either. It just passes them through "as-is". diff --git a/src/cmd/linuxkit/pkglib/docker.go b/src/cmd/linuxkit/pkglib/docker.go index b499fd7ec..045359623 100644 --- a/src/cmd/linuxkit/pkglib/docker.go +++ b/src/cmd/linuxkit/pkglib/docker.go @@ -41,13 +41,19 @@ func isExecErrNotFound(err error) bool { return eerr.Err == exec.ErrNotFound } +// these are the standard 4 build-args supported by `docker build` +// plus the all_proxy/ALL_PROXY which is a socks standard one var proxyEnvVars = []string{ "http_proxy", "https_proxy", "no_proxy", + "ftp_proxy", + "all_proxy", "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", + "FTP_PROXY", + "ALL_PROXY", } func (dr dockerRunner) command(args ...string) error { @@ -72,7 +78,12 @@ func (dr dockerRunner) command(args ...string) error { []string{"--build-arg", fmt.Sprintf("%s=%s", proxyVarName, value)}...) } } - cmd.Args = append(append(cmd.Args[:2], buildArgs...), cmd.Args[2:]...) + // cannot use usual append(append( because it overwrites part of it + newArgs := make([]string, len(cmd.Args)+len(buildArgs)) + copy(newArgs[:2], cmd.Args[:2]) + copy(newArgs[2:], buildArgs) + copy(newArgs[2+len(buildArgs):], cmd.Args[2:]) + cmd.Args = newArgs if dr.ctx != nil { stdin, err := cmd.StdinPipe()