-
-
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: cli option to enable the new action cache #1954
Changes from 12 commits
d620ca7
b8a5410
64df8ae
be5d3a4
b497266
7e7f4b2
13ffce7
5c1c3b7
509df53
05c91d6
48364c6
d1ada52
0cee15c
354d9d0
a1a5869
139998c
ff9dd6a
f8226cd
cc6ca22
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 |
---|---|---|
|
@@ -240,8 +240,8 @@ | |
|
||
archMapper := map[string]string{ | ||
"x86_64": "X64", | ||
"386": "X86", | ||
"aarch64": "ARM64", | ||
} | ||
if arch, ok := archMapper[info.Architecture]; ok { | ||
return arch | ||
|
@@ -345,13 +345,13 @@ | |
return nil, nil, fmt.Errorf("Cannot parse container options: '%s': '%w'", input.Options, err) | ||
} | ||
|
||
if len(copts.netMode.Value()) == 0 { | ||
if err = copts.netMode.Set("host"); err != nil { | ||
return nil, nil, fmt.Errorf("Cannot parse networkmode=host. This is an internal error and should not happen: '%w'", err) | ||
} | ||
} | ||
|
||
containerConfig, err := parse(flags, copts, runtime.GOOS) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("Cannot process container options: '%s': '%w'", input.Options, err) | ||
} | ||
|
@@ -586,7 +586,7 @@ | |
} | ||
exp := regexp.MustCompile(`\d+\n`) | ||
found := exp.FindString(sid) | ||
id, err := strconv.ParseInt(strings.TrimSpace(found), 10, 32) | ||
if err != nil { | ||
return nil | ||
} | ||
|
@@ -649,12 +649,30 @@ | |
} | ||
} | ||
|
||
func (cr *containerReference) CopyTarStream(ctx context.Context, destPath string, tarStream io.Reader) error { | ||
err := cr.cli.CopyToContainer(ctx, cr.id, destPath, tarStream, types.CopyToContainerOptions{}) | ||
// Mkdir | ||
buf := &bytes.Buffer{} | ||
tw := tar.NewWriter(buf) | ||
_ = tw.WriteHeader(&tar.Header{ | ||
Name: destPath, | ||
Mode: 777, | ||
Typeflag: tar.TypeDir, | ||
}) | ||
tw.Close() | ||
err := cr.cli.CopyToContainer(ctx, cr.id, "/", buf, types.CopyToContainerOptions{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to mkdir to copy content to container: %w", err) | ||
} | ||
Comment on lines
+674
to
+686
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. The second CopyToContainer would fail with destPath doesn't exists. |
||
// Copy Content | ||
err = cr.cli.CopyToContainer(ctx, cr.id, destPath, tarStream, types.CopyToContainerOptions{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to copy content to container: %w", err) | ||
} | ||
// If this fails, then folders have wrong permissions on non root container | ||
if cr.UID != 0 || cr.GID != 0 { | ||
_ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), destPath}, nil, "0", "")(ctx) | ||
} | ||
Comment on lines
+692
to
+695
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. As before we need to fix folder ownership |
||
return nil | ||
} | ||
|
||
func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgnore bool) common.Executor { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ | |
stepStagePost | ||
) | ||
|
||
// Controls how many symlinks are resolved for local and remote Actions | ||
const maxSymlinkDepth = 10 | ||
|
||
func (s stepStage) String() string { | ||
switch s { | ||
case stepStagePre: | ||
|
@@ -50,8 +53,8 @@ | |
env := map[string]string{} | ||
err := rc.JobContainer.UpdateFromEnv(path.Join(rc.JobContainer.GetActPath(), fileName), &env)(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
for k, v := range env { | ||
setter(ctx, map[string]string{"name": k}, v) | ||
} | ||
|
@@ -173,7 +176,7 @@ | |
} | ||
err = processRunnerEnvFileCommand(ctx, outputFileCommand, rc, rc.setOutput) | ||
if err != nil { | ||
return err | ||
} | ||
err = rc.UpdateExtraPath(ctx, path.Join(actPath, pathFileCommand)) | ||
if err != nil { | ||
|
@@ -189,9 +192,9 @@ | |
func evaluateStepTimeout(ctx context.Context, exprEval ExpressionEvaluator, stepModel *model.Step) (context.Context, context.CancelFunc) { | ||
timeout := exprEval.Interpolate(ctx, stepModel.TimeoutMinutes) | ||
if timeout != "" { | ||
if timeOutMinutes, err := strconv.ParseInt(timeout, 10, 64); err == nil { | ||
return context.WithTimeout(ctx, time.Duration(timeOutMinutes)*time.Minute) | ||
} | ||
} | ||
return ctx, func() {} | ||
} | ||
|
@@ -274,7 +277,7 @@ | |
|
||
func mergeIntoMap(step step, target *map[string]string, maps ...map[string]string) { | ||
if rc := step.getRunContext(); rc != nil && rc.JobContainer != nil && rc.JobContainer.IsEnvironmentCaseInsensitive() { | ||
mergeIntoMapCaseInsensitive(*target, maps...) | ||
} else { | ||
mergeIntoMapCaseSensitive(*target, maps...) | ||
} | ||
|
@@ -298,8 +301,8 @@ | |
if k, ok := foldKeys[foldKey]; ok { | ||
return k | ||
} | ||
foldKeys[strings.ToLower(foldKey)] = s | ||
return s | ||
} | ||
for _, m := range maps { | ||
for k, v := range m { | ||
|
@@ -307,3 +310,13 @@ | |
} | ||
} | ||
} | ||
|
||
func symlinkJoin(filename, sym, parent string) (string, error) { | ||
dir := path.Dir(filename) | ||
dest := path.Join(dir, sym) | ||
prefix := path.Clean(parent) + "/" | ||
if strings.HasPrefix(dest, prefix) || prefix == "./" { | ||
return dest, nil | ||
} | ||
return "", fmt.Errorf("symlink tries to access file '%s' outside of '%s'", strings.ReplaceAll(dest, "'", "''"), strings.ReplaceAll(parent, "'", "''")) | ||
} | ||
Comment on lines
+314
to
+322
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 forget that |
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.
Enabled behind feature cli flag:
--use-new-action-cache
, old code has been restored.