Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add podman backend #305

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 18 additions & 1 deletion agent/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewRunner(workEngine rpc.Peer, f rpc.Filter, h string, state *State, backen
}
}

func (r *Runner) Run(ctx context.Context) error {
func (r *Runner) Run(ctx context.Context, usePodman bool) error {
anbraten marked this conversation as resolved.
Show resolved Hide resolved
log.Debug().
Msg("request next execution")

Expand Down Expand Up @@ -98,6 +98,23 @@ func (r *Runner) Run(ctx context.Context) error {
logger.Debug().
Msg("received execution")

/*
var engine backend.Engine
if usePodman == true {
engine = podman.New()
} else {
// new docker engine
engine, err = docker.NewEnv()
if err != nil {
logger.Error().
Err(err).
Msg("cannot create docker client")

return err
}
}
*/

ctx, cancel := context.WithTimeout(ctxmeta, timeout)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func loop(c *cli.Context) error {
}

r := agent.NewRunner(client, filter, hostname, counter, &engine)
if err := r.Run(ctx); err != nil {
if err := r.Run(ctx, c.BoolT("use-podman")); err != nil {
log.Error().Err(err).Msg("pipeline done with error")
return
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/agent/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ var flags = []cli.Flag{
Usage: "should the grpc server certificate be verified, only valid when DRONE_GRPC_SECURE is true",
EnvVar: "DRONE_GRPC_VERIFY,WOODPECKER_GRPC_VERIFY",
},
cli.BoolTFlag{
Name: "use-podman",
Usage: "use podman as backend instead of docker",
EnvVar: "WOODPECKER_AGENT_PODMAN",
},
}
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ go 1.16

require (
code.gitea.io/sdk/gitea v0.15.0
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/bradrydzewski/togo v0.0.0-20180401185031-50a0e4726e74 // indirect
github.com/containerd/containerd v1.5.5 // indirect
github.com/containers/podman/v3 v3.3.1
github.com/dimfeld/httptreemux v5.0.1+incompatible
github.com/docker/cli v0.0.0-20200303215952-eb310fca4956
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v20.10.8+incompatible
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/libcompose v0.4.0
github.com/drone/envsubst v1.0.3
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
Expand All @@ -39,7 +37,6 @@ require (
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/mrjones/oauth v0.0.0-20190623134757-126b35219450
github.com/prometheus/client_golang v1.7.1
github.com/rs/zerolog v1.25.0
Expand All @@ -54,12 +51,11 @@ require (
github.com/woodpecker-ci/togo v0.0.0-20180401185031-50a0e4726e74
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/net v0.0.0-20210825183410-e898025ed96a
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/grpc v1.33.2
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
476 changes: 465 additions & 11 deletions go.sum

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions pipeline/backend/podman/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package podman

import (
"fmt"
"net"

"github.com/containers/podman/v3/pkg/specgen"

"github.com/woodpecker-ci/woodpecker/pipeline/backend"
)

// returns specgen.SpecGenerator container config
func toSpecGenerator(proc *backend.Step) (*specgen.SpecGenerator, error) {
var err error
specGen := specgen.NewSpecGenerator(proc.Image, false)
specGen.Terminal = true

specGen.Image = proc.Image
specGen.Name = proc.Name
specGen.Labels = proc.Labels
specGen.WorkDir = proc.WorkingDir

if len(proc.Environment) > 0 {
specGen.Env = proc.Environment
}
if len(proc.Command) > 0 {
specGen.Command = proc.Command
}
fmt.Printf("specgenentrypoint: %v\n", proc.Entrypoint)
if len(proc.Entrypoint) > 0 {
specGen.Entrypoint = proc.Entrypoint
}
fmt.Printf("specgenvolumes: %v\n", proc.Volumes)
if len(proc.Volumes) > 0 {
for _, v := range proc.Volumes {
fmt.Printf("proc.vol: %v\n", v)
}
_, vols, _, err := specgen.GenVolumeMounts(proc.Volumes)
if err != nil {
return nil, err
}
for _, vol := range vols {
fmt.Printf("specgenvol: %v\n", vol)
specGen.Volumes = append(specGen.Volumes, vol)
}
}

specGen.LogConfiguration = &specgen.LogConfig{
//Driver: "json-file",
}
// TODO: Privileged seems to be required
specGen.Privileged = true
specGen.ShmSize = new(int64)
*specGen.ShmSize = proc.ShmSize
specGen.Sysctl = proc.Sysctls

if len(proc.IpcMode) > 0 {
if specGen.IpcNS, err = specgen.ParseNamespace(proc.IpcMode); err != nil {
return nil, err
}
}
if len(proc.DNS) > 0 {
for _, dns := range proc.DNS {
if ip := net.ParseIP(dns); ip != nil {
specGen.DNSServers = append(specGen.DNSServers, ip)
}
}
}
if len(proc.DNSSearch) > 0 {
specGen.DNSSearch = proc.DNSSearch
}
if len(proc.ExtraHosts) > 0 {
specGen.HostAdd = proc.ExtraHosts
}

return specGen, err
}
Loading