Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
537c620051
|
||
|
|
a7b62868b6 |
@@ -22,6 +22,7 @@ type ExecutorConfig struct {
|
|||||||
FacadeSPIFFEID string
|
FacadeSPIFFEID string
|
||||||
WorkloadAPIAddr string
|
WorkloadAPIAddr string
|
||||||
RunnerBinary string
|
RunnerBinary string
|
||||||
|
RunnerConfig string
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
WorkDir string
|
WorkDir string
|
||||||
Stdout *os.File
|
Stdout *os.File
|
||||||
@@ -35,6 +36,9 @@ func RunExecutor(ctx context.Context, config ExecutorConfig) error {
|
|||||||
if config.RunnerBinary == "" {
|
if config.RunnerBinary == "" {
|
||||||
config.RunnerBinary = "gitea-runner"
|
config.RunnerBinary = "gitea-runner"
|
||||||
}
|
}
|
||||||
|
if config.RunnerConfig == "" {
|
||||||
|
config.RunnerConfig = "/etc/gitea-runner/config.yaml"
|
||||||
|
}
|
||||||
if config.ListenAddress == "" {
|
if config.ListenAddress == "" {
|
||||||
config.ListenAddress = "127.0.0.1:0"
|
config.ListenAddress = "127.0.0.1:0"
|
||||||
}
|
}
|
||||||
@@ -93,7 +97,7 @@ func RunExecutor(ctx context.Context, config ExecutorConfig) error {
|
|||||||
return errors.Join(readyErr, shutdownErr, serverErr)
|
return errors.Join(readyErr, shutdownErr, serverErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
command := exec.CommandContext(ctx, config.RunnerBinary, "daemon", "--once")
|
command := exec.CommandContext(ctx, config.RunnerBinary, runnerArguments(config.RunnerConfig)...)
|
||||||
command.Dir = workDir
|
command.Dir = workDir
|
||||||
command.Stdout = config.Stdout
|
command.Stdout = config.Stdout
|
||||||
command.Stderr = config.Stderr
|
command.Stderr = config.Stderr
|
||||||
@@ -108,6 +112,10 @@ func RunExecutor(ctx context.Context, config ExecutorConfig) error {
|
|||||||
return errors.Join(runnerErr, shutdownErr, serverErr)
|
return errors.Join(runnerErr, shutdownErr, serverErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runnerArguments(configFile string) []string {
|
||||||
|
return []string{"daemon", "--config", configFile, "--once"}
|
||||||
|
}
|
||||||
|
|
||||||
func waitForFacade(ctx context.Context, endpoint string) error {
|
func waitForFacade(ctx context.Context, endpoint string) error {
|
||||||
client := &http.Client{Timeout: 2 * time.Second}
|
client := &http.Client{Timeout: 2 * time.Second}
|
||||||
ticker := time.NewTicker(250 * time.Millisecond)
|
ticker := time.NewTicker(250 * time.Millisecond)
|
||||||
@@ -143,7 +151,8 @@ func ExecutorConfigFromEnvironment() (ExecutorConfig, error) {
|
|||||||
config := ExecutorConfig{
|
config := ExecutorConfig{
|
||||||
AssignmentID: os.Getenv(EnvAssignmentID), Capability: os.Getenv(EnvCapability),
|
AssignmentID: os.Getenv(EnvAssignmentID), Capability: os.Getenv(EnvCapability),
|
||||||
Backend: backend, FacadeURL: os.Getenv(EnvFacadeURL), FacadeSPIFFEID: os.Getenv(EnvFacadeID),
|
Backend: backend, FacadeURL: os.Getenv(EnvFacadeURL), FacadeSPIFFEID: os.Getenv(EnvFacadeID),
|
||||||
RunnerBinary: os.Getenv("GITEA_RUNNER_BINARY"), ListenAddress: "127.0.0.1:0",
|
RunnerBinary: os.Getenv("GITEA_RUNNER_BINARY"), RunnerConfig: os.Getenv("GITEA_RUNNER_CONFIG_FILE"),
|
||||||
|
ListenAddress: "127.0.0.1:0",
|
||||||
Stdout: os.Stdout, Stderr: os.Stderr,
|
Stdout: os.Stdout, Stderr: os.Stderr,
|
||||||
}
|
}
|
||||||
if config.AssignmentID == "" || config.Capability == "" || config.FacadeURL == "" || config.FacadeSPIFFEID == "" {
|
if config.AssignmentID == "" || config.Capability == "" || config.FacadeURL == "" || config.FacadeSPIFFEID == "" {
|
||||||
|
|||||||
@@ -4,11 +4,19 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"reflect"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestRunnerArgumentsLoadJobHooksConfig(t *testing.T) {
|
||||||
|
want := []string{"daemon", "--config", "/etc/gitea-runner/config.yaml", "--once"}
|
||||||
|
if got := runnerArguments("/etc/gitea-runner/config.yaml"); !reflect.DeepEqual(got, want) {
|
||||||
|
t.Fatalf("runner arguments = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestWaitForFacadeRetriesTransientGatewayFailure(t *testing.T) {
|
func TestWaitForFacadeRetriesTransientGatewayFailure(t *testing.T) {
|
||||||
var requests atomic.Int32
|
var requests atomic.Int32
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user