From cbd21b8ec539a5def5649b10702e55f6656e2ee9 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 8 Nov 2022 18:35:13 +0800 Subject: [PATCH] feat: avoid reuse of containers --- go.mod | 2 +- go.sum | 6 ++---- runtime/task.go | 13 ++++--------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 4407184..6a16d26 100644 --- a/go.mod +++ b/go.mod @@ -72,4 +72,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/nektos/act => gitea.com/gitea/act v0.0.0-20220922135643-52a5bba9e7fa +replace github.com/nektos/act => gitea.com/gitea/act v0.0.0-20221108101106-28099ee68a88 diff --git a/go.sum b/go.sum index dd34da3..e92a47c 100644 --- a/go.sum +++ b/go.sum @@ -23,10 +23,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -gitea.com/gitea/act v0.0.0-20220922135643-52a5bba9e7fa h1:HHqlvfIvqFlny3sgJgAM1BYeLNr1uM4yXtvF7aAoYK8= -gitea.com/gitea/act v0.0.0-20220922135643-52a5bba9e7fa/go.mod h1:9W/Nz16tjfnWp7O5DUo3EjZBnZFBI/5rlWstX4o7+hU= -gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b h1:TSz7VRHfnM/5JwGPgIAjSlDIvcr4pTGfuRMtgMxttmg= -gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= +gitea.com/gitea/act v0.0.0-20221108101106-28099ee68a88 h1:pfeGhadGGQbQuXqIgi/C6NQ+VopNEkHayz49IgANPAg= +gitea.com/gitea/act v0.0.0-20221108101106-28099ee68a88/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo= gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835 h1:27PhT7Nli/pgRo1bDYVZ+hlCKuF9cfFuo+y9muaPVJY= gitea.com/gitea/proto-go v0.0.0-20221028125601-35c4f6b05835/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= diff --git a/runtime/task.go b/runtime/task.go index d0b5894..1464411 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -72,7 +72,7 @@ type Task struct { func NewTask(forgeInstance string, buildID int64, client client.Client, runnerEnvs map[string]string) *Task { task := &Task{ Input: &TaskInput{ - reuseContainers: true, + reuseContainers: false, ForgeInstance: forgeInstance, envs: runnerEnvs, }, @@ -166,12 +166,6 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { log.Infof("plan: %+v", plan.Stages[0].Runs) - curDir, err := os.Getwd() - if err != nil { - lastWords = err.Error() - return err - } - token := getToken(task) dataContext := task.Context.Fields @@ -202,13 +196,14 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { input := t.Input config := &runner.Config{ - Workdir: curDir, // TODO: temp dir? + Workdir: "/root", BindWorkdir: input.bindWorkdir, ReuseContainers: input.reuseContainers, ForcePull: input.forcePull, ForceRebuild: input.forceRebuild, LogOutput: true, JSONLogger: input.jsonLogger, + Env: input.envs, Secrets: task.Secrets, InsecureSecrets: input.insecureSecrets, Platforms: demoPlatforms(), // TODO: supported platforms @@ -226,7 +221,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error { NoSkipCheckout: input.noSkipCheckout, PresetGitHubContext: preset, EventJSON: string(eventJSON), - Env: t.Input.envs, + ContainerNamePrefix: fmt.Sprintf("gitea-task-%d", task.Id), } r, err := runner.New(config) if err != nil {