mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-04 22:37:55 +00:00
The Kubernetes backend copies actions and workspaces into job containers with `tar` over `pods/exec`, so every byte goes through the API server. On managed clusters that often sits in other zones than the nodes, so each byte can cross zones twice, and the copies load the API server. With `kubernetes.transfer.mode: auto` or `direct`, an init container copies `gitea-runner` into the job pod, and the job container fetches directories and copies of 64 KiB or more gzipped from the runner over the pod network. `auto` falls back to the API server for a job pod that cannot reach the runner, `direct` fails the job. Copies can hold secrets, so each is served once, over TLS 1.3 pinned to a certificate the runner generates, only to the job pod's IPs. Copying setup-go@v5, cache@v4, setup-java@v4 and build-push-action@v6 sends 11.6 MB through the API server on main and 532 B with this PR. Co-authored-by: silverwind <[email protected]> Co-authored-by: silverwind <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1354 Reviewed-by: silverwind <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
92 lines
3.4 KiB
Go
92 lines
3.4 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"gitea.com/gitea/runner/internal/pkg/ver"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func Execute(ctx context.Context) {
|
|
// ./gitea-runner
|
|
rootCmd := &cobra.Command{
|
|
Use: "gitea-runner",
|
|
Short: "Gitea Runner",
|
|
Version: ver.Version(),
|
|
SilenceUsage: true,
|
|
}
|
|
configFile := ""
|
|
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Config file path. `config` subcommands fall back to config.yaml in the working directory or next to the executable")
|
|
|
|
// ./gitea-runner register
|
|
var regArgs registerArgs
|
|
registerCmd := &cobra.Command{
|
|
Use: "register",
|
|
Short: "Register a runner to the server",
|
|
Args: cobra.MaximumNArgs(0),
|
|
RunE: runRegister(ctx, ®Args, &configFile), // must use a pointer to regArgs
|
|
}
|
|
registerCmd.Flags().BoolVar(®Args.NoInteractive, "no-interactive", false, "Disable interactive mode")
|
|
registerCmd.Flags().StringVar(®Args.InstanceAddr, "instance", "", "Gitea instance address")
|
|
registerCmd.Flags().StringVar(®Args.Token, "token", "", "Runner token (or set the GITEA_RUNNER_REGISTRATION_TOKEN envvar)")
|
|
registerCmd.Flags().StringVar(®Args.TokenFile, "token-file", "", "Path to a file containing the runner token")
|
|
registerCmd.Flags().StringVar(®Args.RunnerName, "name", "", "Runner name")
|
|
registerCmd.Flags().StringVar(®Args.Labels, "labels", "", "Runner tags, comma separated")
|
|
registerCmd.Flags().BoolVar(®Args.Ephemeral, "ephemeral", false, "Configure the runner to be ephemeral and only ever be able to pick a single job (stricter than --once)")
|
|
rootCmd.AddCommand(registerCmd)
|
|
|
|
// ./gitea-runner daemon
|
|
var daemArgs daemonArgs
|
|
daemonCmd := &cobra.Command{
|
|
Use: "daemon",
|
|
Short: "Run as a runner daemon",
|
|
Args: cobra.MaximumNArgs(0),
|
|
RunE: runDaemon(ctx, &daemArgs, &configFile),
|
|
}
|
|
daemonCmd.Flags().BoolVar(&daemArgs.Once, "once", false, "Run one job then exit")
|
|
daemonCmd.Flags().StringVar(&daemArgs.Labels, "labels", os.Getenv("GITEA_RUNNER_LABELS"), "Runner labels, comma separated. Overrides the labels of an already registered runner")
|
|
rootCmd.AddCommand(daemonCmd)
|
|
|
|
// ./gitea-runner exec
|
|
rootCmd.AddCommand(loadExecCmd(ctx))
|
|
|
|
// ./gitea-runner bug-report
|
|
rootCmd.AddCommand(loadBugReportCmd())
|
|
|
|
// ./gitea-runner kubernetes-transfer, run inside Kubernetes job pods
|
|
rootCmd.AddCommand(loadKubernetesTransferCmd())
|
|
|
|
// ./gitea-runner config
|
|
rootCmd.AddCommand(loadConfigCmd(&configFile))
|
|
|
|
// ./gitea-runner generate-config
|
|
generateConfigCmd := loadGenerateConfigCmd("generate-config")
|
|
generateConfigCmd.Deprecated = "use `config generate` instead."
|
|
rootCmd.AddCommand(generateConfigCmd)
|
|
|
|
// ./gitea-runner cache-server
|
|
var cacheArgs cacheServerArgs
|
|
cacheCmd := &cobra.Command{
|
|
Use: "cache-server",
|
|
Short: "Start a cache server for the cache action",
|
|
Args: cobra.MaximumNArgs(0),
|
|
RunE: runCacheServer(&configFile, &cacheArgs),
|
|
}
|
|
cacheCmd.Flags().StringVarP(&cacheArgs.Dir, "dir", "d", "", "Cache directory")
|
|
cacheCmd.Flags().StringVarP(&cacheArgs.Host, "host", "s", "", "Host of the cache server")
|
|
cacheCmd.Flags().Uint16VarP(&cacheArgs.Port, "port", "p", 0, "Port of the cache server")
|
|
rootCmd.AddCommand(cacheCmd)
|
|
|
|
// hide completion command
|
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
|
|
|
if err := rootCmd.ExecuteContext(ctx); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|