mirror of
https://github.com/cooperspencer/gickup
synced 2025-05-01 00:37:55 +02:00
add support for specifying storageclass for S3 dest
This commit is contained in:
parent
6be0214ee3
commit
2c9cabff89
@ -279,6 +279,7 @@ destination:
|
||||
token: your-token # can be an environment variable, just don't add a $ in front of it
|
||||
zip: false # if true, will zip the entire git repo into a single zip file and upload that instead
|
||||
usessl: true # wheter to use ssl or not
|
||||
storageclass: "" # storage class for all repos to be uploaded to this S3 bucket. E.g. for AWS: STANDARD, STANDARD_IA, GLACIER, etc.
|
||||
cron: 0 22 * * * # optional - when cron is not provided, the program runs once and exits.
|
||||
# Otherwise, it runs according to the cron schedule.
|
||||
# See timezone commentary in docker-compose.yml for making sure this container runs
|
||||
|
@ -546,6 +546,10 @@
|
||||
"zip": {
|
||||
"type": "boolean",
|
||||
"description": "If true, zip the entire Git repo into a single zip file and upload that instead"
|
||||
},
|
||||
"storageclass": {
|
||||
"type": "string",
|
||||
"description": "Storage class applied to all repos uploaded to this S3 bucket (optional)"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
5
main.go
5
main.go
@ -18,6 +18,7 @@ import (
|
||||
"github.com/cooperspencer/gickup/sourcehut"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/minio/minio-go/v7"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/cooperspencer/gickup/bitbucket"
|
||||
@ -262,7 +263,9 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
err = s3.UploadDirToS3(tempdir, d)
|
||||
err = s3.UploadDirToS3(tempdir, d, &minio.PutObjectOptions{
|
||||
StorageClass: d.StorageClass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Str("stage", "s3").Str("endpoint", d.Endpoint).Str("bucket", d.Bucket).Msg(err.Error())
|
||||
}
|
||||
|
8
s3/s3.go
8
s3/s3.go
@ -17,7 +17,7 @@ var (
|
||||
)
|
||||
|
||||
// UploadDirToS3 uploads the contents of a directory to S3-compatible storage
|
||||
func UploadDirToS3(directory string, s3repo types.S3Repo) error {
|
||||
func UploadDirToS3(directory string, s3repo types.S3Repo, options *minio.PutObjectOptions) error {
|
||||
// Initialize minio client object.
|
||||
client, err := minio.New(s3repo.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(s3repo.AccessKey, s3repo.SecretKey, s3repo.Token),
|
||||
@ -51,7 +51,11 @@ func UploadDirToS3(directory string, s3repo types.S3Repo) error {
|
||||
// Upload the file to S3-compatible storage
|
||||
objectName := filepath.ToSlash(path[len(directory)+1:]) // Object name in bucket
|
||||
|
||||
_, err = client.PutObject(context.Background(), s3repo.Bucket, objectName, file, stat.Size(), minio.PutObjectOptions{})
|
||||
if options == nil {
|
||||
options = &minio.PutObjectOptions{}
|
||||
}
|
||||
|
||||
_, err = client.PutObject(context.Background(), s3repo.Bucket, objectName, file, stat.Size(), *options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -535,15 +535,16 @@ func StatRemote(remoteURL, sshURL string, repo GenRepo) bool {
|
||||
}
|
||||
|
||||
type S3Repo struct {
|
||||
Bucket string `yaml:"bucket"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
AccessKey string `yaml:"accesskey"`
|
||||
SecretKey string `yaml:"secretkey"`
|
||||
Token string `yaml:"token"`
|
||||
Region string `yaml:"region"`
|
||||
UseSSL bool `yaml:"usessl"`
|
||||
Structured bool `yaml:"structured"`
|
||||
Zip bool `yaml:"zip"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
AccessKey string `yaml:"accesskey"`
|
||||
SecretKey string `yaml:"secretkey"`
|
||||
Token string `yaml:"token"`
|
||||
Region string `yaml:"region"`
|
||||
UseSSL bool `yaml:"usessl"`
|
||||
Structured bool `yaml:"structured"`
|
||||
Zip bool `yaml:"zip"`
|
||||
StorageClass string `yaml:"storageclass"`
|
||||
}
|
||||
|
||||
func (s3 S3Repo) GetKey(accessString string) (string, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user