updated to buckete.minio.store virtual host style
This commit is contained in:
committed by
=Michael Hohn
parent
8d4c766e8c
commit
47a021d84a
@@ -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 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"math"
|
||||
|
||||
"github.com/hohn/mrvacommander/pkg/common"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
@@ -21,6 +22,7 @@ func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, er
|
||||
minioClient, err := minio.New(endpoint, &minio.Options{
|
||||
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,
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -26,6 +27,7 @@ func NewMinIOCodeQLDatabaseStore(endpoint, id, secret string) (*MinIOCodeQLDatab
|
||||
minioClient, err := minio.New(endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(id, secret, ""),
|
||||
Secure: false,
|
||||
BucketLookup: minio.BucketLookupDNS, // Enable virtual-host-style addressing
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user