Skip to content

Commit 7e8d070

Browse files
feat: Allow building without docker support (#1507)
* feat: Allow building without docker support * fix macos build tag Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a53a1c2 commit 7e8d070

10 files changed

+143
-62
lines changed

pkg/container/container_types.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package container
2+
3+
import (
4+
"context"
5+
"io"
6+
7+
"github.com/nektos/act/pkg/common"
8+
)
9+
10+
// NewContainerInput the input for the New function
11+
type NewContainerInput struct {
12+
Image string
13+
Username string
14+
Password string
15+
Entrypoint []string
16+
Cmd []string
17+
WorkingDir string
18+
Env []string
19+
Binds []string
20+
Mounts map[string]string
21+
Name string
22+
Stdout io.Writer
23+
Stderr io.Writer
24+
NetworkMode string
25+
Privileged bool
26+
UsernsMode string
27+
Platform string
28+
Options string
29+
}
30+
31+
// FileEntry is a file to copy to a container
32+
type FileEntry struct {
33+
Name string
34+
Mode int64
35+
Body string
36+
}
37+
38+
// Container for managing docker run containers
39+
type Container interface {
40+
Create(capAdd []string, capDrop []string) common.Executor
41+
Copy(destPath string, files ...*FileEntry) common.Executor
42+
CopyDir(destPath string, srcPath string, useGitIgnore bool) common.Executor
43+
GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error)
44+
Pull(forcePull bool) common.Executor
45+
Start(attach bool) common.Executor
46+
Exec(command []string, env map[string]string, user, workdir string) common.Executor
47+
UpdateFromEnv(srcPath string, env *map[string]string) common.Executor
48+
UpdateFromImageEnv(env *map[string]string) common.Executor
49+
UpdateFromPath(env *map[string]string) common.Executor
50+
Remove() common.Executor
51+
Close() common.Executor
52+
ReplaceLogWriter(io.Writer, io.Writer) (io.Writer, io.Writer)
53+
}
54+
55+
// NewDockerBuildExecutorInput the input for the NewDockerBuildExecutor function
56+
type NewDockerBuildExecutorInput struct {
57+
ContextDir string
58+
Container Container
59+
ImageTag string
60+
Platform string
61+
}
62+
63+
// NewDockerPullExecutorInput the input for the NewDockerPullExecutor function
64+
type NewDockerPullExecutorInput struct {
65+
Image string
66+
ForcePull bool
67+
Platform string
68+
Username string
69+
Password string
70+
}

pkg/container/docker_auth.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (

pkg/container/docker_build.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (
@@ -16,14 +18,6 @@ import (
1618
"github.com/nektos/act/pkg/common"
1719
)
1820

19-
// NewDockerBuildExecutorInput the input for the NewDockerBuildExecutor function
20-
type NewDockerBuildExecutorInput struct {
21-
ContextDir string
22-
Container Container
23-
ImageTag string
24-
Platform string
25-
}
26-
2721
// NewDockerBuildExecutor function to create a run executor for the container
2822
func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
2923
return func(ctx context.Context) error {

pkg/container/docker_cli.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
// This file is exact copy of https://github.com/docker/cli/blob/9ac8584acfd501c3f4da0e845e3a40ed15c85041/cli/command/container/opts.go
24
// appended with license information.
35
//

pkg/container/docker_images.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (

pkg/container/docker_logger.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (

pkg/container/docker_pull.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (
@@ -12,15 +14,6 @@ import (
1214
"github.com/nektos/act/pkg/common"
1315
)
1416

15-
// NewDockerPullExecutorInput the input for the NewDockerPullExecutor function
16-
type NewDockerPullExecutorInput struct {
17-
Image string
18-
ForcePull bool
19-
Platform string
20-
Username string
21-
Password string
22-
}
23-
2417
// NewDockerPullExecutor function to create a run executor for the container
2518
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
2619
return func(ctx context.Context) error {

pkg/container/docker_run.go

+2-45
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (
@@ -38,51 +40,6 @@ import (
3840
"github.com/nektos/act/pkg/common"
3941
)
4042

41-
// NewContainerInput the input for the New function
42-
type NewContainerInput struct {
43-
Image string
44-
Username string
45-
Password string
46-
Entrypoint []string
47-
Cmd []string
48-
WorkingDir string
49-
Env []string
50-
Binds []string
51-
Mounts map[string]string
52-
Name string
53-
Stdout io.Writer
54-
Stderr io.Writer
55-
NetworkMode string
56-
Privileged bool
57-
UsernsMode string
58-
Platform string
59-
Options string
60-
}
61-
62-
// FileEntry is a file to copy to a container
63-
type FileEntry struct {
64-
Name string
65-
Mode int64
66-
Body string
67-
}
68-
69-
// Container for managing docker run containers
70-
type Container interface {
71-
Create(capAdd []string, capDrop []string) common.Executor
72-
Copy(destPath string, files ...*FileEntry) common.Executor
73-
CopyDir(destPath string, srcPath string, useGitIgnore bool) common.Executor
74-
GetContainerArchive(ctx context.Context, srcPath string) (io.ReadCloser, error)
75-
Pull(forcePull bool) common.Executor
76-
Start(attach bool) common.Executor
77-
Exec(command []string, env map[string]string, user, workdir string) common.Executor
78-
UpdateFromEnv(srcPath string, env *map[string]string) common.Executor
79-
UpdateFromImageEnv(env *map[string]string) common.Executor
80-
UpdateFromPath(env *map[string]string) common.Executor
81-
Remove() common.Executor
82-
Close() common.Executor
83-
ReplaceLogWriter(io.Writer, io.Writer) (io.Writer, io.Writer)
84-
}
85-
8643
// NewContainer creates a reference to a container
8744
func NewContainer(input *NewContainerInput) ExecutionsEnvironment {
8845
cr := new(containerReference)

pkg/container/docker_stub.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//go:build WITHOUT_DOCKER || !(linux || darwin || windows)
2+
3+
package container
4+
5+
import (
6+
"context"
7+
"runtime"
8+
9+
"github.com/docker/docker/api/types"
10+
"github.com/nektos/act/pkg/common"
11+
"github.com/pkg/errors"
12+
)
13+
14+
// ImageExistsLocally returns a boolean indicating if an image with the
15+
// requested name, tag and architecture exists in the local docker image store
16+
func ImageExistsLocally(ctx context.Context, imageName string, platform string) (bool, error) {
17+
return false, errors.New("Unsupported Operation")
18+
}
19+
20+
// RemoveImage removes image from local store, the function is used to run different
21+
// container image architectures
22+
func RemoveImage(ctx context.Context, imageName string, force bool, pruneChildren bool) (bool, error) {
23+
return false, errors.New("Unsupported Operation")
24+
}
25+
26+
// NewDockerBuildExecutor function to create a run executor for the container
27+
func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
28+
return func(ctx context.Context) error {
29+
return errors.New("Unsupported Operation")
30+
}
31+
}
32+
33+
// NewDockerPullExecutor function to create a run executor for the container
34+
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
35+
return func(ctx context.Context) error {
36+
return errors.New("Unsupported Operation")
37+
}
38+
}
39+
40+
// NewContainer creates a reference to a container
41+
func NewContainer(input *NewContainerInput) ExecutionsEnvironment {
42+
return nil
43+
}
44+
45+
func RunnerArch(ctx context.Context) string {
46+
return runtime.GOOS
47+
}
48+
49+
func GetHostInfo(ctx context.Context) (info types.Info, err error) {
50+
return types.Info{}, nil
51+
}
52+
53+
func NewDockerVolumeRemoveExecutor(volume string, force bool) common.Executor {
54+
return func(ctx context.Context) error {
55+
return nil
56+
}
57+
}

pkg/container/docker_volume.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows))
2+
13
package container
24

35
import (

0 commit comments

Comments
 (0)