Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable support for proxies needed in the Docker environment #982

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/rbe_configs_gen/rbe_configs_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
enableMonitoring = flag.Bool("enable_monitoring", false, "(Optional) Enables reporting reporting results to Google Cloud Monitoring. Defaults to false.")
monitoringProjectID = flag.String("monitoring_project_id", "", "GCP Project ID where monitoring results will be reported. Required if --enable_monitoring is true.")
monitoringDockerImage = flag.String("monitoring_docker_image", "", "Name of the toolchain docker image to be reported as a string label to monitoring. Required if --enable_monitoring is true.")
httpsProxy = flag.String("https_proxy", "", "The proxy argument to send to Docker.")
)

// printFlag prints flag values with the intent of allowing easy copy paste of flags to rerun this
Expand Down Expand Up @@ -110,6 +111,9 @@ func printFlags() {
if len(*monitoringDockerImage) != 0 {
log.Printf("--monitoring_docker_image=%q \\", *monitoringDockerImage)
}
if len(*httpsProxy) != 0 {
log.Printf("--https_proxy=%q \\", *httpsProxy)
}
}

func initMonitoringClient(ctx context.Context) (*monitoring.Client, error) {
Expand Down Expand Up @@ -171,6 +175,7 @@ func main() {
JavaUseLocalRuntime: *javaUseLocalRuntime,
TempWorkDir: *tempWorkDir,
Cleanup: *cleanup,
HttpsProxy: *httpsProxy,
}

result := true
Expand Down
2 changes: 2 additions & 0 deletions pkg/rbeconfigsgen/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ type Options struct {
// Cleanup determines whether the running container & intermediate files will be deleted once
// config generation is done. Setting it to false is useful for debugging intermediate state.
Cleanup bool
// HttpsProxy set the proxy to pass to the Docker daemon
HttpsProxy string
}

// DefaultOptions are some option values that are populated as default values for certain fields
Expand Down
10 changes: 8 additions & 2 deletions pkg/rbeconfigsgen/rbeconfigsgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ type dockerRunner struct {
// Parameters that affect how commands are executed inside the running toolchain container.
// These parameters can be changed between calls to the execCmd function.

// httpsProxy is the proxy to use by commands inside the container.
httpsProxy string
// workdir is the working directory to use to run commands inside the container.
workdir string
// env is the environment variables to set when executing commands specified in the given order
Expand Down Expand Up @@ -251,14 +253,15 @@ func BazeliskDownloadInfo(os string) (string, string, error) {
// newDockerRunner creates a new running container of the given containerImage. stopContainer
// determines if the cleanup function on the dockerRunner will stop the running container when
// called.
func newDockerRunner(containerImage string, stopContainer bool) (*dockerRunner, error) {
func newDockerRunner(containerImage string, stopContainer bool, httpsProxy string) (*dockerRunner, error) {
if containerImage == "" {
return nil, fmt.Errorf("container image was not specified")
}
d := &dockerRunner{
containerImage: containerImage,
stopContainer: stopContainer,
dockerPath: "docker",
httpsProxy: httpsProxy,
}
if _, err := runCmd(d.dockerPath, "pull", d.containerImage); err != nil {
return nil, fmt.Errorf("docker was unable to pull the toolchain container image %q: %w", d.containerImage, err)
Expand Down Expand Up @@ -294,6 +297,9 @@ func (d *dockerRunner) execCmd(args ...string) (string, error) {
if d.workdir != "" {
a = append(a, "-w", d.workdir)
}
if len(d.httpsProxy) != 0 {
a = append(a, "-e", fmt.Sprintf("https_proxy=%s", d.httpsProxy))
}
for _, e := range d.env {
a = append(a, "-e", e)
}
Expand Down Expand Up @@ -982,7 +988,7 @@ func Run(o Options) error {
if err := processTempDir(&o); err != nil {
return fmt.Errorf("unable to initialize a local temporary working directory to store intermediate files: %w", err)
}
d, err := newDockerRunner(o.ToolchainContainer, o.Cleanup)
d, err := newDockerRunner(o.ToolchainContainer, o.Cleanup, o.HttpsProxy)
if err != nil {
return fmt.Errorf("failed to initialize a docker container: %w", err)
}
Expand Down