Skip to content

Commit

Permalink
Consider failed casting to error response, use established minio boot…
Browse files Browse the repository at this point in the history
…strap in tests
  • Loading branch information
m90 committed Oct 13, 2022
1 parent dec7d7e commit 5c7856f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
16 changes: 8 additions & 8 deletions cmd/backup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package main

import (
"os"
"fmt"
"os"
"regexp"
"time"
)
Expand Down Expand Up @@ -62,14 +62,14 @@ type Config struct {
}

func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) {
if secretPath != "" {
data, err := os.ReadFile(secretPath)
if err != nil {
return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err)
}
return string(data), nil
if secretPath == "" {
return envVar, nil
}
data, err := os.ReadFile(secretPath)
if err != nil {
return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err)
}
return envVar, nil
return string(data), nil
}

type RegexpDecoder struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ func (b *s3Storage) Copy(file string) error {
ContentType: "application/tar+gzip",
StorageClass: b.storageClass,
}); err != nil {
errResp := minio.ToErrorResponse(err)
return fmt.Errorf("(*s3Storage).Copy: error uploading backup to remote storage: [Message]: '%s', [Code]: %s, [StatusCode]: %d", errResp.Message, errResp.Code, errResp.StatusCode)
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: %w", err)
}
b.Log(storage.LogLevelInfo, b.Name(), "Uploaded a copy of backup `%s` to bucket `%s`.", file, b.bucket)

Expand Down
25 changes: 7 additions & 18 deletions test/secret/docker-compose.yml → test/secrets/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,19 @@
version: '3.8'

services:
minio_setup:
image: alpine:latest
deploy:
restart_policy:
condition: none
volumes:
- backup_data:/data
command: mkdir -p /data/backup

minio:
image: minio/minio:RELEASE.2021-12-20T22-07-16Z
image: minio/minio:RELEASE.2020-08-04T23-10-51Z
deploy:
restart_policy:
condition: on-failure
environment:
MINIO_ROOT_USER_FILE: /run/secrets/minio_root_user
MINIO_ROOT_PASSWORD_FILE: /run/secrets/minio_root_password
command: minio server /data
MINIO_ROOT_USER: test
MINIO_ROOT_PASSWORD: test
MINIO_ACCESS_KEY: test
MINIO_SECRET_KEY: GMusLtUmILge2by+z890kQ
entrypoint: /bin/ash -c 'mkdir -p /data/backup && minio server /data'
volumes:
- backup_data:/data
secrets:
- minio_root_user
- minio_root_password
depends_on:
- minio_setup

backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary}
Expand Down Expand Up @@ -81,6 +69,7 @@ volumes:
backup_data:
name: backup_data
pg_data:
name: pg_data

secrets:
minio_root_user:
Expand Down
2 changes: 1 addition & 1 deletion test/secret/run.sh → test/secrets/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ docker swarm leave --force
sleep 10

docker volume rm backup_data
docker volume rm test_stack_pg_data
docker volume rm pg_data
1 change: 1 addition & 0 deletions test/swarm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ volumes:
backup_data:
name: backup_data
pg_data:
name: pg_data
2 changes: 1 addition & 1 deletion test/swarm/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ docker swarm leave --force
sleep 10

docker volume rm backup_data
docker volume rm test_stack_pg_data
docker volume rm pg_data

0 comments on commit 5c7856f

Please sign in to comment.