Exclude dummy backend in production (#3877)

This commit is contained in:
qwerty287 2024-07-08 16:29:43 +02:00 committed by GitHub
parent fb199f68e3
commit a076393561
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 62 additions and 96 deletions

24
cli/exec/dummy.go Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2024 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build test
// +build test
package exec
import "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy"
func init() { //nolint:gochecknoinits
backends = append(backends, dummy.New())
}

View file

@ -33,7 +33,6 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/pipeline"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/docker"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/kubernetes"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/local"
backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
@ -54,6 +53,12 @@ var Command = &cli.Command{
Flags: utils.MergeSlices(flags, docker.Flags, kubernetes.Flags, local.Flags),
}
var backends = []backend_types.Backend{
kubernetes.New(),
docker.New(),
local.New(),
}
func run(c *cli.Context) error {
return common.RunPipelineFunc(c, execFile, execDir)
}
@ -231,12 +236,6 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
}
backendCtx := context.WithValue(c.Context, backend_types.CliContext, c)
backends := []backend_types.Backend{
kubernetes.New(),
docker.New(),
local.New(),
dummy.New(),
}
backendEngine, err := backend.FindBackend(backendCtx, backends, c.String("backend-engine"))
if err != nil {
return err

24
cmd/agent/dummy.go Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2024 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build test
// +build test
package main
import "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy"
func init() { //nolint:gochecknoinits
backends = append(backends, dummy.New())
}

View file

@ -17,17 +17,17 @@ package main
import (
"go.woodpecker-ci.org/woodpecker/v2/cmd/agent/core"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/docker"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/dummy"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/kubernetes"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/local"
backendTypes "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
)
func main() {
core.RunAgent([]backendTypes.Backend{
kubernetes.New(),
docker.New(),
local.New(),
dummy.New(),
})
var backends = []backendTypes.Backend{
kubernetes.New(),
docker.New(),
local.New(),
}
func main() {
core.RunAgent(backends)
}

View file

@ -1,78 +0,0 @@
// Copyright 2024 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !test
// +build !test
package dummy
import (
"context"
"errors"
"io"
"github.com/urfave/cli/v2"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
)
type noop struct{}
var ErrOnCompileExcluded = errors.New("the dummy backend engine was excluded on compile time")
// New returns a dummy backend.
func New() types.Backend {
return &noop{}
}
func (e *noop) Name() string {
return "dummy"
}
func (e *noop) IsAvailable(context.Context) bool {
return false
}
func (e *noop) Flags() []cli.Flag {
return nil
}
// Load new client for Docker Backend using environment variables.
func (e *noop) Load(context.Context) (*types.BackendInfo, error) {
return nil, ErrOnCompileExcluded
}
func (e *noop) SetupWorkflow(context.Context, *types.Config, string) error {
return ErrOnCompileExcluded
}
func (e *noop) StartStep(context.Context, *types.Step, string) error {
return ErrOnCompileExcluded
}
func (e *noop) WaitStep(context.Context, *types.Step, string) (*types.State, error) {
return nil, ErrOnCompileExcluded
}
func (e *noop) TailStep(context.Context, *types.Step, string) (io.ReadCloser, error) {
return nil, ErrOnCompileExcluded
}
func (e *noop) DestroyStep(context.Context, *types.Step, string) error {
return ErrOnCompileExcluded
}
func (e *noop) DestroyWorkflow(context.Context, *types.Config, string) error {
return ErrOnCompileExcluded
}

View file

@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build test
// +build test
package dummy_test
import (