ToMobyHealthCheck convert into container.HealthConfig
(ctx context.Context, check *compose.HealthCheckConfig)
| 41 | |
| 42 | // ToMobyHealthCheck convert into container.HealthConfig |
| 43 | func (s *composeService) ToMobyHealthCheck(ctx context.Context, check *compose.HealthCheckConfig) (*container.HealthConfig, error) { |
| 44 | if check == nil { |
| 45 | return nil, nil |
| 46 | } |
| 47 | var ( |
| 48 | interval time.Duration |
| 49 | timeout time.Duration |
| 50 | period time.Duration |
| 51 | retries int |
| 52 | ) |
| 53 | if check.Interval != nil { |
| 54 | interval = time.Duration(*check.Interval) |
| 55 | } |
| 56 | if check.Timeout != nil { |
| 57 | timeout = time.Duration(*check.Timeout) |
| 58 | } |
| 59 | if check.StartPeriod != nil { |
| 60 | period = time.Duration(*check.StartPeriod) |
| 61 | } |
| 62 | if check.Retries != nil { |
| 63 | retries = int(*check.Retries) |
| 64 | } |
| 65 | test := check.Test |
| 66 | if check.Disable { |
| 67 | test = []string{"NONE"} |
| 68 | } |
| 69 | var startInterval time.Duration |
| 70 | if check.StartInterval != nil { |
| 71 | startInterval = time.Duration(*check.StartInterval) |
| 72 | if check.StartPeriod == nil { |
| 73 | // see https://github.com/moby/moby/issues/48874 |
| 74 | return nil, errors.New("healthcheck.start_interval requires healthcheck.start_period to be set") |
| 75 | } |
| 76 | } |
| 77 | return &container.HealthConfig{ |
| 78 | Test: test, |
| 79 | Interval: interval, |
| 80 | Timeout: timeout, |
| 81 | StartPeriod: period, |
| 82 | StartInterval: startInterval, |
| 83 | Retries: retries, |
| 84 | }, nil |
| 85 | } |
| 86 | |
| 87 | // ToSeconds convert into seconds |
| 88 | func ToSeconds(d *compose.Duration) *int { |