Skip to content

Maintenance (2025 may) #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.21

RUN apk add --no-cache ca-certificates && apk upgrade --update-cache --available
RUN apk upgrade --update-cache --available && apk add ca-certificates && rm -rf /var/cache/apk/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticed that the add --no-cache didn't make sense as the next statement added a cache anyway 😅

RUN adduser --disabled-password --no-create-home --uid=1983 spacelift

COPY spacelift-vcs-agent /usr/bin/spacelift-vcs-agent
Expand Down
57 changes: 29 additions & 28 deletions cmd/spacelift-vcs-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
"github.com/bugsnag/bugsnag-go/v2"
"github.com/go-kit/log"
"github.com/spacelift-io/spcontext"
"github.com/urfave/cli/v2"
"context"
"github.com/urfave/cli/v3"

"github.com/spacelift-io/vcs-agent/agent"
"github.com/spacelift-io/vcs-agent/logging"
Expand Down Expand Up @@ -49,78 +50,78 @@ var (

flagAllowedProjects = &cli.StringFlag{
Name: "allowed-projects",
EnvVars: []string{"SPACELIFT_VCS_AGENT_ALLOWED_PROJECTS"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_ALLOWED_PROJECTS"),
Usage: "Regexp matching allowed projects for API calls. Projects are in the form: 'group/repository'.",
Value: ".*",
}

flagBugsnagAPIKey = &cli.StringFlag{
Name: "bugsnag-api-key",
EnvVars: []string{"SPACELIFT_VCS_AGENT_BUGSNAG_API_KEY"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_BUGSNAG_API_KEY"),
Usage: "Override the Bugsnag API key used for error reporting.",
Value: "",
}

flagBugsnagDisable = &cli.BoolFlag{
Name: "disable-bugsnag",
EnvVars: []string{"SPACELIFT_VCS_AGENT_BUGSNAG_DISABLE"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_BUGSNAG_DISABLE"),
Usage: "Disable Bugsnag reporting entirely.",
}

flagParallelism = &cli.IntFlag{
Name: "parallelism",
EnvVars: []string{"SPACELIFT_VCS_AGENT_PARALLELISM"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_PARALLELISM"),
Usage: "Number of streams to create. Each stream can handle one request simultaneously.",
Value: 4,
}

flagPoolToken = &cli.StringFlag{
Name: "token",
EnvVars: []string{"SPACELIFT_VCS_AGENT_POOL_TOKEN"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_POOL_TOKEN"),
Usage: "Token received on VCS Agent Pool creation",
Required: true,
}

flagTargetBaseEndpoint = &cli.StringFlag{
Name: "target-base-endpoint",
EnvVars: []string{"SPACELIFT_VCS_AGENT_TARGET_BASE_ENDPOINT"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_TARGET_BASE_ENDPOINT"),
Usage: "Target endpoint this agent proxies to. Should include protocol (http/https).",
Required: true,
}

flagVCSVendor = &cli.StringFlag{
Name: "vendor",
EnvVars: []string{"SPACELIFT_VCS_AGENT_VENDOR"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_VENDOR"),
Usage: fmt.Sprintf("VCS vendor proxied by this agent. Available vendors: %s", strings.Join(availableVendors, ", ")),
Required: true,
}

flagUseAllowlist = &cli.BoolFlag{
Name: "use-allowlist",
EnvVars: []string{"SPACELIFT_VCS_AGENT_USE_ALLOWLIST"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_USE_ALLOWLIST"),
Usage: "Whether to use the allowlist to validate API calls. Incompatible with --blocklist-path.",
}

flagBlocklistPath = &cli.StringFlag{
Name: "blocklist-path",
EnvVars: []string{"SPACELIFT_VCS_AGENT_BLOCKLIST_PATH"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_BLOCKLIST_PATH"),
Usage: "Path to the YAML blocklist file. Incompatible with --use-allowlist.",
}

flagDebugPrintAll = &cli.BoolFlag{
Name: "debug-print-all",
EnvVars: []string{"SPACELIFT_VCS_AGENT_DEBUG_PRINT_ALL"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_DEBUG_PRINT_ALL"),
Usage: "Whether to print all requests and responses to stdout.",
}

flagHTTPDisableResponseCompression = &cli.BoolFlag{
Name: "http-disable-response-compression",
EnvVars: []string{"SPACELIFT_VCS_AGENT_HTTP_DISABLE_RESPONSE_COMPRESSION"},
Sources: cli.EnvVars("SPACELIFT_VCS_AGENT_HTTP_DISABLE_RESPONSE_COMPRESSION"),
Usage: "Whether to disable HTTP response compression.",
}
)

var app = &cli.App{
var app = &cli.Command{
Flags: []cli.Flag{
flagAllowedProjects,
flagBugsnagAPIKey,
Expand All @@ -132,12 +133,12 @@ var app = &cli.App{
flagDebugPrintAll,
flagHTTPDisableResponseCompression,
},
Action: func(cmdCtx *cli.Context) error {
Action: func(cliCtx context.Context, cmd *cli.Command) error {
availableVendorsMap := make(map[string]bool)
for _, vendor := range availableVendors {
availableVendorsMap[vendor] = true
}
vendor := cmdCtx.String(flagVCSVendor.Name)
vendor := cmd.String(flagVCSVendor.Name)
if !availableVendorsMap[vendor] {
stdlog.Fatalf("invalid vendor specified: '%s', available vendors: [%s]", vendor, strings.Join(availableVendors, ", "))
}
Expand All @@ -146,11 +147,11 @@ var app = &cli.App{
ctx := spcontext.New(log.NewJSONLogger(os.Stdout), opts...)

apiKey := BugsnagAPIKey
if apiKeyOverride := cmdCtx.String(flagBugsnagAPIKey.Name); len(apiKeyOverride) > 0 {
if apiKeyOverride := cmd.String(flagBugsnagAPIKey.Name); len(apiKeyOverride) > 0 {
apiKey = apiKeyOverride
}

if !cmdCtx.Bool(flagBugsnagDisable.Name) {
if !cmd.Bool(flagBugsnagDisable.Name) {
ctx.Notifier = bugsnag.New(bugsnag.Configuration{
APIKey: apiKey,
Logger: &spcontext.BugsnagLogger{
Expand All @@ -163,41 +164,41 @@ var app = &cli.App{
}

var poolConfig privatevcs.AgentPoolConfig
configBytes, err := base64.StdEncoding.DecodeString(cmdCtx.String(flagPoolToken.Name))
configBytes, err := base64.StdEncoding.DecodeString(cmd.String(flagPoolToken.Name))
if err != nil {
stdlog.Fatal("invalid pool token: ", err.Error())
}
if err := json.Unmarshal(configBytes, &poolConfig); err != nil {
stdlog.Fatal("invalid pool token: ", err.Error())
}

if cmdCtx.IsSet(flagAllowedProjects.Name) && vendor == vendorGitHubEnterprise {
if cmd.IsSet(flagAllowedProjects.Name) && vendor == vendorGitHubEnterprise {
stdlog.Fatal("--allowed-projects is not currently supported for the GitHub Enterprise integration")
}

agentMetadata := loadMetadata()

var validationStrategy validation.Strategy = new(blocklist.List)

useAllowlist := cmdCtx.Bool(flagUseAllowlist.Name)
useAllowlist := cmd.Bool(flagUseAllowlist.Name)
if useAllowlist {
if validationStrategy, err = allowlist.New(cmdCtx.String(flagAllowedProjects.Name)); err != nil {
if validationStrategy, err = allowlist.New(cmd.String(flagAllowedProjects.Name)); err != nil {
stdlog.Fatal("could not create request allowlist: ", err.Error())
}
}

if cmdCtx.IsSet(flagBlocklistPath.Name) {
if cmd.IsSet(flagBlocklistPath.Name) {
if useAllowlist {
stdlog.Fatal("--use-allowlist and --blocklist-path are mutually exclusive")
}

if validationStrategy, err = blocklist.Load(cmdCtx.String(flagBlocklistPath.Name)); err != nil {
if validationStrategy, err = blocklist.Load(cmd.String(flagBlocklistPath.Name)); err != nil {
stdlog.Fatal("could not create request blocklist: ", err.Error())
}
}

var httpClient agent.RequestDoer = http.DefaultClient
if cmdCtx.Bool(flagDebugPrintAll.Name) {
if cmd.Bool(flagDebugPrintAll.Name) {
httpClient = &logging.HTTPClient{
Wrapped: http.DefaultClient,
Out: &logging.ConcurrentSafeWriter{Out: os.Stdout},
Expand All @@ -206,15 +207,15 @@ var app = &cli.App{

a := agent.New(
&poolConfig,
cmdCtx.String(flagTargetBaseEndpoint.Name),
cmd.String(flagTargetBaseEndpoint.Name),
vendor,
validationStrategy,
agentMetadata,
httpClient,
)
a.HTTPDisableResponseCompression = cmdCtx.Bool(flagHTTPDisableResponseCompression.Name)
a.HTTPDisableResponseCompression = cmd.Bool(flagHTTPDisableResponseCompression.Name)

parallelismSemaphore := make(chan struct{}, cmdCtx.Int(flagParallelism.Name))
parallelismSemaphore := make(chan struct{}, cmd.Int(flagParallelism.Name))

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGHUP)
Expand Down Expand Up @@ -267,7 +268,7 @@ var app = &cli.App{
}

func main() {
if err := app.Run(os.Args); err != nil {
if err := app.Run(context.Background(), os.Args); err != nil {
stdlog.Fatal(err)
}
}
Expand Down
25 changes: 10 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
module github.com/spacelift-io/vcs-agent

go 1.23
go 1.24

require (
github.com/bugsnag/bugsnag-go/v2 v2.5.1
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf
github.com/go-kit/log v0.2.1
github.com/kr/text v0.2.0
github.com/onsi/gomega v1.36.2
github.com/pkg/errors v0.9.1
github.com/spacelift-io/spcontext v0.0.6
github.com/spacelift-io/spcontext v0.0.7
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v2 v2.27.5
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.5
github.com/urfave/cli/v3 v3.3.3
google.golang.org/grpc v1.72.0
google.golang.org/protobuf v1.36.6
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/bugsnag/panicwrap v1.3.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
)
Loading
Loading