Skip to content

Commit

Permalink
Merge pull request #9 from deepfence/add-newruntime
Browse files Browse the repository at this point in the history
Add NewRuntime util function
  • Loading branch information
noboruma authored Jan 7, 2022
2 parents f32d297 + 259c693 commit 6ef3cc6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package vessel
import (
"context"
"fmt"
"net"
"net/url"
"strings"

"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
"github.com/deepfence/vessel/constants"
self_containerd "github.com/deepfence/vessel/containerd"
"github.com/deepfence/vessel/docker"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"net"
"net/url"
"strings"
)

func init() {
Expand Down Expand Up @@ -187,3 +190,20 @@ func isContainerdRunning(host string) (bool, error) {
}
return false, nil
}

// Auto detect and returns the runtime available for the current system
func NewRuntime() (Runtime, error) {

runtime, _, err := AutoDetectRuntime()
if err != nil {
return nil, err
}

if runtime == constants.DOCKER {
return docker.New(), nil
} else if runtime == constants.CONTAINERD {
return self_containerd.New(), nil
}

return nil, errors.New("Unknown runtime")
}

0 comments on commit 6ef3cc6

Please sign in to comment.