-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: tart macOS vm's as job container #2434
base: master
Are you sure you want to change the base?
Changes from all commits
ec7f288
0be92a8
b751b59
e4d7c63
2941e25
6c9ee6b
2b1fefe
538618a
e18951c
5512718
22d5a80
ae8e5ca
175ea58
01897b9
ce5d63f
bb077bc
706746e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package runner | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"encoding/hex" | ||
"fmt" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/nektos/act/pkg/common" | ||
"github.com/nektos/act/pkg/container" | ||
"github.com/nektos/act/pkg/tart" | ||
) | ||
|
||
func (rc *RunContext) startTartEnvironment() common.Executor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This started as a copy of hostenvironment, but is now different |
||
return func(ctx context.Context) error { | ||
logger := common.Logger(ctx) | ||
rawLogger := logger.WithField("raw_output", true) | ||
logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) bool { | ||
if rc.Config.LogOutput { | ||
rawLogger.Infof("%s", s) | ||
} else { | ||
rawLogger.Debugf("%s", s) | ||
} | ||
return true | ||
}) | ||
cacheDir := rc.ActionCacheDir() | ||
randBytes := make([]byte, 8) | ||
_, _ = rand.Read(randBytes) | ||
miscpath := filepath.Join(cacheDir, hex.EncodeToString(randBytes)) | ||
actPath := filepath.Join(miscpath, "act") | ||
if err := os.MkdirAll(actPath, 0o777); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
return err | ||
} | ||
path := filepath.Join(miscpath, "hostexecutor") | ||
if err := os.MkdirAll(path, 0o777); err != nil { | ||
return err | ||
} | ||
runnerTmp := filepath.Join(miscpath, "tmp") | ||
if err := os.MkdirAll(runnerTmp, 0o777); err != nil { | ||
return err | ||
} | ||
toolCache := filepath.Join(cacheDir, "tool_cache") | ||
platImage := rc.runsOnImage(ctx) | ||
platURI, _ := url.Parse(platImage) | ||
query := platURI.Query() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that I'm smart, but no providing options in the |
||
tenv := &tart.Environment{ | ||
HostEnvironment: container.HostEnvironment{ | ||
Path: path, | ||
TmpDir: runnerTmp, | ||
ToolCache: toolCache, | ||
Workdir: rc.Config.Workdir, | ||
ActPath: actPath, | ||
CleanUp: func() { | ||
os.RemoveAll(miscpath) | ||
}, | ||
StdOut: logWriter, | ||
}, | ||
Config: tart.Config{ | ||
SSHUsername: "admin", | ||
SSHPassword: "admin", | ||
Softnet: query.Get("softnet") == "1", | ||
Headless: query.Get("headless") != "0", | ||
AlwaysPull: query.Get("pull") != "0", | ||
}, | ||
Env: &tart.Env{ | ||
JobImage: platURI.Host + platURI.EscapedPath(), | ||
JobID: rc.jobContainerName(), | ||
}, | ||
Miscpath: miscpath, | ||
} | ||
rc.JobContainer = tenv | ||
if query.Has("sshusername") { | ||
tenv.Config.SSHUsername = query.Get("sshusername") | ||
} | ||
if query.Has("sshpassword") { | ||
tenv.Config.SSHPassword = query.Get("sshpassword") | ||
} | ||
rc.cleanUpJobContainer = rc.JobContainer.Remove() | ||
for k, v := range rc.JobContainer.GetRunnerContext(ctx) { | ||
if v, ok := v.(string); ok { | ||
rc.Env[fmt.Sprintf("RUNNER_%s", strings.ToUpper(k))] = v | ||
} | ||
} | ||
// for _, env := range os.Environ() { | ||
// if k, v, ok := strings.Cut(env, "="); ok { | ||
// // don't override | ||
// if _, ok := rc.Env[k]; !ok { | ||
// rc.Env[k] = v | ||
// } | ||
// } | ||
// } | ||
|
||
return common.NewPipelineExecutor( | ||
// rc.JobContainer.Remove(), | ||
rc.JobContainer.Start(false), | ||
rc.JobContainer.Copy(rc.JobContainer.GetActPath()+"/", &container.FileEntry{ | ||
Name: "workflow/event.json", | ||
Mode: 0o644, | ||
Body: rc.EventJSON, | ||
}, &container.FileEntry{ | ||
Name: "workflow/envs.txt", | ||
Mode: 0o666, | ||
Body: "", | ||
}), | ||
)(ctx) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//go:build !darwin | ||
|
||
package runner | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/nektos/act/pkg/common" | ||
) | ||
|
||
func (rc *RunContext) startTartEnvironment() common.Executor { | ||
return func(_ context.Context) error { | ||
return fmt.Errorf("You need macOS for tart") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone thinks to run this mode on another OS, abort as tart is not available and some syscall part doesn't compile anyway.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tart | ||
|
||
type Config struct { | ||
SSHUsername string | ||
SSHPassword string | ||
Softnet bool | ||
Headless bool | ||
AlwaysPull bool | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package tart | ||
|
||
type Env struct { | ||
JobID string | ||
JobImage string | ||
FailureExitCode int | ||
Registry *Registry | ||
} | ||
|
||
type Registry struct { | ||
Address string | ||
User string | ||
Password string | ||
} | ||
|
||
func (e Env) VirtualMachineID() string { | ||
return e.JobID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm reusing the docker container names used by containers, so no prefix and so on |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like
-self-hosted
, but withtart://
. I forget this variant has only been used in act_runner as of now, but looks better.