feat(19.3-03): summer.yaml build.tags and the summercms_s3 tag that links the S3 uploads driver
- Manifest.Tags from build.tags (^[a-z0-9_]+$, duplicates dropped), round-tripped by SaveManifest - summer build passes -tags=<list> through goBuildArgs and prints the build tags line - attach: s3blob imported only by s3_on.go (//go:build summercms_s3); an untagged binary refuses an s3:// bucket_url naming the tag, build.tags and -tags - go mod tidy adds the AWS SDK v2 modules as indirect requirements - storage, modules, scaffolding, configuration and scaling docs plus the lagoon README
This commit is contained in:
@@ -16,6 +16,11 @@ import (
|
||||
|
||||
const defaultPublicPathPrefix = "/storage/uploads"
|
||||
|
||||
// S3BuildTag is the Go build tag that links the gocloud S3 driver
|
||||
// (s3blob, imported only by s3_on.go). List it under build.tags in summer.yaml so
|
||||
// summer build passes it to go build; a raw go build needs -tags summercms_s3.
|
||||
const S3BuildTag = "summercms_s3"
|
||||
|
||||
var (
|
||||
prefixMu sync.RWMutex
|
||||
publicPathPrefix = defaultPublicPathPrefix
|
||||
@@ -57,8 +62,24 @@ func normalizeBucketURL(raw string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// OpenBucket opens storage.uploads.bucket_url (file:// or mem://) and
|
||||
// records storage.uploads.public_path_prefix. An empty bucket_url fails boot.
|
||||
// checkS3Driver refuses an s3:// bucket URL when the binary was built
|
||||
// without S3BuildTag, naming the tag and where to set it.
|
||||
func checkS3Driver(bucketURL string) error {
|
||||
if s3Enabled {
|
||||
return nil
|
||||
}
|
||||
scheme, _, ok := strings.Cut(bucketURL, "://")
|
||||
if !ok || !strings.EqualFold(scheme, "s3") {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("attach: storage.uploads.bucket_url uses s3:// but this binary was built without the %s build tag; "+
|
||||
"list %s under build.tags in summer.yaml and rebuild with summer build (a raw go build needs -tags %s, or GOFLAGS=-tags=%s)",
|
||||
S3BuildTag, S3BuildTag, S3BuildTag, S3BuildTag)
|
||||
}
|
||||
|
||||
// OpenBucket opens storage.uploads.bucket_url (file://, mem://, or s3:// in a
|
||||
// binary built with S3BuildTag) and records
|
||||
// storage.uploads.public_path_prefix. An empty bucket_url fails boot.
|
||||
func OpenBucket(ctx context.Context, cfg *compass.Config) (*blob.Bucket, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("attach: config is nil")
|
||||
@@ -71,6 +92,9 @@ func OpenBucket(ctx context.Context, cfg *compass.Config) (*blob.Bucket, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := checkS3Driver(bucketURL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bucket, err := blob.OpenBucket(ctx, bucketURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attach: open bucket %q: %w", raw, err)
|
||||
|
||||
Reference in New Issue
Block a user