mirror of
https://gitea.com/gitea/act_runner.git
synced 2025-06-13 01:57:13 +02:00
refactor: docker engine with options
This commit is contained in:
@ -6,30 +6,28 @@ import (
|
||||
"github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
// Opts configures the Docker engine.
|
||||
type Opts struct {
|
||||
HidePull bool
|
||||
}
|
||||
|
||||
type Docker struct {
|
||||
client client.APIClient
|
||||
hidePull bool
|
||||
}
|
||||
|
||||
func New(client client.APIClient, opts Opts) *Docker {
|
||||
return &Docker{
|
||||
client: client,
|
||||
hidePull: opts.HidePull,
|
||||
}
|
||||
}
|
||||
|
||||
// NewEnv returns a new Engine from the environment.
|
||||
func NewEnv(opts Opts) (*Docker, error) {
|
||||
func New(opts ...Option) (*Docker, error) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(cli, opts), nil
|
||||
|
||||
srv := &Docker{
|
||||
client: cli,
|
||||
}
|
||||
|
||||
// Loop through each option
|
||||
for _, opt := range opts {
|
||||
// Call the option giving the instantiated
|
||||
opt.Apply(srv)
|
||||
}
|
||||
|
||||
return srv, nil
|
||||
}
|
||||
|
||||
// Ping pings the Docker daemon.
|
||||
|
Reference in New Issue
Block a user