mirror of
https://gitea.com/gitea/act_runner
synced 2026-09-21 19:37:07 +02:00
Three independent fixes, one commit each. 1. Hosts and ports were interpolated directly when building URLs, so a literal IPv6 address produced an unbracketed authority, making `ACTIONS_CACHE_URL`, `ACTIONS_RUNTIME_URL` and the artifact server listener unusable. Hosts are expected bare, as documented for `cache.host`, so an address that already carries brackets is no longer accepted. 2. `cache-server` waited on its own `os.Interrupt` channel and ignored SIGTERM, so service managers and container runtimes had to kill it. 3. Task admission used a separate `Load` and `Store`, so two concurrent dispatches of the same task id could both be admitted. Assisted-by: Claude Code:Opus 5 Co-authored-by: bircni <bircni@icloud.com> Reviewed-on: https://gitea.com/gitea/runner/pulls/1217 Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
89 lines
3.3 KiB
Go
89 lines
3.3 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 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)
|
|
}
|
|
}
|