mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-01 08:31:57 +00:00
Refactor agent (#2021)
- code cleanup - init backend engine only once - pass a taskUUID to the backend --- *Sponsored by Kithara Software GmbH*
This commit is contained in:
@@ -101,7 +101,9 @@ func (e *docker) Load(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *docker) Setup(_ context.Context, conf *backend.Config) error {
|
||||
func (e *docker) SetupWorkflow(_ context.Context, conf *backend.Config, taskUUID string) error {
|
||||
log.Trace().Str("taskUUID", taskUUID).Msg("create workflow environment")
|
||||
|
||||
for _, vol := range conf.Volumes {
|
||||
_, err := e.client.VolumeCreate(noContext, volume.VolumeCreateBody{
|
||||
Name: vol.Name,
|
||||
@@ -128,7 +130,9 @@ func (e *docker) Setup(_ context.Context, conf *backend.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *docker) Exec(ctx context.Context, step *backend.Step) error {
|
||||
func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID string) error {
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("start step %s", step.Name)
|
||||
|
||||
config := toConfig(step)
|
||||
hostConfig := toHostConfig(step)
|
||||
containerName := toContainerName(step)
|
||||
@@ -204,7 +208,9 @@ func (e *docker) Exec(ctx context.Context, step *backend.Step) error {
|
||||
return e.client.ContainerStart(ctx, containerName, startOpts)
|
||||
}
|
||||
|
||||
func (e *docker) Wait(ctx context.Context, step *backend.Step) (*backend.State, error) {
|
||||
func (e *docker) WaitStep(ctx context.Context, step *backend.Step, taskUUID string) (*backend.State, error) {
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("wait for step %s", step.Name)
|
||||
|
||||
containerName := toContainerName(step)
|
||||
|
||||
wait, errc := e.client.ContainerWait(ctx, containerName, "")
|
||||
@@ -228,7 +234,9 @@ func (e *docker) Wait(ctx context.Context, step *backend.Step) (*backend.State,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *docker) Tail(ctx context.Context, step *backend.Step) (io.ReadCloser, error) {
|
||||
func (e *docker) TailStep(ctx context.Context, step *backend.Step, taskUUID string) (io.ReadCloser, error) {
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("tail logs of step %s", step.Name)
|
||||
|
||||
logs, err := e.client.ContainerLogs(ctx, toContainerName(step), logsOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -244,7 +252,9 @@ func (e *docker) Tail(ctx context.Context, step *backend.Step) (io.ReadCloser, e
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func (e *docker) Destroy(_ context.Context, conf *backend.Config) error {
|
||||
func (e *docker) DestroyWorkflow(_ context.Context, conf *backend.Config, taskUUID string) error {
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("delete workflow environment")
|
||||
|
||||
for _, stage := range conf.Stages {
|
||||
for _, step := range stage.Steps {
|
||||
containerName := toContainerName(step)
|
||||
|
Reference in New Issue
Block a user