Skip to content

Commit c5f023f

Browse files
committed
cmd/go-cache-plugin: add support for a custom S3 endpoint URL
This allows use of other S3-compatible implementations for cache storage. Signed-off-by: Lukas Hoehl <[email protected]>
1 parent bebc589 commit c5f023f

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

cmd/go-cache-plugin/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var flags struct {
2626
CacheDir string `flag:"cache-dir,default=$GOCACHE_DIR,Local cache directory (required)"`
2727
S3Bucket string `flag:"bucket,default=$GOCACHE_S3_BUCKET,S3 bucket name (required)"`
2828
S3Region string `flag:"region,default=$GOCACHE_S3_REGION,S3 region"`
29+
S3Endpoint string `flag:"s3-endpoint-url,default=$GOCACHE_S3_ENDPOINT_URL,S3 custom endpoint URL (if unset, use AWS default)"`
2930
S3PathStyle bool `flag:"s3-path-style,default=$GOCACHE_S3_PATH_STYLE,S3 path-style URLs (optional)"`
3031
KeyPrefix string `flag:"prefix,default=$GOCACHE_KEY_PREFIX,S3 key prefix (optional)"`
3132
MinUploadSize int64 `flag:"min-upload-size,default=$GOCACHE_MIN_SIZE,Minimum object size to upload to S3 (in bytes)"`

cmd/go-cache-plugin/help.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,30 @@ To make it easier to configure this tool for multiple workflows, most of the
3333
settings can be set via environment variables as well as flags.
3434
3535
--------------------------------------------------------------------
36-
Flag (global) Variable Format Default
36+
Flag (global) Variable Format Default
3737
--------------------------------------------------------------------
38-
--cache-dir GOCACHE_DIR path (required)
39-
--bucket GOCACHE_S3_BUCKET string (required)
40-
--region GOCACHE_S3_REGION string based on bucket
41-
--s3-path-style GOCACHE_S3_PATH_STYLE bool false
42-
--prefix GOCACHE_KEY_PREFIX string ""
43-
--min-upload-size GOCACHE_MIN_SIZE int64 0
44-
--metrics GOCACHE_METRICS bool false
45-
--expiry GOCACHE_EXPIRY duration 0
46-
-c GOCACHE_CONCURRENCY int runtime.NumCPU
47-
-u GOCACHE_S3_CONCURRENCY duration runtime.NumCPU
48-
-v GOCACHE_VERBOSE bool false
49-
--debug GOCACHE_DEBUG int 0 (see "help debug")
38+
--cache-dir GOCACHE_DIR path (required)
39+
--bucket GOCACHE_S3_BUCKET string (required)
40+
--region GOCACHE_S3_REGION string based on bucket
41+
--s3-path-style GOCACHE_S3_PATH_STYLE bool false
42+
--s3-endpoint-url GOCACHE_S3_PATH_STYLE bool false
43+
--prefix GOCACHE_KEY_PREFIX string ""
44+
--min-upload-size GOCACHE_MIN_SIZE int64 0
45+
--metrics GOCACHE_METRICS bool false
46+
--expiry GOCACHE_EXPIRY duration 0
47+
-c GOCACHE_CONCURRENCY int runtime.NumCPU
48+
-u GOCACHE_S3_CONCURRENCY duration runtime.NumCPU
49+
-v GOCACHE_VERBOSE bool false
50+
--debug GOCACHE_DEBUG int 0 (see "help debug")
5051
5152
--------------------------------------------------------------------
52-
Flag (serve) Variable Format Default
53+
Flag (serve) Variable Format Default
5354
--------------------------------------------------------------------
54-
--plugin GOCACHE_PLUGIN port (required)
55-
--http GOCACHE_HTTP [host]:port ""
56-
--modproxy GOCACHE_MODPROXY bool false
57-
--revproxy GOCACHE_REVPROXY host,... ""
58-
--sumdb GOCACHE_SUMDB host,... ""
55+
--plugin GOCACHE_PLUGIN port (required)
56+
--http GOCACHE_HTTP [host]:port ""
57+
--modproxy GOCACHE_MODPROXY bool false
58+
--revproxy GOCACHE_REVPROXY host,... ""
59+
--sumdb GOCACHE_SUMDB host,... ""
5960
6061
See also: "help configure".`,
6162
},

cmd/go-cache-plugin/setup.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ func initCacheServer(env *command.Env) (*gocache.Server, *s3util.Client, error)
5252
return nil, nil, fmt.Errorf("create local cache: %w", err)
5353
}
5454

55-
cfg, err := config.LoadDefaultConfig(env.Context(),
55+
opts := []func(*config.LoadOptions) error{
5656
config.WithRegion(region),
5757
config.WithResponseChecksumValidation(aws.ResponseChecksumValidationWhenRequired),
58-
)
58+
}
59+
if flags.S3Endpoint != "" {
60+
vprintf("S3 endpoint URL: %s", flags.S3Endpoint)
61+
opts = append(opts, config.WithBaseEndpoint(flags.S3Endpoint))
62+
}
63+
cfg, err := config.LoadDefaultConfig(env.Context(), opts...)
5964
if err != nil {
6065
return nil, nil, fmt.Errorf("load AWS config: %w", err)
6166
}

0 commit comments

Comments
 (0)