mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-25 08:38:43 +00:00
Revert volumes/network list (#4656)
Co-authored-by: Robert Kaussow <xoxys@rknet.org> Co-authored-by: Patrick Schratz <patrick.schratz@gmail.com>
This commit is contained in:
parent
58807857e9
commit
7c31bcf327
9 changed files with 57 additions and 77 deletions
|
@ -22,7 +22,7 @@ import (
|
|||
// Generate docs/openapi.json via:
|
||||
//go:generate go run github.com/swaggo/swag/cmd/swag init -g cmd/server/openapi.go --outputTypes go -output openapi -d ../../
|
||||
//go:generate go run openapi_json_gen.go openapi.go
|
||||
//go:generate go run github.com/getkin/kin-openapi/cmd/validate@latest ../../docs/openapi.json
|
||||
//go:generate go run github.com/getkin/kin-openapi/cmd/validate ../../docs/openapi.json
|
||||
|
||||
// setupOpenAPIStaticConfig initializes static content (version) for the OpenAPI config.
|
||||
//
|
||||
|
|
|
@ -144,32 +144,23 @@ func (e *docker) Load(ctx context.Context) (*backend.BackendInfo, error) {
|
|||
func (e *docker) SetupWorkflow(ctx 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(ctx, volume.CreateOptions{
|
||||
Name: vol.Name,
|
||||
Driver: volumeDriver,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := e.client.VolumeCreate(ctx, volume.CreateOptions{
|
||||
Name: conf.Volume.Name,
|
||||
Driver: volumeDriver,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
networkDriver := networkDriverBridge
|
||||
if e.info.OSType == "windows" {
|
||||
networkDriver = networkDriverNAT
|
||||
}
|
||||
|
||||
for _, n := range conf.Networks {
|
||||
_, err := e.client.NetworkCreate(ctx, n.Name, network.CreateOptions{
|
||||
Driver: networkDriver,
|
||||
EnableIPv6: &e.config.enableIPv6,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err = e.client.NetworkCreate(ctx, conf.Network.Name, network.CreateOptions{
|
||||
Driver: networkDriver,
|
||||
EnableIPv6: &e.config.enableIPv6,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID string) error {
|
||||
|
@ -332,19 +323,12 @@ func (e *docker) DestroyWorkflow(ctx context.Context, conf *backend.Config, task
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range conf.Volumes {
|
||||
if err := e.client.VolumeRemove(ctx, v.Name, true); err != nil {
|
||||
log.Error().Err(err).Msgf("could not remove volume '%s'", v.Name)
|
||||
}
|
||||
if err := e.client.VolumeRemove(ctx, conf.Volume.Name, true); err != nil {
|
||||
log.Error().Err(err).Msgf("could not remove volume '%s'", conf.Volume.Name)
|
||||
}
|
||||
|
||||
for _, n := range conf.Networks {
|
||||
if err := e.client.NetworkRemove(ctx, n.Name); err != nil {
|
||||
log.Error().Err(err).Msgf("could not remove network '%s'", n.Name)
|
||||
}
|
||||
if err := e.client.NetworkRemove(ctx, conf.Network.Name); err != nil {
|
||||
log.Error().Err(err).Msgf("could not remove network '%s'", conf.Network.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -191,11 +191,9 @@ func (e *kube) getConfig() *config {
|
|||
func (e *kube) SetupWorkflow(ctx context.Context, conf *types.Config, taskUUID string) error {
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("Setting up Kubernetes primitives")
|
||||
|
||||
for _, vol := range conf.Volumes {
|
||||
_, err := startVolume(ctx, e, vol.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := startVolume(ctx, e, conf.Volume.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var extraHosts []types.HostAlias
|
||||
|
@ -427,11 +425,9 @@ func (e *kube) DestroyWorkflow(ctx context.Context, conf *types.Config, taskUUID
|
|||
}
|
||||
}
|
||||
|
||||
for _, vol := range conf.Volumes {
|
||||
err := stopVolume(ctx, e, vol.Name, defaultDeleteOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err := stopVolume(ctx, e, conf.Volume.Name, defaultDeleteOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -16,10 +16,10 @@ package types
|
|||
|
||||
// Config defines the runtime configuration of a workflow.
|
||||
type Config struct {
|
||||
Stages []*Stage `json:"pipeline"` // workflow stages
|
||||
Networks []*Network `json:"network"` // network definitions
|
||||
Volumes []*Volume `json:"volume"` // volume definitions
|
||||
Secrets []*Secret `json:"secrets"` // secret definitions
|
||||
Stages []*Stage `json:"pipeline"` // workflow stages
|
||||
Network *Network `json:"network"` // network definition
|
||||
Volume *Volume `json:"volume"` // volume definition
|
||||
Secrets []*Secret `json:"secrets"` // secret definitions
|
||||
}
|
||||
|
||||
// CliCommand is the context key to pass cli context to backends if needed.
|
||||
|
|
|
@ -129,14 +129,14 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
|||
}
|
||||
|
||||
// create a default volume
|
||||
config.Volumes = append(config.Volumes, &backend_types.Volume{
|
||||
config.Volume = &backend_types.Volume{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
})
|
||||
}
|
||||
|
||||
// create a default network
|
||||
config.Networks = append(config.Networks, &backend_types.Network{
|
||||
config.Network = &backend_types.Network{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
})
|
||||
}
|
||||
|
||||
// create secrets for mask
|
||||
for _, sec := range c.secrets {
|
||||
|
|
|
@ -81,12 +81,12 @@ func TestCompilerCompile(t *testing.T) {
|
|||
WithWorkspaceFromURL("/test", repoURL),
|
||||
)
|
||||
|
||||
defaultNetworks := []*backend_types.Network{{
|
||||
defaultNetwork := &backend_types.Network{
|
||||
Name: "test_default",
|
||||
}}
|
||||
defaultVolumes := []*backend_types.Volume{{
|
||||
}
|
||||
defaultVolume := &backend_types.Volume{
|
||||
Name: "test_default",
|
||||
}}
|
||||
}
|
||||
|
||||
defaultCloneStage := &backend_types.Stage{
|
||||
Steps: []*backend_types.Step{{
|
||||
|
@ -95,7 +95,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Image: constant.DefaultClonePlugin,
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/woodpecker"},
|
||||
Volumes: []string{defaultVolume.Name + ":/woodpecker"},
|
||||
WorkingDir: "/woodpecker/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/woodpecker",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"clone"}}},
|
||||
|
@ -113,17 +113,17 @@ func TestCompilerCompile(t *testing.T) {
|
|||
name: "empty workflow, no clone",
|
||||
fronConf: &yaml_types.Workflow{SkipClone: true},
|
||||
backConf: &backend_types.Config{
|
||||
Networks: defaultNetworks,
|
||||
Volumes: defaultVolumes,
|
||||
Network: defaultNetwork,
|
||||
Volume: defaultVolume,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty workflow, default clone",
|
||||
fronConf: &yaml_types.Workflow{},
|
||||
backConf: &backend_types.Config{
|
||||
Networks: defaultNetworks,
|
||||
Volumes: defaultVolumes,
|
||||
Stages: []*backend_types.Stage{defaultCloneStage},
|
||||
Network: defaultNetwork,
|
||||
Volume: defaultVolume,
|
||||
Stages: []*backend_types.Stage{defaultCloneStage},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -133,8 +133,8 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Image: "dummy_img",
|
||||
}}}},
|
||||
backConf: &backend_types.Config{
|
||||
Networks: defaultNetworks,
|
||||
Volumes: defaultVolumes,
|
||||
Network: defaultNetwork,
|
||||
Volume: defaultVolume,
|
||||
Stages: []*backend_types.Stage{defaultCloneStage, {
|
||||
Steps: []*backend_types.Step{{
|
||||
Name: "dummy",
|
||||
|
@ -142,7 +142,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Image: "dummy_img",
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/woodpecker"},
|
||||
Volumes: []string{defaultVolume.Name + ":/woodpecker"},
|
||||
WorkingDir: "/woodpecker/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/woodpecker",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"dummy"}}},
|
||||
|
@ -167,8 +167,8 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"echo 2"},
|
||||
}}}},
|
||||
backConf: &backend_types.Config{
|
||||
Networks: defaultNetworks,
|
||||
Volumes: defaultVolumes,
|
||||
Network: defaultNetwork,
|
||||
Volume: defaultVolume,
|
||||
Stages: []*backend_types.Stage{
|
||||
defaultCloneStage, {
|
||||
Steps: []*backend_types.Step{{
|
||||
|
@ -178,7 +178,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"env"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/test"},
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo env"}}},
|
||||
|
@ -192,7 +192,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"echo 1"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/test"},
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"parallel echo 1"}}},
|
||||
|
@ -206,7 +206,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"echo 2"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/test"},
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"parallel echo 2"}}},
|
||||
|
@ -233,8 +233,8 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"echo 2"},
|
||||
}}}},
|
||||
backConf: &backend_types.Config{
|
||||
Networks: defaultNetworks,
|
||||
Volumes: defaultVolumes,
|
||||
Network: defaultNetwork,
|
||||
Volume: defaultVolume,
|
||||
Stages: []*backend_types.Stage{defaultCloneStage, {
|
||||
Steps: []*backend_types.Step{{
|
||||
Name: "echo env",
|
||||
|
@ -243,7 +243,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"env"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/test"},
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo env"}}},
|
||||
|
@ -255,7 +255,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"echo 2"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/test"},
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo 2"}}},
|
||||
|
@ -269,7 +269,7 @@ func TestCompilerCompile(t *testing.T) {
|
|||
Commands: []string{"echo 1"},
|
||||
OnSuccess: true,
|
||||
Failure: "fail",
|
||||
Volumes: []string{defaultVolumes[0].Name + ":/test"},
|
||||
Volumes: []string{defaultVolume.Name + ":/test"},
|
||||
WorkingDir: "/test/src/github.com/octocat/hello-world",
|
||||
WorkspaceBase: "/test",
|
||||
Networks: []backend_types.Conn{{Name: "test_default", Aliases: []string{"echo 1"}}},
|
||||
|
|
|
@ -16,4 +16,4 @@ package proto
|
|||
|
||||
// Version is the version of the woodpecker.proto file,
|
||||
// IMPORTANT: increased by 1 each time it get changed.
|
||||
const Version int32 = 11
|
||||
const Version int32 = 12
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.0
|
||||
// protoc v4.24.4
|
||||
// protoc-gen-go v1.36.1
|
||||
// protoc v5.28.3
|
||||
// source: woodpecker.proto
|
||||
|
||||
package proto
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.5.1
|
||||
// - protoc v4.24.4
|
||||
// - protoc v5.28.3
|
||||
// source: woodpecker.proto
|
||||
|
||||
package proto
|
||||
|
|
Loading…
Reference in a new issue