Skip to content

Commit

Permalink
feat(context): add podman support
Browse files Browse the repository at this point in the history
feat(CI): add setup podman
  • Loading branch information
TaylorHere committed Nov 7, 2022
1 parent 3233cd6 commit 2561f10
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ jobs:
${{ runner.OS }}-
- uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
- name: setup podman
run: sudo apt install podman && systemctl --user start podman.socket && systemctl --user status podman.socket
- name: e2e test
run: make e2e-cli-test
env:
Expand Down
54 changes: 54 additions & 0 deletions e2e/cli/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cli

import (
"os"
"os/exec"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -108,4 +109,57 @@ var _ = Describe("home context", func() {
Expect(contexts.Current).To(Equal(defaultContext))
})
})

Describe("add a podman context", Ordered, func() {
testContext := "envd_home_test"
testBuilder := types.BuilderTypePodman
testBuilderAddress := "envd_buildkitd"
testRunner := types.RunnerTypePodman
c := types.Context{
Name: testContext,
Builder: testBuilder,
BuilderAddress: testBuilderAddress,
Runner: testRunner,
}
originalEnv := os.Getenv("DOCKER_HOST")
BeforeAll(func() {
os.Setenv("DOCKER_HOST", "unix://"+os.Getenv("XDG_RUNTIME_DIR")+"/podman/podman.sock")
err := home.GetManager().ContextCreate(c, true)
Expect(err).NotTo(HaveOccurred())
})

It("should find a new context", func() {
contexts, err := home.GetManager().ContextList()
Expect(err).NotTo(HaveOccurred())
Expect(contexts.Current).To(Equal(testContext))
})

Describe("connect buildkit through podman-container", Ordered, func() {
buildContext := "testdata/build-test"

It("should be able to build image with podman context", func() {
args := []string{"envd.test", "--debug", "build", "--path", buildContext}
envdApp := app.New()
e2e.ResetEnvdApp()
err := envdApp.Run(args)
Expect(err).NotTo(HaveOccurred())
})
})

It("fail to delete the current context", func() {
err := home.GetManager().ContextRemove(testContext)
Expect(err).To(HaveOccurred())
})

AfterAll(func() {
os.Setenv("DOCKER_HOST", originalEnv)
err := home.GetManager().ContextUse(defaultContext)
Expect(err).NotTo(HaveOccurred())
err = home.GetManager().ContextRemove(testContext)
Expect(err).NotTo(HaveOccurred())
contexts, err := home.GetManager().ContextList()
Expect(err).NotTo(HaveOccurred())
Expect(contexts.Current).To(Equal(defaultContext))
})
})
})
4 changes: 2 additions & 2 deletions pkg/app/context_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var CommandContextCreate = &cli.Command{
},
&cli.StringFlag{
Name: "builder",
Usage: "Builder to use (docker-container, kube-pod, tcp, unix)",
Usage: "Builder to use (docker-container, podman-container, kube-pod, tcp, unix)",
Value: string(types.BuilderTypeDocker),
},
&cli.StringFlag{
Expand All @@ -45,7 +45,7 @@ var CommandContextCreate = &cli.Command{
},
&cli.StringFlag{
Name: "runner",
Usage: "Runner to use(docker, envd-server)",
Usage: "Runner to use(docker, podman, envd-server)",
Value: string(types.RunnerTypeDocker),
},
&cli.StringFlag{
Expand Down
12 changes: 11 additions & 1 deletion pkg/buildkitd/buildkitd.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,26 @@ func (c generalClient) Close() error {
// that can be used to connect to it.
func (c *generalClient) maybeStart(ctx context.Context,
runningTimeout, connectingTimeout time.Duration) (string, error) {
if c.driver == types.BuilderTypeDocker {
if c.driver == types.BuilderTypeDocker || c.driver == types.BuilderTypePodman {
dockerClient, err := docker.NewClient(ctx)
if err != nil {
return "", err
}

opt := envd.Options{
Context: &types.Context{
Runner: types.RunnerTypeDocker,
},
}

if c.driver == types.BuilderTypePodman {
opt = envd.Options{
Context: &types.Context{
Runner: types.RunnerTypePodman,
},
}
}

engine, err := envd.New(ctx, opt)
if err != nil {
return "", err
Expand Down
5 changes: 3 additions & 2 deletions pkg/home/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ func (m *generalManager) ContextCreate(ctx types.Context, use bool) error {
}
switch ctx.Builder {
case types.BuilderTypeDocker, types.BuilderTypeKubernetes,
types.BuilderTypeUNIXDomainSocket, types.BuilderTypeTCP:
types.BuilderTypeUNIXDomainSocket, types.BuilderTypeTCP,
types.BuilderTypePodman:
break
default:
return errors.New("unknown builder type")
}
switch ctx.Runner {
case types.RunnerTypeDocker, types.RunnerTypeEnvdServer:
case types.RunnerTypeDocker, types.RunnerTypeEnvdServer, types.RunnerTypePodman:
break
default:
return errors.New("unknown runner type")
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type BuilderType string

const (
BuilderTypeDocker BuilderType = "docker-container"
BuilderTypePodman BuilderType = "podman-container"
BuilderTypeKubernetes BuilderType = "kube-pod"
BuilderTypeTCP BuilderType = "tcp"
BuilderTypeUNIXDomainSocket BuilderType = "unix"
Expand All @@ -138,6 +139,7 @@ type RunnerType string

const (
RunnerTypeDocker RunnerType = "docker"
RunnerTypePodman RunnerType = "podman"
RunnerTypeEnvdServer RunnerType = "envd-server"
)

Expand Down

0 comments on commit 2561f10

Please sign in to comment.