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

act dind flag #2420

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Input struct {
networkName string
useNewActionCache bool
localRepository []string
dind bool
}

func (i *Input) resolve(path string) string {
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func Execute(ctx context.Context, version string) {
rootCmd.PersistentFlags().StringVarP(&input.networkName, "network", "", "host", "Sets a docker network name. Defaults to host.")
rootCmd.PersistentFlags().BoolVarP(&input.useNewActionCache, "use-new-action-cache", "", false, "Enable using the new Action Cache for storing Actions locally")
rootCmd.PersistentFlags().StringArrayVarP(&input.localRepository, "local-repository", "", []string{}, "Replaces the specified repository and ref with a local folder (e.g. https://github.com/test/test@v0=/home/act/test or test/test@v0=/home/act/test, the latter matches any hosts or protocols)")
rootCmd.PersistentFlags().BoolVarP(&input.dind, "dind", "", false, "Starts a dind container as a service to resolve most bind mount issues")
rootCmd.SetArgs(args())

if err := rootCmd.Execute(); err != nil {
Expand Down Expand Up @@ -568,6 +569,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
ReplaceGheActionTokenWithGithubCom: input.replaceGheActionTokenWithGithubCom,
Matrix: matrixes,
ContainerNetworkMode: docker_container.NetworkMode(input.networkName),
Dind: input.dind,
}
if input.useNewActionCache || len(input.localRepository) > 0 {
if input.actionOfflineMode {
Expand Down Expand Up @@ -639,7 +641,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
func defaultImageSurvey(actrc string) error {
var answer string
confirmation := &survey.Select{
Message: "Please choose the default image you want to use with act:\n - Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in " + configLocations()[0] + " (please refer to https://github.com/nektos/act#configuration for additional information about file structure)",
Message: "Please choose the default image you want to use with act:\n - Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images\n - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions\n - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions\n\nDefault image and other options can be changed manually in " + configLocations()[0] + " (please refer to https://github.com/nektos/act#configuration for additional information about file structure)",
Help: "If you want to know why act asks you that, please go to https://github.com/nektos/act/issues/107",
Default: "Medium",
Options: []string{"Large", "Medium", "Micro"},
Expand Down
38 changes: 34 additions & 4 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"fmt"
"io"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -131,7 +132,7 @@
}

binds := []string{}
if rc.Config.ContainerDaemonSocket != "-" {
if rc.Config.ContainerDaemonSocket != "-" && !rc.Config.Dind {
daemonPath := getDockerDaemonSocketMountPath(rc.Config.ContainerDaemonSocket)
binds = append(binds, fmt.Sprintf("%s:%s", daemonPath, "/var/run/docker.sock"))
}
Expand Down Expand Up @@ -343,15 +344,42 @@
rc.ServiceContainers = append(rc.ServiceContainers, c)
}

if rc.Config.Dind {
imageName := "docker:dind"

Check warning on line 348 in pkg/runner/run_context.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/run_context.go#L348

Added line #L348 was not covered by tests

serviceContainerName := createContainerName(rc.jobContainerName(), "act-dind")
c := container.NewContainer(&container.NewContainerInput{
Name: serviceContainerName,
WorkingDir: ext.ToContainerPath(rc.Config.Workdir),
Cmd: []string{
"--host",
"unix://" + path.Join(ext.GetActPath(), "docker.sock"),
},
Image: imageName,
Username: username,
Password: password,
Mounts: mounts,
Binds: binds,
Stdout: logWriter,
Stderr: logWriter,
Privileged: true,
UsernsMode: rc.Config.UsernsMode,
Platform: rc.Config.ContainerArchitecture,
NetworkMode: networkName,
Options: "--health-cmd=\"docker info\" --health-interval=10s --health-timeout=5s --health-retries=3",
})
rc.ServiceContainers = append(rc.ServiceContainers, c)

Check warning on line 371 in pkg/runner/run_context.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/run_context.go#L350-L371

Added lines #L350 - L371 were not covered by tests

envList = append(envList, fmt.Sprintf("%s=%s", "DOCKER_HOST", "unix://"+path.Join(ext.GetActPath(), "docker.sock")))

Check warning on line 373 in pkg/runner/run_context.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/run_context.go#L373

Added line #L373 was not covered by tests
}

rc.cleanUpJobContainer = func(ctx context.Context) error {
reuseJobContainer := func(ctx context.Context) bool {
return rc.Config.ReuseContainers
}

if rc.JobContainer != nil {
return rc.JobContainer.Remove().IfNot(reuseJobContainer).
Then(container.NewDockerVolumeRemoveExecutor(rc.jobContainerName(), false)).IfNot(reuseJobContainer).
Then(container.NewDockerVolumeRemoveExecutor(rc.jobContainerName()+"-env", false)).IfNot(reuseJobContainer).
Then(func(ctx context.Context) error {
if len(rc.ServiceContainers) > 0 {
logger.Infof("Cleaning up services for job %s", rc.JobName)
Expand All @@ -370,7 +398,9 @@
}
}
return nil
})(ctx)
}).
Then(container.NewDockerVolumeRemoveExecutor(rc.jobContainerName(), false)).IfNot(reuseJobContainer).
Then(container.NewDockerVolumeRemoveExecutor(rc.jobContainerName()+"-env", false)).IfNot(reuseJobContainer)(ctx)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Config struct {
Matrix map[string]map[string]bool // Matrix config to run
ContainerNetworkMode docker_container.NetworkMode // the network mode of job containers (the value of --network)
ActionCache ActionCache // Use a custom ActionCache Implementation
Dind bool
}

type caller struct {
Expand Down
Loading