From 47a021d84a5b6ce06f9ed02d67de2dc13bb9c057 Mon Sep 17 00:00:00 2001 From: Michael Hohn Date: Wed, 26 Mar 2025 09:02:08 -0700 Subject: [PATCH] updated to buckete.minio.store virtual host style --- pkg/artifactstore/common.go | 5 +++-- pkg/artifactstore/store_minio.go | 23 ++++++++++------------- pkg/deploy/init.go | 1 + pkg/qldbstore/qldbstore_minio.go | 8 +++++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pkg/artifactstore/common.go b/pkg/artifactstore/common.go index 7d45923..c66a015 100644 --- a/pkg/artifactstore/common.go +++ b/pkg/artifactstore/common.go @@ -2,14 +2,15 @@ package artifactstore import ( "fmt" + "github.com/hohn/mrvacommander/pkg/common" ) // Restrict the keys / values for ArtifactLocation and centralize the common ones // here const ( - AF_BUCKETNAME_RESULTS = "results" - AF_BUCKETNAME_PACKS = "packs" + AF_BUCKETNAME_RESULTS = "mrvabucket" + AF_BUCKETNAME_PACKS = "mrvabucket" ) type ArtifactLocation struct { diff --git a/pkg/artifactstore/store_minio.go b/pkg/artifactstore/store_minio.go index 7cd4aba..42dfa4d 100644 --- a/pkg/artifactstore/store_minio.go +++ b/pkg/artifactstore/store_minio.go @@ -7,6 +7,7 @@ import ( "io" "log/slog" "math" + "github.com/hohn/mrvacommander/pkg/common" "github.com/minio/minio-go/v7" @@ -19,8 +20,9 @@ type MinIOArtifactStore struct { func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, error) { minioClient, err := minio.New(endpoint, &minio.Options{ - Creds: credentials.NewStaticV4(id, secret, ""), - Secure: false, + Creds: credentials.NewStaticV4(id, secret, ""), + Secure: false, + BucketLookup: minio.BucketLookupDNS, // Enable virtual-host-style addressing }) if err != nil { return nil, err @@ -28,16 +30,6 @@ func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, er slog.Info("Connected to MinIO artifact store server") - // Create "results" bucket - if err := common.CreateMinIOBucketIfNotExists(minioClient, AF_BUCKETNAME_RESULTS); err != nil { - return nil, fmt.Errorf("could not create results bucket: %v", err) - } - - // Create "packs" bucket - if err := common.CreateMinIOBucketIfNotExists(minioClient, AF_BUCKETNAME_PACKS); err != nil { - return nil, fmt.Errorf("could not create packs bucket: %v", err) - } - return &MinIOArtifactStore{ client: minioClient, }, nil @@ -95,7 +87,12 @@ func (store *MinIOArtifactStore) getArtifact(location ArtifactLocation) ([]byte, func (store *MinIOArtifactStore) saveArtifact(bucket, key string, data []byte, contentType string) (ArtifactLocation, error) { - _, err := store.client.PutObject(context.Background(), bucket, key, + exists, err := store.client.BucketExists(context.Background(), bucket) + if err != nil || !exists { + slog.Error("Bucket does not exist", "bucket", bucket) + } + + _, err = store.client.PutObject(context.Background(), bucket, key, bytes.NewReader(data), int64(len(data)), minio.PutObjectOptions{ ContentType: contentType, }) diff --git a/pkg/deploy/init.go b/pkg/deploy/init.go index 948915b..f0cf99a 100644 --- a/pkg/deploy/init.go +++ b/pkg/deploy/init.go @@ -69,6 +69,7 @@ func InitMinIOArtifactStore() (artifactstore.Store, error) { secret := os.Getenv("ARTIFACT_MINIO_SECRET") store, err := artifactstore.NewMinIOArtifactStore(endpoint, id, secret) + if err != nil { return nil, fmt.Errorf("failed to initialize artifact store: %v", err) } diff --git a/pkg/qldbstore/qldbstore_minio.go b/pkg/qldbstore/qldbstore_minio.go index 6c328de..ce7c898 100644 --- a/pkg/qldbstore/qldbstore_minio.go +++ b/pkg/qldbstore/qldbstore_minio.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log/slog" + "github.com/hohn/mrvacommander/pkg/common" "github.com/minio/minio-go/v7" @@ -14,7 +15,7 @@ import ( // XX: static types: split by type? // Restrict the keys / values and centralize the common ones here const ( - QL_DB_BUCKETNAME = "qldb" + QL_DB_BUCKETNAME = "mrvabucket" ) type MinIOCodeQLDatabaseStore struct { @@ -24,8 +25,9 @@ type MinIOCodeQLDatabaseStore struct { func NewMinIOCodeQLDatabaseStore(endpoint, id, secret string) (*MinIOCodeQLDatabaseStore, error) { minioClient, err := minio.New(endpoint, &minio.Options{ - Creds: credentials.NewStaticV4(id, secret, ""), - Secure: false, + Creds: credentials.NewStaticV4(id, secret, ""), + Secure: false, + BucketLookup: minio.BucketLookupDNS, // Enable virtual-host-style addressing }) if err != nil { return nil, err