mirror of
				https://github.com/offen/docker-volume-backup.git
				synced 2025-11-01 01:46:00 +08:00 
			
		
		
		
	Consider failed casting to error response, use established minio bootstrap in tests
This commit is contained in:
		
							parent
							
								
									dec7d7e2c0
								
							
						
					
					
						commit
						5c7856feb3
					
				
					 6 changed files with 22 additions and 30 deletions
				
			
		|  | @ -4,8 +4,8 @@ | |||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"regexp" | ||||
| 	"time" | ||||
| ) | ||||
|  | @ -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 | ||||
| 	} | ||||
| 	return envVar, nil | ||||
| 	data, err := os.ReadFile(secretPath) | ||||
| 	if err != nil { | ||||
| 		return "", fmt.Errorf("resolveSecret: error reading secret path: %w", err) | ||||
| 	} | ||||
| 	return string(data), nil | ||||
| } | ||||
| 
 | ||||
| type RegexpDecoder struct { | ||||
|  |  | |||
|  | @ -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) | ||||
| 
 | ||||
|  |  | |||
|  | @ -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} | ||||
|  | @ -81,6 +69,7 @@ volumes: | |||
|   backup_data: | ||||
|     name: backup_data | ||||
|   pg_data: | ||||
|     name: pg_data | ||||
| 
 | ||||
| secrets: | ||||
|   minio_root_user: | ||||
|  | @ -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 | ||||
|  | @ -66,3 +66,4 @@ volumes: | |||
|   backup_data: | ||||
|     name: backup_data | ||||
|   pg_data: | ||||
|     name: pg_data | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue