2023-02-28 10:44:46 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-08-13 07:15:21 +01:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Docker struct {
|
|
|
|
client client.APIClient
|
|
|
|
hidePull bool
|
|
|
|
}
|
|
|
|
|
2022-08-13 07:30:05 +01:00
|
|
|
func New(opts ...Option) (*Docker, error) {
|
2022-08-13 07:15:21 +01:00
|
|
|
cli, err := client.NewClientWithOpts(client.FromEnv)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-13 07:30:05 +01:00
|
|
|
|
|
|
|
srv := &Docker{
|
|
|
|
client: cli,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through each option
|
|
|
|
for _, opt := range opts {
|
|
|
|
// Call the option giving the instantiated
|
|
|
|
opt.Apply(srv)
|
|
|
|
}
|
|
|
|
|
|
|
|
return srv, nil
|
2022-08-13 07:15:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ping pings the Docker daemon.
|
|
|
|
func (e *Docker) Ping(ctx context.Context) error {
|
|
|
|
_, err := e.client.Ping(ctx)
|
|
|
|
return err
|
|
|
|
}
|