mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-06 00:44:22 +02:00
Service containers were started and then left alone, so a job's first step could run while a database was still starting up. The runner now waits for every service whose image or `options` declare a healthcheck, as GitHub does. An unhealthy service fails the job with its container log, one that never becomes healthy fails it after `container.service_ready_timeout` (default `5m`, negative disables the wait), and one that exits without a healthcheck only gets its log and a warning.
The started containers also fill the `job` context, whose fields existed but were never populated: `job.container.{id,network}` and `job.services.<id>.{id,network,ports}`. `ports` is keyed by the plain container port, so `job.services.postgres.ports['5432']` resolves to the host port Docker picked.
---------
Co-authored-by: silverwind <me@silverwind.io>
Reviewed-on: https://gitea.com/gitea/runner/pulls/1107
Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
Co-authored-by: bircni <bircni@icloud.com>
92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
"gitea.com/gitea/runner/act/container"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
type containerMock struct {
|
|
mock.Mock
|
|
container.Container
|
|
container.LinuxContainerEnvironmentExtensions
|
|
}
|
|
|
|
func (cm *containerMock) Create(capAdd, capDrop []string) common.Executor {
|
|
args := cm.Called(capAdd, capDrop)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) Pull(forcePull bool) common.Executor {
|
|
args := cm.Called(forcePull)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) Start(attach bool) common.Executor {
|
|
args := cm.Called(attach)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) Remove() common.Executor {
|
|
args := cm.Called()
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) Close() common.Executor {
|
|
args := cm.Called()
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) UpdateFromEnv(srcPath string, env *map[string]string) common.Executor {
|
|
args := cm.Called(srcPath, env)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) UpdateFromImageEnv(env *map[string]string) common.Executor {
|
|
args := cm.Called(env)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) Copy(destPath string, files ...*container.FileEntry) common.Executor {
|
|
args := cm.Called(destPath, files)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) CopyDir(destPath, srcPath string, useGitIgnore bool) common.Executor {
|
|
args := cm.Called(destPath, srcPath, useGitIgnore)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) Exec(command []string, env map[string]string, user, workdir string) common.Executor {
|
|
args := cm.Called(command, env, user, workdir)
|
|
return args.Get(0).(func(context.Context) error)
|
|
}
|
|
|
|
func (cm *containerMock) GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error) {
|
|
args := cm.Called(ctx, srcPath)
|
|
err, hasErr := args.Get(1).(error)
|
|
if !hasErr {
|
|
err = nil
|
|
}
|
|
return args.Get(0).(io.ReadCloser), err
|
|
}
|
|
|
|
func (cm *containerMock) DumpLogs(ctx context.Context) error {
|
|
return cm.Called(ctx).Error(0)
|
|
}
|
|
|
|
func (cm *containerMock) Inspect(ctx context.Context) (*container.Info, error) {
|
|
args := cm.Called(ctx)
|
|
info, _ := args.Get(0).(*container.Info)
|
|
err, _ := args.Get(1).(error)
|
|
return info, err
|
|
}
|