diff --git a/act/container/docker_build.go b/act/container/docker_build.go index 5f56ec70..cb08efb1 100644 --- a/act/container/docker_build.go +++ b/act/container/docker_build.go @@ -73,7 +73,7 @@ func createBuildContext(ctx context.Context, contextDir string, relDockerfile st common.Logger(ctx).Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile) // And canonicalize dockerfile name to a platform-independent one - relDockerfile = archive.CanonicalTarNameForPath(relDockerfile) + relDockerfile = filepath.ToSlash(relDockerfile) f, err := os.Open(filepath.Join(contextDir, ".dockerignore")) if err != nil && !os.IsNotExist(err) { diff --git a/act/container/docker_images.go b/act/container/docker_images.go index 50ec68da..3d6f6928 100644 --- a/act/container/docker_images.go +++ b/act/container/docker_images.go @@ -6,7 +6,7 @@ import ( "context" "fmt" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/client" ) @@ -42,14 +42,14 @@ func RemoveImage(ctx context.Context, imageName string, force bool, pruneChildre } defer cli.Close() - inspectImage, _, err := cli.ImageInspectWithRaw(ctx, imageName) + inspectImage, err := cli.ImageInspect(ctx, imageName) if client.IsErrNotFound(err) { return false, nil } else if err != nil { return false, err } - if _, err = cli.ImageRemove(ctx, inspectImage.ID, types.ImageRemoveOptions{ + if _, err = cli.ImageRemove(ctx, inspectImage.ID, image.RemoveOptions{ Force: force, PruneChildren: pruneChildren, }); err != nil { diff --git a/act/container/docker_images_test.go b/act/container/docker_images_test.go index cf13f435..a6612832 100644 --- a/act/container/docker_images_test.go +++ b/act/container/docker_images_test.go @@ -5,7 +5,7 @@ import ( "io" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/client" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -40,7 +40,7 @@ func TestImageExistsLocally(t *testing.T) { // Chose alpine latest because it's so small // maybe we should build an image instead so that tests aren't reliable on dockerhub - readerDefault, err := cli.ImagePull(ctx, "node:16-buster-slim", types.ImagePullOptions{ + readerDefault, err := cli.ImagePull(ctx, "node:16-buster-slim", image.PullOptions{ Platform: "linux/amd64", }) assert.Nil(t, err) @@ -53,7 +53,7 @@ func TestImageExistsLocally(t *testing.T) { assert.Equal(t, true, imageDefaultArchExists) // Validate if another architecture platform can be pulled - readerArm64, err := cli.ImagePull(ctx, "node:16-buster-slim", types.ImagePullOptions{ + readerArm64, err := cli.ImagePull(ctx, "node:16-buster-slim", image.PullOptions{ Platform: "linux/arm64", }) assert.Nil(t, err) diff --git a/act/container/docker_network.go b/act/container/docker_network.go index e97d8f73..111acd13 100644 --- a/act/container/docker_network.go +++ b/act/container/docker_network.go @@ -5,11 +5,11 @@ package container import ( "context" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/network" "github.com/nektos/act/pkg/common" ) -func NewDockerNetworkCreateExecutor(name string, config *types.NetworkCreate) common.Executor { +func NewDockerNetworkCreateExecutor(name string, config *network.CreateOptions) common.Executor { return func(ctx context.Context) error { cli, err := GetDockerClient(ctx) if err != nil { @@ -18,7 +18,7 @@ func NewDockerNetworkCreateExecutor(name string, config *types.NetworkCreate) co defer cli.Close() // Only create the network if it doesn't exist - networks, err := cli.NetworkList(ctx, types.NetworkListOptions{}) + networks, err := cli.NetworkList(ctx, network.ListOptions{}) if err != nil { return err } @@ -48,20 +48,20 @@ func NewDockerNetworkRemoveExecutor(name string) common.Executor { // Make shure that all network of the specified name are removed // cli.NetworkRemove refuses to remove a network if there are duplicates - networks, err := cli.NetworkList(ctx, types.NetworkListOptions{}) + networks, err := cli.NetworkList(ctx, network.ListOptions{}) if err != nil { return err } common.Logger(ctx).Debugf("%v", networks) - for _, network := range networks { - if network.Name == name { - result, err := cli.NetworkInspect(ctx, network.ID, types.NetworkInspectOptions{}) + for _, net := range networks { + if net.Name == name { + result, err := cli.NetworkInspect(ctx, net.ID, network.InspectOptions{}) if err != nil { return err } if len(result.Containers) == 0 { - if err = cli.NetworkRemove(ctx, network.ID); err != nil { + if err = cli.NetworkRemove(ctx, net.ID); err != nil { common.Logger(ctx).Debugf("%v", err) } } else { diff --git a/act/container/docker_pull.go b/act/container/docker_pull.go index 529d1c8c..65b930ee 100644 --- a/act/container/docker_pull.go +++ b/act/container/docker_pull.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/distribution/reference" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" "github.com/nektos/act/pkg/common" @@ -74,8 +74,8 @@ func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor { } } -func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput) (types.ImagePullOptions, error) { - imagePullOptions := types.ImagePullOptions{ +func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput) (image.PullOptions, error) { + imagePullOptions := image.PullOptions{ Platform: input.Platform, } logger := common.Logger(ctx) diff --git a/act/container/docker_run.go b/act/container/docker_run.go index 02e4dbfb..64b29909 100644 --- a/act/container/docker_run.go +++ b/act/container/docker_run.go @@ -24,6 +24,7 @@ import ( "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/network" networktypes "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/system" "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" "github.com/go-git/go-billy/v5/helper/polyfill" @@ -234,7 +235,7 @@ func GetDockerClient(ctx context.Context) (cli client.APIClient, err error) { return cli, nil } -func GetHostInfo(ctx context.Context) (info types.Info, err error) { +func GetHostInfo(ctx context.Context) (info system.Info, err error) { var cli client.APIClient cli, err = GetDockerClient(ctx) if err != nil { @@ -304,7 +305,7 @@ func (cr *containerReference) find() common.Executor { if cr.id != "" { return nil } - containers, err := cr.cli.ContainerList(ctx, types.ContainerListOptions{ + containers, err := cr.cli.ContainerList(ctx, container.ListOptions{ All: true, }) if err != nil { @@ -332,7 +333,7 @@ func (cr *containerReference) remove() common.Executor { } logger := common.Logger(ctx) - err := cr.cli.ContainerRemove(ctx, cr.id, types.ContainerRemoveOptions{ + err := cr.cli.ContainerRemove(ctx, cr.id, container.RemoveOptions{ RemoveVolumes: true, Force: true, }) @@ -642,7 +643,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string, user, wo } logger.Debugf("Working directory '%s'", wd) - idResp, err := cr.cli.ContainerExecCreate(ctx, cr.id, types.ExecConfig{ + idResp, err := cr.cli.ContainerExecCreate(ctx, cr.id, container.ExecOptions{ User: user, Cmd: cmd, WorkingDir: wd, @@ -655,7 +656,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string, user, wo return fmt.Errorf("failed to create exec: %w", err) } - resp, err := cr.cli.ContainerExecAttach(ctx, idResp.ID, types.ExecStartCheck{ + resp, err := cr.cli.ContainerExecAttach(ctx, idResp.ID, container.ExecAttachOptions{ Tty: isTerminal, }) if err != nil { @@ -686,7 +687,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string, user, wo func (cr *containerReference) tryReadID(opt string, cbk func(id int)) common.Executor { return func(ctx context.Context) error { - idResp, err := cr.cli.ContainerExecCreate(ctx, cr.id, types.ExecConfig{ + idResp, err := cr.cli.ContainerExecCreate(ctx, cr.id, container.ExecOptions{ Cmd: []string{"id", opt}, AttachStdout: true, AttachStderr: true, @@ -695,7 +696,7 @@ func (cr *containerReference) tryReadID(opt string, cbk func(id int)) common.Exe return nil } - resp, err := cr.cli.ContainerExecAttach(ctx, idResp.ID, types.ExecStartCheck{}) + resp, err := cr.cli.ContainerExecAttach(ctx, idResp.ID, container.ExecAttachOptions{}) if err != nil { return nil } @@ -780,12 +781,12 @@ func (cr *containerReference) CopyTarStream(ctx context.Context, destPath string Typeflag: tar.TypeDir, }) tw.Close() - err := cr.cli.CopyToContainer(ctx, cr.id, "/", buf, types.CopyToContainerOptions{}) + err := cr.cli.CopyToContainer(ctx, cr.id, "/", buf, container.CopyToContainerOptions{}) if err != nil { return fmt.Errorf("failed to mkdir to copy content to container: %w", err) } // Copy Content - err = cr.cli.CopyToContainer(ctx, cr.id, destPath, tarStream, types.CopyToContainerOptions{}) + err = cr.cli.CopyToContainer(ctx, cr.id, destPath, tarStream, container.CopyToContainerOptions{}) if err != nil { return fmt.Errorf("failed to copy content to container: %w", err) } @@ -861,7 +862,7 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgno if err != nil { return fmt.Errorf("failed to seek tar archive: %w", err) } - err = cr.cli.CopyToContainer(ctx, cr.id, "/", tarFile, types.CopyToContainerOptions{}) + err = cr.cli.CopyToContainer(ctx, cr.id, "/", tarFile, container.CopyToContainerOptions{}) if err != nil { return fmt.Errorf("failed to copy content to container: %w", err) } @@ -895,7 +896,7 @@ func (cr *containerReference) copyContent(dstPath string, files ...*FileEntry) c } logger.Debugf("Extracting content to '%s'", dstPath) - err := cr.cli.CopyToContainer(ctx, cr.id, dstPath, &buf, types.CopyToContainerOptions{}) + err := cr.cli.CopyToContainer(ctx, cr.id, dstPath, &buf, container.CopyToContainerOptions{}) if err != nil { return fmt.Errorf("failed to copy content to container: %w", err) } @@ -905,7 +906,7 @@ func (cr *containerReference) copyContent(dstPath string, files ...*FileEntry) c func (cr *containerReference) attach() common.Executor { return func(ctx context.Context) error { - out, err := cr.cli.ContainerAttach(ctx, cr.id, types.ContainerAttachOptions{ + out, err := cr.cli.ContainerAttach(ctx, cr.id, container.AttachOptions{ Stream: true, Stdout: true, Stderr: true, @@ -943,7 +944,7 @@ func (cr *containerReference) start() common.Executor { logger := common.Logger(ctx) logger.Debugf("Starting container: %v", cr.id) - if err := cr.cli.ContainerStart(ctx, cr.id, types.ContainerStartOptions{}); err != nil { + if err := cr.cli.ContainerStart(ctx, cr.id, container.StartOptions{}); err != nil { return fmt.Errorf("failed to start container: %w", err) } diff --git a/act/container/docker_run_test.go b/act/container/docker_run_test.go index 14af789f..81e7a013 100644 --- a/act/container/docker_run_test.go +++ b/act/container/docker_run_test.go @@ -70,22 +70,22 @@ type mockDockerClient struct { mock.Mock } -func (m *mockDockerClient) ContainerExecCreate(ctx context.Context, id string, opts types.ExecConfig) (types.IDResponse, error) { +func (m *mockDockerClient) ContainerExecCreate(ctx context.Context, id string, opts container.ExecOptions) (container.ExecCreateResponse, error) { args := m.Called(ctx, id, opts) - return args.Get(0).(types.IDResponse), args.Error(1) + return args.Get(0).(container.ExecCreateResponse), args.Error(1) } -func (m *mockDockerClient) ContainerExecAttach(ctx context.Context, id string, opts types.ExecStartCheck) (types.HijackedResponse, error) { +func (m *mockDockerClient) ContainerExecAttach(ctx context.Context, id string, opts container.ExecAttachOptions) (types.HijackedResponse, error) { args := m.Called(ctx, id, opts) return args.Get(0).(types.HijackedResponse), args.Error(1) } -func (m *mockDockerClient) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) { +func (m *mockDockerClient) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) { args := m.Called(ctx, execID) - return args.Get(0).(types.ContainerExecInspect), args.Error(1) + return args.Get(0).(container.ExecInspect), args.Error(1) } -func (m *mockDockerClient) CopyToContainer(ctx context.Context, id string, path string, content io.Reader, options types.CopyToContainerOptions) error { +func (m *mockDockerClient) CopyToContainer(ctx context.Context, id string, path string, content io.Reader, options container.CopyToContainerOptions) error { args := m.Called(ctx, id, path, content, options) return args.Error(0) } @@ -119,8 +119,9 @@ func TestDockerExecAbort(t *testing.T) { conn.On("Write", mock.AnythingOfType("[]uint8")).Return(1, nil) client := &mockDockerClient{} - client.On("ContainerExecCreate", ctx, "123", mock.AnythingOfType("types.ExecConfig")).Return(types.IDResponse{ID: "id"}, nil) - client.On("ContainerExecAttach", ctx, "id", mock.AnythingOfType("types.ExecStartCheck")).Return(types.HijackedResponse{ + client.On("ContainerExecCreate", ctx, "123", mock.AnythingOfType("container.ExecOptions")).Return(container.ExecCreateResponse{ID: "id"}, nil) + // container.ExecStartOptions should be container.ExecAttachOptions but fails + client.On("ContainerExecAttach", ctx, "id", mock.AnythingOfType("container.ExecStartOptions")).Return(types.HijackedResponse{ Conn: conn, Reader: bufio.NewReader(endlessReader{}), }, nil) @@ -156,12 +157,13 @@ func TestDockerExecFailure(t *testing.T) { conn := &mockConn{} client := &mockDockerClient{} - client.On("ContainerExecCreate", ctx, "123", mock.AnythingOfType("types.ExecConfig")).Return(types.IDResponse{ID: "id"}, nil) - client.On("ContainerExecAttach", ctx, "id", mock.AnythingOfType("types.ExecStartCheck")).Return(types.HijackedResponse{ + client.On("ContainerExecCreate", ctx, "123", mock.AnythingOfType("container.ExecOptions")).Return(container.ExecCreateResponse{ID: "id"}, nil) + // container.ExecStartOptions should be container.ExecAttachOptions but fails + client.On("ContainerExecAttach", ctx, "id", mock.AnythingOfType("container.ExecStartOptions")).Return(types.HijackedResponse{ Conn: conn, Reader: bufio.NewReader(strings.NewReader("output")), }, nil) - client.On("ContainerExecInspect", ctx, "id").Return(types.ContainerExecInspect{ + client.On("ContainerExecInspect", ctx, "id").Return(container.ExecInspect{ ExitCode: 1, }, nil) @@ -186,8 +188,8 @@ func TestDockerCopyTarStream(t *testing.T) { conn := &mockConn{} client := &mockDockerClient{} - client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(nil) - client.On("CopyToContainer", ctx, "123", "/var/run/act", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(nil) + client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("container.CopyToContainerOptions")).Return(nil) + client.On("CopyToContainer", ctx, "123", "/var/run/act", mock.Anything, mock.AnythingOfType("container.CopyToContainerOptions")).Return(nil) cr := &containerReference{ id: "123", cli: client, @@ -210,8 +212,8 @@ func TestDockerCopyTarStreamErrorInCopyFiles(t *testing.T) { merr := fmt.Errorf("Failure") client := &mockDockerClient{} - client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(merr) - client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(merr) + client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("container.CopyToContainerOptions")).Return(merr) + client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("container.CopyToContainerOptions")).Return(merr) cr := &containerReference{ id: "123", cli: client, @@ -235,8 +237,8 @@ func TestDockerCopyTarStreamErrorInMkdir(t *testing.T) { merr := fmt.Errorf("Failure") client := &mockDockerClient{} - client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(nil) - client.On("CopyToContainer", ctx, "123", "/var/run/act", mock.Anything, mock.AnythingOfType("types.CopyToContainerOptions")).Return(merr) + client.On("CopyToContainer", ctx, "123", "/", mock.Anything, mock.AnythingOfType("container.CopyToContainerOptions")).Return(nil) + client.On("CopyToContainer", ctx, "123", "/var/run/act", mock.Anything, mock.AnythingOfType("container.CopyToContainerOptions")).Return(merr) cr := &containerReference{ id: "123", cli: client, diff --git a/act/container/docker_stub.go b/act/container/docker_stub.go index 155d5abb..d476f300 100644 --- a/act/container/docker_stub.go +++ b/act/container/docker_stub.go @@ -6,7 +6,8 @@ import ( "context" "runtime" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/system" "github.com/nektos/act/pkg/common" "github.com/pkg/errors" ) @@ -46,8 +47,8 @@ func RunnerArch(ctx context.Context) string { return runtime.GOOS } -func GetHostInfo(ctx context.Context) (info types.Info, err error) { - return types.Info{}, nil +func GetHostInfo(ctx context.Context) (info system.Info, err error) { + return system.Info{}, nil } func NewDockerVolumeRemoveExecutor(volume string, force bool) common.Executor { @@ -56,7 +57,7 @@ func NewDockerVolumeRemoveExecutor(volume string, force bool) common.Executor { } } -func NewDockerNetworkCreateExecutor(name string, config *types.NetworkCreate) common.Executor { +func NewDockerNetworkCreateExecutor(name string, config *network.CreateOptions) common.Executor { return func(ctx context.Context) error { return nil } diff --git a/act/runner/run_context.go b/act/runner/run_context.go index d726aa41..649095ab 100644 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -20,7 +20,7 @@ import ( "strings" "text/template" - docker "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/network" "github.com/docker/go-connections/nat" "github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/container" @@ -561,10 +561,10 @@ func (rc *RunContext) startJobContainer() common.Executor { return errors.New("Failed to create job container") } - networkConfig := docker.NetworkCreate{ + networkConfig := network.CreateOptions{ Driver: "bridge", Scope: "local", - EnableIPv6: rc.Config.ContainerNetworkEnableIPv6, + EnableIPv6: &rc.Config.ContainerNetworkEnableIPv6, } return common.NewPipelineExecutor( rc.pullServicesImages(rc.Config.ForcePull),