Skip to content

Commit 0e4fae1

Browse files
Asutorufacreachadair
authored andcommitted
cmd/go-cache-plugin: add a setting to use S3 path-style URLs
This allows using the plugin with other S3-compatible storage implementations that do not support the default virtual-hosted format. Can also use the AWS_ENDPOINT_URL environment variable to customize the s3 address. Signed-off-by: Asutorufa <[email protected]>
1 parent 7346bbd commit 0e4fae1

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
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+
S3PathStyle bool `flag:"s3-path-style,default=$GOCACHE_S3_PATH_STYLE,S3 path-style URLs (optional)"`
2930
KeyPrefix string `flag:"prefix,default=$GOCACHE_KEY_PREFIX,S3 key prefix (optional)"`
3031
MinUploadSize int64 `flag:"min-upload-size,default=$GOCACHE_MIN_SIZE,Minimum object size to upload to S3 (in bytes)"`
3132
Concurrency int `flag:"c,default=$GOCACHE_CONCURRENCY,Maximum number of concurrent requests"`

cmd/go-cache-plugin/help.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ See also "help environment".
1919
2020
The plugin requires credentials to access S3. If you are running in AWS, it can
2121
get credentials from the instance metadata service; otherwise you will need to
22-
plumb AWS environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) or
23-
set up a configuration file.
22+
plumb AWS environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
23+
AWS_ENDPOINT_URL) or set up a configuration file.
2424
2525
See also: "help environment".
2626
Related: "direct-mode", "serve-mode", "module-proxy", "reverse-proxy".`,
@@ -38,6 +38,7 @@ settings can be set via environment variables as well as flags.
3838
--cache-dir GOCACHE_DIR path (required)
3939
--bucket GOCACHE_S3_BUCKET string (required)
4040
--region GOCACHE_S3_REGION string based on bucket
41+
--s3-path-style GOCACHE_S3_PATH_STYLE bool false
4142
--prefix GOCACHE_KEY_PREFIX string ""
4243
--min-upload-size GOCACHE_MIN_SIZE int64 0
4344
--metrics GOCACHE_METRICS bool false

cmd/go-cache-plugin/setup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func initCacheServer(env *command.Env) (*gocache.Server, *s3util.Client, error)
5959
vprintf("local cache directory: %s", flags.CacheDir)
6060
vprintf("S3 cache bucket %q (%s)", flags.S3Bucket, region)
6161
client := &s3util.Client{
62-
Client: s3.NewFromConfig(cfg),
62+
Client: s3.NewFromConfig(cfg, func(o *s3.Options) {
63+
o.UsePathStyle = flags.S3PathStyle
64+
}),
6365
Bucket: flags.S3Bucket,
6466
}
6567
cache := &gobuild.S3Cache{

0 commit comments

Comments
 (0)