mirror of
https://github.com/cooperspencer/gickup.git
synced 2025-05-11 09:45:36 +02:00
add support for specifying storageclass for S3 dest (#307)
This commit is contained in:
parent
69ddf8b24a
commit
00d278094a
5 changed files with 25 additions and 12 deletions
|
@ -279,6 +279,7 @@ destination:
|
||||||
token: your-token # can be an environment variable, just don't add a $ in front of it
|
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
|
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
|
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.
|
cron: 0 22 * * * # optional - when cron is not provided, the program runs once and exits.
|
||||||
# Otherwise, it runs according to the cron schedule.
|
# Otherwise, it runs according to the cron schedule.
|
||||||
# See timezone commentary in docker-compose.yml for making sure this container runs
|
# See timezone commentary in docker-compose.yml for making sure this container runs
|
||||||
|
|
|
@ -546,6 +546,10 @@
|
||||||
"zip": {
|
"zip": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "If true, zip the entire Git repo into a single zip file and upload that instead"
|
"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
|
"additionalProperties": false
|
||||||
|
|
5
main.go
5
main.go
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/cooperspencer/gickup/sourcehut"
|
"github.com/cooperspencer/gickup/sourcehut"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
|
|
||||||
"github.com/alecthomas/kong"
|
"github.com/alecthomas/kong"
|
||||||
"github.com/cooperspencer/gickup/bitbucket"
|
"github.com/cooperspencer/gickup/bitbucket"
|
||||||
|
@ -264,7 +265,9 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = s3.UploadDirToS3(tempdir, d)
|
err = s3.UploadDirToS3(tempdir, d, &minio.PutObjectOptions{
|
||||||
|
StorageClass: d.StorageClass,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Str("stage", "s3").Str("endpoint", d.Endpoint).Str("bucket", d.Bucket).Msg(err.Error())
|
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
|
// 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.
|
// Initialize minio client object.
|
||||||
client, err := minio.New(s3repo.Endpoint, &minio.Options{
|
client, err := minio.New(s3repo.Endpoint, &minio.Options{
|
||||||
Creds: credentials.NewStaticV4(s3repo.AccessKey, s3repo.SecretKey, s3repo.Token),
|
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
|
// Upload the file to S3-compatible storage
|
||||||
objectName := filepath.ToSlash(path[len(directory)+1:]) // Object name in bucket
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -535,15 +535,16 @@ func StatRemote(remoteURL, sshURL string, repo GenRepo) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type S3Repo struct {
|
type S3Repo struct {
|
||||||
Bucket string `yaml:"bucket"`
|
Bucket string `yaml:"bucket"`
|
||||||
Endpoint string `yaml:"endpoint"`
|
Endpoint string `yaml:"endpoint"`
|
||||||
AccessKey string `yaml:"accesskey"`
|
AccessKey string `yaml:"accesskey"`
|
||||||
SecretKey string `yaml:"secretkey"`
|
SecretKey string `yaml:"secretkey"`
|
||||||
Token string `yaml:"token"`
|
Token string `yaml:"token"`
|
||||||
Region string `yaml:"region"`
|
Region string `yaml:"region"`
|
||||||
UseSSL bool `yaml:"usessl"`
|
UseSSL bool `yaml:"usessl"`
|
||||||
Structured bool `yaml:"structured"`
|
Structured bool `yaml:"structured"`
|
||||||
Zip bool `yaml:"zip"`
|
Zip bool `yaml:"zip"`
|
||||||
|
StorageClass string `yaml:"storageclass"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s3 S3Repo) GetKey(accessString string) (string, error) {
|
func (s3 S3Repo) GetKey(accessString string) (string, error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue