Consider failed casting to error response, use established minio bootstrap in tests

This commit is contained in:
Frederik Ring 2022-10-12 21:15:17 +02:00
parent dec7d7e2c0
commit 5c7856feb3
6 changed files with 22 additions and 30 deletions

View File

@ -4,8 +4,8 @@
package main package main
import ( import (
"os"
"fmt" "fmt"
"os"
"regexp" "regexp"
"time" "time"
) )
@ -62,14 +62,14 @@ type Config struct {
} }
func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) { func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) {
if secretPath != "" { if secretPath == "" {
return envVar, nil
}
data, err := os.ReadFile(secretPath) data, err := os.ReadFile(secretPath)
if err != nil { if err != nil {
return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err) return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err)
} }
return string(data), nil return string(data), nil
}
return envVar, nil
} }
type RegexpDecoder struct { type RegexpDecoder struct {

View File

@ -100,9 +100,11 @@ func (b *s3Storage) Copy(file string) error {
ContentType: "application/tar+gzip", ContentType: "application/tar+gzip",
StorageClass: b.storageClass, StorageClass: b.storageClass,
}); err != nil { }); err != nil {
errResp := minio.ToErrorResponse(err) if errResp := minio.ToErrorResponse(err); errResp.Message != "" {
return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: [Message]: '%s', [Code]: %s, [StatusCode]: %d", errResp.Message, errResp.Code, errResp.StatusCode) return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: [Message]: '%s', [Code]: %s, [StatusCode]: %d", errResp.Message, errResp.Code, errResp.StatusCode)
} }
return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: %w", err)
}
b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup `%s` to bucket `%s`.", file, b.bucket) b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup `%s` to bucket `%s`.", file, b.bucket)
return nil return nil

View File

@ -4,31 +4,19 @@
version: '3.8' version: '3.8'
services: services:
minio_setup:
image: alpine:latest
deploy:
restart_policy:
condition: none
volumes:
- backup_data:/data
command: mkdir -p /data/backup
minio: minio:
image: minio/minio:RELEASE.2021-12-20T22-07-16Z image: minio/minio:RELEASE.2020-08-04T23-10-51Z
deploy: deploy:
restart_policy: restart_policy:
condition: on-failure condition: on-failure
environment: environment:
MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user MINIO_ROOT_USER: test
MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password MINIO_ROOT_PASSWORD: test
command: minio server /data MINIO_ACCESS_KEY: test
MINIO_SECRET_KEY: GMusLtUmILge2by+z890kQ
entrypoint: /bin/ash -c 'mkdir -p /data/backup && minio server /data'
volumes: volumes:
- backup_data:/data - backup_data:/data
secrets:
- minio_root_user
- minio_root_password
depends_on:
- minio_setup
backup: backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary} image: offen/docker-volume-backup:${TEST_VERSION:-canary}
@ -81,6 +69,7 @@ volumes:
backup_data: backup_data:
name: backup_data name: backup_data
pg_data: pg_data:
name: pg_data
secrets: secrets:
minio_root_user: minio_root_user:

View File

@ -41,4 +41,4 @@ docker swarm leave --force
sleep 10 sleep 10
docker volume rm backup_data docker volume rm backup_data
docker volume rm test_stack_pg_data docker volume rm pg_data

View File

@ -66,3 +66,4 @@ volumes:
backup_data: backup_data:
name: backup_data name: backup_data
pg_data: pg_data:
name: pg_data

View File

@ -34,4 +34,4 @@ docker swarm leave --force
sleep 10 sleep 10
docker volume rm backup_data docker volume rm backup_data
docker volume rm test_stack_pg_data docker volume rm pg_data