...

Source file src/edge-infra.dev/pkg/tools/hack/containers/options.go

Documentation: edge-infra.dev/pkg/tools/hack/containers

     1  package containers
     2  
     3  import "fmt"
     4  
     5  // Option allows controlling behavior for working with container_push targets.
     6  type Option func(*options)
     7  
     8  // Insecure adds a flag to rules_docker container_push targets to allow HTTP
     9  // repositories.
    10  func Insecure(opts *options) {
    11  	opts.insecure = true
    12  }
    13  
    14  // ToRepository overrides the destination repository set on the container_push
    15  // rule(s).
    16  func ToRepository(r string) Option {
    17  	return func(opts *options) {
    18  		opts.registry = r
    19  	}
    20  }
    21  
    22  func makeOptions(o ...Option) *options {
    23  	options := &options{}
    24  	for _, option := range o {
    25  		option(options)
    26  	}
    27  	return options
    28  }
    29  
    30  type options struct {
    31  	insecure bool
    32  	registry string
    33  }
    34  
    35  // args generates CLI arguments to pass to Bazel
    36  func (o options) args() []string {
    37  	var args []string
    38  	if o.registry != "" {
    39  		args = append(args,
    40  			fmt.Sprintf("%s=%s", workloadsRepoFlag, o.registry),
    41  			fmt.Sprintf("%s=%s", thirdPartyRepoFlag, o.registry),
    42  		)
    43  	}
    44  	if o.insecure {
    45  		args = append(args, "--", fmt.Sprintf("--%s=true", insecureFlag))
    46  	}
    47  
    48  	return args
    49  }
    50  

View as plain text