From e3271d8469b605cc1a380b6e1e835aff6178170a Mon Sep 17 00:00:00 2001 From: harryzcy Date: Mon, 22 May 2023 23:50:29 +0800 Subject: [PATCH 1/6] Remove trailing slash from instance address (#197) Related #136 Co-authored-by: harryzcy Reviewed-on: https://gitea.com/gitea/act_runner/pulls/197 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: harryzcy Co-committed-by: harryzcy --- internal/app/run/runner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index b07e59c..a36adad 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -184,7 +184,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. JSONLogger: false, Env: r.envs, Secrets: task.Secrets, - GitHubInstance: r.client.Address(), + GitHubInstance: strings.TrimSuffix(r.client.Address(), "/"), AutoRemove: true, NoSkipCheckout: true, PresetGitHubContext: preset, From a384adbbc618be293924cc2cf650379aa148c59c Mon Sep 17 00:00:00 2001 From: Chris Cureau Date: Mon, 5 Jun 2023 08:46:15 +0000 Subject: [PATCH 2/6] Documentation enhancements (#207) This PR addresses the issue listed in issue #170 regarding how to set up rootless Docker. It also expands on the documentation to show how to create deployments for different environments. Co-authored-by: ccureau Reviewed-on: https://gitea.com/gitea/act_runner/pulls/207 Reviewed-by: Jason Song Co-authored-by: Chris Cureau Co-committed-by: Chris Cureau --- README.md | 30 +--------- examples/README.md | 16 +++++ examples/docker-compose/README.md | 20 +++++++ examples/docker/README.md | 8 +++ examples/kubernetes/README.md | 8 +++ examples/kubernetes/dind-docker.yaml | 78 +++++++++++++++++++++++++ examples/vm/README.md | 6 ++ examples/vm/rootless-docker.md | 87 ++++++++++++++++++++++++++++ 8 files changed, 225 insertions(+), 28 deletions(-) create mode 100644 examples/README.md create mode 100644 examples/docker-compose/README.md create mode 100644 examples/docker/README.md create mode 100644 examples/kubernetes/README.md create mode 100644 examples/kubernetes/dind-docker.yaml create mode 100644 examples/vm/README.md create mode 100644 examples/vm/rootless-docker.md diff --git a/README.md b/README.md index 9fbb75b..f031dca 100644 --- a/README.md +++ b/README.md @@ -88,32 +88,6 @@ You can specify the configuration file path with `-c`/`--config` argument. ./act_runner -c config.yaml daemon # run with config file ``` -### Run a docker container +### Example Deployments -```sh -docker run -e GITEA_INSTANCE_URL=http://192.168.8.18:3000 -e GITEA_RUNNER_REGISTRATION_TOKEN= -v /var/run/docker.sock:/var/run/docker.sock -v $PWD/data:/data --name my_runner gitea/act_runner:nightly -``` - -The `/data` directory inside the docker container contains the runner API keys after registration. -It must be persisted, otherwise the runner would try to register again, using the same, now defunct registration token. - -### Running in docker-compose - -```yml -... - gitea: - image: gitea/gitea - ... - - runner: - image: gitea/act_runner - restart: always - depends_on: - - gitea - volumes: - - ./data/act_runner:/data - - /var/run/docker.sock:/var/run/docker.sock - environment: - - GITEA_INSTANCE_URL= - - GITEA_RUNNER_REGISTRATION_TOKEN= -``` +Check out the [examples](examples) directory for sample deployment types. diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..83439c7 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,16 @@ +## Usage Examples for `act_runner` + +Here you will find usage and deployment examples that can be directly used in a Gitea setup. Please feel free to contribute! + + +- [`docker`](docker) + Contains scripts and instructions for running containers on a workstation or server with Docker installed. + +- [`docker-compose`](docker-compose) + Contains examples of using `docker-compose` to manage deployments. + +- [`kubernetes`](kubernetes) + Contains examples of setting up deployments in Kubernetes clusters. + +- [`vm`](vm) + Contains examples for setting up virtual or physical servers. diff --git a/examples/docker-compose/README.md b/examples/docker-compose/README.md new file mode 100644 index 0000000..c3b714c --- /dev/null +++ b/examples/docker-compose/README.md @@ -0,0 +1,20 @@ +### Running `act_runner` using `docker-compose` + +```yml +... + gitea: + image: gitea/gitea + ... + + runner: + image: gitea/act_runner + restart: always + depends_on: + - gitea + volumes: + - ./data/act_runner:/data + - /var/run/docker.sock:/var/run/docker.sock + environment: + - GITEA_INSTANCE_URL= + - GITEA_RUNNER_REGISTRATION_TOKEN= +``` diff --git a/examples/docker/README.md b/examples/docker/README.md new file mode 100644 index 0000000..dde2d63 --- /dev/null +++ b/examples/docker/README.md @@ -0,0 +1,8 @@ +### Run `act_runner` in a Docker Container + +```sh +docker run -e GITEA_INSTANCE_URL=http://192.168.8.18:3000 -e GITEA_RUNNER_REGISTRATION_TOKEN= -v /var/run/docker.sock:/var/run/docker.sock -v $PWD/data:/data --name my_runner gitea/act_runner:nightly +``` + +The `/data` directory inside the docker container contains the runner API keys after registration. +It must be persisted, otherwise the runner would try to register again, using the same, now defunct registration token. diff --git a/examples/kubernetes/README.md b/examples/kubernetes/README.md new file mode 100644 index 0000000..a21d4a6 --- /dev/null +++ b/examples/kubernetes/README.md @@ -0,0 +1,8 @@ +## Kubernetes Docker in Docker Deployment with `act_runner` + +NOTE: Docker in Docker (dind) requires elevated privileges on Kubernetes. The current way to achieve this is to set the pod `SecurityContext` to `privileged`. Keep in mind that this is a potential security issue that has the potential for a malicious application to break out of the container context. + +Files in this directory: + +- [`dind-docker.yaml`](dind-docker.yaml) + How to create a Deployment and Persistent Volume for Kubernetes to act as a runner. The Docker credentials are re-generated each time the pod connects and does not need to be persisted. diff --git a/examples/kubernetes/dind-docker.yaml b/examples/kubernetes/dind-docker.yaml new file mode 100644 index 0000000..98a139a --- /dev/null +++ b/examples/kubernetes/dind-docker.yaml @@ -0,0 +1,78 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: act-runner-vol +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: standard +--- +apiVersion: v1 +data: + token: << base64 encoded registration token >> +kind: Secret +metadata: + name: runner-secret +type: Opaque +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: act-runner + name: act-runner +spec: + replicas: 1 + selector: + matchLabels: + app: act-runner + strategy: {} + template: + metadata: + creationTimestamp: null + labels: + app: act-runner + spec: + restartPolicy: Always + volumes: + - name: docker-certs + emptyDir: {} + - name: runner-data + persistentVolumeClaim: + claimName: act-runner-vol + containers: + - name: runner + image: gitea/act_runner:nightly + command: ["sh", "-c", "while ! nc -z localhost 2376 /home/rootless/act_runner/config +``` + +- Create a new user-level`systemd` unit file as `/home/rootless/.config/systemd/user/act_runner.service` with the following contents: + +```bash + Description=Gitea Actions runner + Documentation=https://gitea.com/gitea/act_runner + After=docker.service + + [Service] + Environment=PATH=/home/rootless/bin:/sbin:/usr/sbin:/home/rootless/bin:/home/rootless/bin:/home/rootless/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games + Environment=DOCKER_HOST=unix:///run/user/1001/docker.sock + ExecStart=/usr/bin/act_runner daemon -c /home/rootless/act_runner/config + ExecReload=/bin/kill -s HUP $MAINPID + WorkingDirectory=/home/rootless/act_runner + TimeoutSec=0 + RestartSec=2 + Restart=always + StartLimitBurst=3 + StartLimitInterval=60s + LimitNOFILE=infinity + LimitNPROC=infinity + LimitCORE=infinity + TasksMax=infinity + Delegate=yes + Type=notify + NotifyAccess=all + KillMode=mixed + + [Install] + WantedBy=default.target +``` + +- Reboot + +After the system restarts, check that the`act_runner` is working and that the runner is connected to Gitea. + +````bash + systemctl --user status act_runner + journalctl --user -xeu act_runner From 01ef57c667360774d7496c41b7ad1c56095d5877 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Mon, 5 Jun 2023 08:51:44 +0000 Subject: [PATCH 3/6] fix `artifactServerPath` and `artifactServerAddr` config for exec (#221) fix exec logic to make `actions/download-artifact` and `actions/upload-artifact` can be used. example result: ```YML name: test-artifact on: - push - pull_request jobs: test-artifact-1: name: test 1 runs-on: ubuntu-latest steps: - run: echo `date` | tee time.txt - name: cache build result uses: actions/upload-artifact@v3 with: name: build-artifact path: time.txt retention-days: 1 test-artifact-2: name: test 2 needs: test-artifact-1 runs-on: ubuntu-latest steps: - name: Retrieve saved build result uses: actions/download-artifact@v3 with: name: build-artifact path: . - run: ls -lh - run: cat time.txt ``` ![image](/attachments/5cad3b4a-930a-4d42-a1ae-45ac32e6bfc2) Co-authored-by: Jason Song Reviewed-on: https://gitea.com/gitea/act_runner/pulls/221 Reviewed-by: Lunny Xiao Co-authored-by: a1012112796 <1012112796@qq.com> Co-committed-by: a1012112796 <1012112796@qq.com> --- internal/app/cmd/exec.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/internal/app/cmd/exec.go b/internal/app/cmd/exec.go index 06568a9..99e7ad8 100644 --- a/internal/app/cmd/exec.go +++ b/internal/app/cmd/exec.go @@ -357,6 +357,24 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command log.Infof("cache handler listens on: %v", handler.ExternalURL()) execArgs.cacheHandler = handler + if len(execArgs.artifactServerAddr) == 0 { + if ip := common.GetOutboundIP(); ip == nil { + return fmt.Errorf("unable to determine outbound IP address") + } else { + execArgs.artifactServerAddr = ip.String() + } + } + + if len(execArgs.artifactServerPath) == 0 { + tempDir, err := os.MkdirTemp("", "gitea-act-") + if err != nil { + fmt.Println(err) + } + defer os.RemoveAll(tempDir) + + execArgs.artifactServerPath = tempDir + } + // run the plan config := &runner.Config{ Workdir: execArgs.Workdir(), @@ -381,6 +399,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command AutoRemove: true, ArtifactServerPath: execArgs.artifactServerPath, ArtifactServerPort: execArgs.artifactServerPort, + ArtifactServerAddr: execArgs.artifactServerAddr, NoSkipCheckout: execArgs.noSkipCheckout, // PresetGitHubContext: preset, // EventJSON: string(eventJSON), @@ -403,16 +422,6 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command return err } - if len(execArgs.artifactServerPath) == 0 { - tempDir, err := os.MkdirTemp("", "gitea-act-") - if err != nil { - fmt.Println(err) - } - defer os.RemoveAll(tempDir) - - execArgs.artifactServerPath = tempDir - } - artifactCancel := artifacts.Serve(ctx, execArgs.artifactServerPath, execArgs.artifactServerAddr, execArgs.artifactServerPort) log.Debugf("artifacts server started at %s:%s", execArgs.artifactServerPath, execArgs.artifactServerPort) @@ -459,6 +468,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command { execCmd.Flags().StringArrayVarP(&execArg.containerCapDrop, "container-cap-drop", "", []string{}, "kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)") execCmd.Flags().StringVarP(&execArg.containerOptions, "container-opts", "", "", "container options") execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPath, "artifact-server-path", "", ".", "Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.") + execCmd.PersistentFlags().StringVarP(&execArg.artifactServerAddr, "artifact-server-addr", "", "", "Defines the address where the artifact server listens") execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPort, "artifact-server-port", "", "34567", "Defines the port where the artifact server listens (will only bind to localhost).") execCmd.PersistentFlags().StringVarP(&execArg.defaultActionsUrl, "default-actions-url", "", "https://gitea.com", "Defines the default url of action instance.") execCmd.PersistentFlags().BoolVarP(&execArg.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout") From 69c55ee003a3553d4e8b50d9bf98d2c31c8832e4 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 5 Jun 2023 13:11:23 +0000 Subject: [PATCH 4/6] refactor: daemon, config, and logging for better clarity (#225) - Import "path", "runtime", "strconv", and "strings" packages in daemon.go - Move "Starting runner daemon" log message to a different location - Refactor log formatter initialization and add debug level caller information - Split Config struct into separate Log, Runner, Cache, and Container structs with comments in config.go Signed-off-by: Bo-Yi Wu Reviewed-on: https://gitea.com/gitea/act_runner/pulls/225 Reviewed-by: Jason Song Co-authored-by: Bo-Yi Wu Co-committed-by: Bo-Yi Wu --- internal/app/cmd/daemon.go | 28 ++++++++++++--- internal/pkg/config/config.go | 65 +++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index a648d64..9cd66e2 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -7,6 +7,10 @@ import ( "context" "fmt" "os" + "path" + "runtime" + "strconv" + "strings" "github.com/mattn/go-isatty" log "github.com/sirupsen/logrus" @@ -23,14 +27,13 @@ import ( func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - log.Infoln("Starting runner daemon") - cfg, err := config.LoadDefault(*configFile) if err != nil { return fmt.Errorf("invalid configuration: %w", err) } initLogging(cfg) + log.Infoln("Starting runner daemon") reg, err := config.LoadRegistration(cfg.Runner.File) if os.IsNotExist(err) { @@ -79,10 +82,11 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command, // initLogging setup the global logrus logger. func initLogging(cfg *config.Config) { isTerm := isatty.IsTerminal(os.Stdout.Fd()) - log.SetFormatter(&log.TextFormatter{ + format := &log.TextFormatter{ DisableColors: !isTerm, FullTimestamp: true, - }) + } + log.SetFormatter(format) if l := cfg.Log.Level; l != "" { level, err := log.ParseLevel(l) @@ -90,6 +94,22 @@ func initLogging(cfg *config.Config) { log.WithError(err). Errorf("invalid log level: %q", l) } + + // debug level + if level == log.DebugLevel { + log.SetReportCaller(true) + format.CallerPrettyfier = func(f *runtime.Frame) (string, string) { + // get function name + s := strings.Split(f.Function, ".") + funcname := "[" + s[len(s)-1] + "]" + // get file name and line number + _, filename := path.Split(f.File) + filename = "[" + filename + ":" + strconv.Itoa(f.Line) + "]" + return funcname, filename + } + log.SetFormatter(format) + } + if log.GetLevel() != level { log.Infof("log level changed to %v", level) log.SetLevel(level) diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 4edf1d6..4819687 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -14,33 +14,46 @@ import ( "gopkg.in/yaml.v3" ) +// Log represents the configuration for logging. +type Log struct { + Level string `yaml:"level"` // Level indicates the logging level. +} + +// Runner represents the configuration for the runner. +type Runner struct { + File string `yaml:"file"` // File specifies the file path for the runner. + Capacity int `yaml:"capacity"` // Capacity specifies the capacity of the runner. + Envs map[string]string `yaml:"envs"` // Envs stores environment variables for the runner. + EnvFile string `yaml:"env_file"` // EnvFile specifies the path to the file containing environment variables for the runner. + Timeout time.Duration `yaml:"timeout"` // Timeout specifies the duration for runner timeout. + Insecure bool `yaml:"insecure"` // Insecure indicates whether the runner operates in an insecure mode. + FetchTimeout time.Duration `yaml:"fetch_timeout"` // FetchTimeout specifies the timeout duration for fetching resources. + FetchInterval time.Duration `yaml:"fetch_interval"` // FetchInterval specifies the interval duration for fetching resources. +} + +// Cache represents the configuration for caching. +type Cache struct { + Enabled *bool `yaml:"enabled"` // Enabled indicates whether caching is enabled. It is a pointer to distinguish between false and not set. If not set, it will be true. + Dir string `yaml:"dir"` // Dir specifies the directory path for caching. + Host string `yaml:"host"` // Host specifies the caching host. + Port uint16 `yaml:"port"` // Port specifies the caching port. +} + +// Container represents the configuration for the container. +type Container struct { + Network string `yaml:"network"` // Network specifies the network for the container. + NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 + Privileged bool `yaml:"privileged"` // Privileged indicates whether the container runs in privileged mode. + Options string `yaml:"options"` // Options specifies additional options for the container. + WorkdirParent string `yaml:"workdir_parent"` // WorkdirParent specifies the parent directory for the container's working directory. +} + +// Config represents the overall configuration. type Config struct { - Log struct { - Level string `yaml:"level"` - } `yaml:"log"` - Runner struct { - File string `yaml:"file"` - Capacity int `yaml:"capacity"` - Envs map[string]string `yaml:"envs"` - EnvFile string `yaml:"env_file"` - Timeout time.Duration `yaml:"timeout"` - Insecure bool `yaml:"insecure"` - FetchTimeout time.Duration `yaml:"fetch_timeout"` - FetchInterval time.Duration `yaml:"fetch_interval"` - } `yaml:"runner"` - Cache struct { - Enabled *bool `yaml:"enabled"` // pointer to distinguish between false and not set, and it will be true if not set - Dir string `yaml:"dir"` - Host string `yaml:"host"` - Port uint16 `yaml:"port"` - } `yaml:"cache"` - Container struct { - Network string `yaml:"network"` - NetworkMode string `yaml:"network_mode"` // Deprecated: use Network instead. Could be removed after Gitea 1.20 - Privileged bool `yaml:"privileged"` - Options string `yaml:"options"` - WorkdirParent string `yaml:"workdir_parent"` - } `yaml:"container"` + Log Log `yaml:"log"` // Log represents the configuration for logging. + Runner Runner `yaml:"runner"` // Runner represents the configuration for the runner. + Cache Cache `yaml:"cache"` // Cache represents the configuration for caching. + Container Container `yaml:"container"` // Container represents the configuration for the container. } // LoadDefault returns the default configuration. From a83f29d5a96a78b61a9dc6967d09a31ef0ad5d7e Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 6 Jun 2023 02:42:58 +0000 Subject: [PATCH 5/6] docs: improve examples README and organization (#230) - Update the introduction and descriptions in the examples README - Add a table with descriptions for each section (docker, docker-compose, kubernetes, vm) Signed-off-by: Bo-Yi Wu Reviewed-on: https://gitea.com/gitea/act_runner/pulls/230 Reviewed-by: techknowlogick Reviewed-by: Lunny Xiao Co-authored-by: Bo-Yi Wu Co-committed-by: Bo-Yi Wu --- examples/README.md | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/README.md b/examples/README.md index 83439c7..d5a5b7e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,16 +1,12 @@ -## Usage Examples for `act_runner` +# Usage Examples for `act_runner` -Here you will find usage and deployment examples that can be directly used in a Gitea setup. Please feel free to contribute! +Welcome to our collection of usage and deployment examples specifically designed for Gitea setups. Whether you're a beginner or an experienced user, you'll find practical resources here that you can directly apply to enhance your Gitea experience. We encourage you to contribute your own insights and knowledge to make this collection even more comprehensive and valuable. +| Section | Description | +|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`docker`](docker) | This section provides you with scripts and instructions tailored for running containers on a workstation or server where Docker is installed. It simplifies the process of setting up and managing your Gitea deployment using Docker. | +| [`docker-compose`](docker-compose) | In this section, you'll discover examples demonstrating how to utilize docker-compose to efficiently handle your Gitea deployments. It offers a straightforward approach to managing multiple containerized components of your Gitea setup. | +| [`kubernetes`](kubernetes) | If you're utilizing Kubernetes clusters for your infrastructure, this section is specifically designed for you. It presents examples and guidelines for configuring Gitea deployments within Kubernetes clusters, enabling you to leverage the scalability and flexibility of Kubernetes. | +| [`vm`](vm) | This section is dedicated to examples that assist you in setting up Gitea on virtual or physical servers. Whether you're working with virtual machines or physical hardware, you'll find helpful resources to guide you through the deployment process. | -- [`docker`](docker) - Contains scripts and instructions for running containers on a workstation or server with Docker installed. - -- [`docker-compose`](docker-compose) - Contains examples of using `docker-compose` to manage deployments. - -- [`kubernetes`](kubernetes) - Contains examples of setting up deployments in Kubernetes clusters. - -- [`vm`](vm) - Contains examples for setting up virtual or physical servers. +We hope these resources provide you with valuable insights and solutions for your Gitea setup. Feel free to explore, contribute, and adapt these examples to suit your specific requirements. From fed01c980790cf7bbec0e4330546233557b15af8 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 6 Jun 2023 04:03:02 +0000 Subject: [PATCH 6/6] Parse multiple default actions URLs (#200) Follow https://gitea.com/gitea/act/pulls/58 Resolve https://github.com/go-gitea/gitea/issues/24789 Co-authored-by: Jason Song Reviewed-on: https://gitea.com/gitea/act_runner/pulls/200 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- go.mod | 2 +- go.sum | 4 +-- internal/app/run/runner.go | 50 +++++++++++++++++++++++--------------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 81e43a2..6b77a04 100644 --- a/go.mod +++ b/go.mod @@ -87,4 +87,4 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect ) -replace github.com/nektos/act => gitea.com/gitea/act v0.245.2-0.20230516060355-9283cfc9b166 +replace github.com/nektos/act => gitea.com/gitea/act v0.245.2-0.20230606002131-6ce5c93cc815 diff --git a/go.sum b/go.sum index 4d8f638..5269551 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ code.gitea.io/actions-proto-go v0.2.1 h1:ToMN/8thz2q10TuCq8dL2d8mI+/pWpJcHCvG+TE code.gitea.io/actions-proto-go v0.2.1/go.mod h1:00ys5QDo1iHN1tHNvvddAcy2W/g+425hQya1cCSvq9A= code.gitea.io/gitea-vet v0.2.3-0.20230113022436-2b1561217fa5 h1:daBEK2GQeqGikJESctP5Cu1i33z5ztAD4kyQWiw185M= code.gitea.io/gitea-vet v0.2.3-0.20230113022436-2b1561217fa5/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE= -gitea.com/gitea/act v0.245.2-0.20230516060355-9283cfc9b166 h1:hvyzFmxDmdSZBd8S2+r8VqPSK9eihTD2SrTBAvwgYsA= -gitea.com/gitea/act v0.245.2-0.20230516060355-9283cfc9b166/go.mod h1:1ffiGQZAZCLuk9QEBDdbRuQj1GL4uAQk6GNNtcEnPmI= +gitea.com/gitea/act v0.245.2-0.20230606002131-6ce5c93cc815 h1:u4rHwJLJnH6mej1BjEc4iubwknVeJmRVq9xQP9cAMeQ= +gitea.com/gitea/act v0.245.2-0.20230606002131-6ce5c93cc815/go.mod h1:1ffiGQZAZCLuk9QEBDdbRuQj1GL4uAQk6GNNtcEnPmI= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index a36adad..d636608 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -177,26 +177,26 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. Workdir: filepath.FromSlash(fmt.Sprintf("/%s/%s", r.cfg.Container.WorkdirParent, preset.Repository)), BindWorkdir: false, - ReuseContainers: false, - ForcePull: false, - ForceRebuild: false, - LogOutput: true, - JSONLogger: false, - Env: r.envs, - Secrets: task.Secrets, - GitHubInstance: strings.TrimSuffix(r.client.Address(), "/"), - AutoRemove: true, - NoSkipCheckout: true, - PresetGitHubContext: preset, - EventJSON: string(eventJSON), - ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id), - ContainerMaxLifetime: maxLifetime, - ContainerNetworkMode: container.NetworkMode(r.cfg.Container.Network), - ContainerOptions: r.cfg.Container.Options, - Privileged: r.cfg.Container.Privileged, - DefaultActionInstance: taskContext["gitea_default_actions_url"].GetStringValue(), - PlatformPicker: r.labels.PickPlatform, - Vars: task.Vars, + ReuseContainers: false, + ForcePull: false, + ForceRebuild: false, + LogOutput: true, + JSONLogger: false, + Env: r.envs, + Secrets: task.Secrets, + GitHubInstance: strings.TrimSuffix(r.client.Address(), "/"), + AutoRemove: true, + NoSkipCheckout: true, + PresetGitHubContext: preset, + EventJSON: string(eventJSON), + ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id), + ContainerMaxLifetime: maxLifetime, + ContainerNetworkMode: container.NetworkMode(r.cfg.Container.Network), + ContainerOptions: r.cfg.Container.Options, + Privileged: r.cfg.Container.Privileged, + DefaultActionsURLs: parseDefaultActionsURLs(taskContext["gitea_default_actions_url"].GetStringValue()), + PlatformPicker: r.labels.PickPlatform, + Vars: task.Vars, } rr, err := runner.New(runnerConfig) @@ -214,3 +214,13 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. reporter.SetOutputs(job.Outputs) return execErr } + +func parseDefaultActionsURLs(s string) []string { + urls := strings.Split(s, ",") + trimmed := make([]string, 0, len(urls)) + for _, u := range urls { + t := strings.TrimRight(strings.TrimSpace(u), "/") + trimmed = append(trimmed, t) + } + return trimmed +}