updated to buckete.minio.store virtual host style

This commit is contained in:
Michael Hohn
2025-03-26 09:02:08 -07:00
committed by =Michael Hohn
parent 8d4c766e8c
commit 47a021d84a
4 changed files with 19 additions and 18 deletions

View File

@@ -2,14 +2,15 @@ package artifactstore
import ( import (
"fmt" "fmt"
"github.com/hohn/mrvacommander/pkg/common" "github.com/hohn/mrvacommander/pkg/common"
) )
// Restrict the keys / values for ArtifactLocation and centralize the common ones // Restrict the keys / values for ArtifactLocation and centralize the common ones
// here // here
const ( const (
AF_BUCKETNAME_RESULTS = "results" AF_BUCKETNAME_RESULTS = "mrvabucket"
AF_BUCKETNAME_PACKS = "packs" AF_BUCKETNAME_PACKS = "mrvabucket"
) )
type ArtifactLocation struct { type ArtifactLocation struct {

View File

@@ -7,6 +7,7 @@ import (
"io" "io"
"log/slog" "log/slog"
"math" "math"
"github.com/hohn/mrvacommander/pkg/common" "github.com/hohn/mrvacommander/pkg/common"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
@@ -19,8 +20,9 @@ type MinIOArtifactStore struct {
func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, error) { func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, error) {
minioClient, err := minio.New(endpoint, &minio.Options{ minioClient, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(id, secret, ""), Creds: credentials.NewStaticV4(id, secret, ""),
Secure: false, Secure: false,
BucketLookup: minio.BucketLookupDNS, // Enable virtual-host-style addressing
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@@ -28,16 +30,6 @@ func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, er
slog.Info("Connected to MinIO artifact store server") 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{ return &MinIOArtifactStore{
client: minioClient, client: minioClient,
}, nil }, nil
@@ -95,7 +87,12 @@ func (store *MinIOArtifactStore) getArtifact(location ArtifactLocation) ([]byte,
func (store *MinIOArtifactStore) saveArtifact(bucket, key string, data []byte, func (store *MinIOArtifactStore) saveArtifact(bucket, key string, data []byte,
contentType string) (ArtifactLocation, error) { 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{ bytes.NewReader(data), int64(len(data)), minio.PutObjectOptions{
ContentType: contentType, ContentType: contentType,
}) })

View File

@@ -69,6 +69,7 @@ func InitMinIOArtifactStore() (artifactstore.Store, error) {
secret := os.Getenv("ARTIFACT_MINIO_SECRET") secret := os.Getenv("ARTIFACT_MINIO_SECRET")
store, err := artifactstore.NewMinIOArtifactStore(endpoint, id, secret) store, err := artifactstore.NewMinIOArtifactStore(endpoint, id, secret)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to initialize artifact store: %v", err) return nil, fmt.Errorf("failed to initialize artifact store: %v", err)
} }

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
"github.com/hohn/mrvacommander/pkg/common" "github.com/hohn/mrvacommander/pkg/common"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
@@ -14,7 +15,7 @@ import (
// XX: static types: split by type? // XX: static types: split by type?
// Restrict the keys / values and centralize the common ones here // Restrict the keys / values and centralize the common ones here
const ( const (
QL_DB_BUCKETNAME = "qldb" QL_DB_BUCKETNAME = "mrvabucket"
) )
type MinIOCodeQLDatabaseStore struct { type MinIOCodeQLDatabaseStore struct {
@@ -24,8 +25,9 @@ type MinIOCodeQLDatabaseStore struct {
func NewMinIOCodeQLDatabaseStore(endpoint, id, secret string) (*MinIOCodeQLDatabaseStore, error) { func NewMinIOCodeQLDatabaseStore(endpoint, id, secret string) (*MinIOCodeQLDatabaseStore, error) {
minioClient, err := minio.New(endpoint, &minio.Options{ minioClient, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(id, secret, ""), Creds: credentials.NewStaticV4(id, secret, ""),
Secure: false, Secure: false,
BucketLookup: minio.BucketLookupDNS, // Enable virtual-host-style addressing
}) })
if err != nil { if err != nil {
return nil, err return nil, err