Skip to content

Commit

Permalink
feat: add test environment with proper docker-compose using MinIO + a…
Browse files Browse the repository at this point in the history
…dd compatibility for it to AWS provider (#165)

* feat: docker-compose for test environment using MinIO

* feat: update AWS provider to be compatible with MinIO (and others S3 compatible ones)

* feat: replace AWS_OTHER_COMPATIBLE_PROVIDER by two distinct generic parameters
  • Loading branch information
hbollon authored and raphink committed Jun 16, 2021
1 parent 71cfc24 commit 6d44ecb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/config.go
Expand Up @@ -74,12 +74,20 @@ type WebConfig struct {
LogoutURL string `long:"logout-url" env:"TERRABOARD_LOGOUT_URL" yaml:"logout-url" description:"Logout URL."`
}

// ProviderConfig stores genral provider parameters
type ProviderConfig struct {
NoVersioning bool `long:"no-versioning" env:"TERRABOARD_NO_VERSIONING" yaml:"no-versioning" description:"Disable versioning support from Terraboard (useful for S3 compatible providers like MinIO)"`
NoLocks bool `long:"no-locks" env:"TERRABOARD_NO_LOCKS" yaml:"no-locks" description:"Disable locks support from Terraboard (useful for S3 compatible providers like MinIO)"`
}

// Config stores the handler's configuration and UI interface parameters
type Config struct {
Version bool `short:"V" long:"version" description:"Display version."`

ConfigFilePath string `short:"c" long:"config-file" env:"CONFIG_FILE" description:"Config File path"`

Provider ProviderConfig `group:"General Provider Options" yaml:"provider"`

Log LogConfig `group:"Logging Options" yaml:"log"`

DB DBConfig `group:"Database Options" yaml:"database"`
Expand Down
4 changes: 4 additions & 0 deletions example.yml
Expand Up @@ -11,6 +11,10 @@ database:
no-sync: false
sync-interval: 5

provider:
no-locks: "true"
no-versioning: "false"

aws:
dynamodb-table: terraboard
s3:
Expand Down
21 changes: 20 additions & 1 deletion state/aws.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

aws_sdk "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
Expand All @@ -25,6 +26,8 @@ type AWS struct {
dynamoTable string
keyPrefix string
fileExtension []string
noLocks bool
noVersioning bool
}

// NewAWS creates an AWS object
Expand Down Expand Up @@ -58,11 +61,18 @@ func NewAWS(c *config.Config) AWS {
fileExtension: c.AWS.S3.FileExtension,
dynamoSvc: dynamodb.New(sess, awsConfig),
dynamoTable: c.AWS.DynamoDBTable,
noLocks: c.Provider.NoLocks,
noVersioning: c.Provider.NoVersioning,
}
}

// GetLocks returns a map of locks by State path
func (a *AWS) GetLocks() (locks map[string]LockInfo, err error) {
if a.noLocks {
locks = make(map[string]LockInfo)
return
}

if a.dynamoTable == "" {
err = fmt.Errorf("no dynamoDB table provided, not getting locks")
return
Expand Down Expand Up @@ -94,6 +104,7 @@ func (a *AWS) GetLocks() (locks map[string]LockInfo, err error) {
locks[strings.TrimPrefix(info.Path, infoPrefix)] = info
}
}

return
}

Expand Down Expand Up @@ -138,7 +149,7 @@ func (a *AWS) GetState(st, versionID string) (sf *statefile.File, err error) {
Bucket: aws_sdk.String(a.bucket),
Key: aws_sdk.String(st),
}
if versionID != "" {
if versionID != "" && !a.noVersioning {
input.VersionId = &versionID
}
result, err := a.svc.GetObjectWithContext(context.Background(), input)
Expand Down Expand Up @@ -168,6 +179,14 @@ func (a *AWS) GetState(st, versionID string) (sf *statefile.File, err error) {
// GetVersions returns a slice of Version objects
func (a *AWS) GetVersions(state string) (versions []Version, err error) {
versions = []Version{}
if a.noVersioning {
versions = append(versions, Version{
ID: "1",
LastModified: time.Now(),
})
return
}

result, err := a.svc.ListObjectVersions(&s3.ListObjectVersionsInput{
Bucket: aws_sdk.String(a.bucket),
Prefix: aws_sdk.String(state),
Expand Down
2 changes: 2 additions & 0 deletions test/.gitignore
@@ -0,0 +1,2 @@
data/*
!data/test-bucket
Empty file added test/data/test-bucket/.gitkeep
Empty file.
62 changes: 62 additions & 0 deletions test/docker-compose.yml
@@ -0,0 +1,62 @@
---
version: "3"
services:
terraboard-dev:
build:
context: ../
dockerfile: ./Dockerfile
environment:
AWS_ACCESS_KEY_ID: root
AWS_SECRET_ACCESS_KEY: mypassword
AWS_BUCKET: test-bucket
AWS_REGION: eu-west-1
AWS_ENDPOINT: http://minio:9000/
AWS_FORCE_PATH_STYLE: "true"
TERRABOARD_LOG_LEVEL: debug
TERRABOARD_NO_LOCKS: "true"
TERRABOARD_NO_VERSIONING: "true"
DB_PASSWORD: mypassword
DB_SSLMODE: disable
GODEBUG: netdns=go
depends_on:
- "db"
- "minio"
volumes:
- ../static:/static:ro
ports:
- "8080:8080"

minio:
image: minio/minio:latest
environment:
MINIO_ROOT_USER: root
MINIO_ROOT_PASSWORD: mypassword
expose:
- "9000"
ports:
- "9200:9000"
volumes:
- ./data:/data
command: server /data

db:
image: postgres:9.5
environment:
POSTGRES_USER: gorm
POSTGRES_PASSWORD: mypassword
POSTGRES_DB: gorm
volumes:
- tb-data:/var/lib/postgresql/data

pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"

volumes:
tb-data: {}

0 comments on commit 6d44ecb

Please sign in to comment.