1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-06-17 00:17:59 +02:00

fixing deploy script

This commit is contained in:
Lee Brown
2019-08-13 17:08:19 -08:00
parent 56f7fb08b9
commit 09b4ff8171
6 changed files with 41 additions and 23 deletions

View File

@ -1406,7 +1406,7 @@ func TestUserToken(t *testing.T) {
expected := weberror.ErrorResponse{ expected := weberror.ErrorResponse{
StatusCode: expectedStatus, StatusCode: expectedStatus,
Error: "Field validation error", Error: "Field validation error",
Fields: []weberror.FieldError{ Fields: []weberror.FieldError{
{ {
Field: "username", Field: "username",

View File

@ -12,15 +12,15 @@ import (
"testing" "testing"
"time" "time"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/docker"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext" "geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"geeks-accelerator/oss/saas-starter-kit/internal/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/ec2metadata" "github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/kelseyhightower/envconfig"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/docker"
"geeks-accelerator/oss/saas-starter-kit/internal/schema"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/kelseyhightower/envconfig"
) )
// Success and failure markers. // Success and failure markers.
@ -48,15 +48,14 @@ func New() *Test {
log := log.New(os.Stdout, "TEST : ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile) log := log.New(os.Stdout, "TEST : ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile)
// ========================================================================= // =========================================================================
// Configuration // Configuration
var cfg struct { var cfg struct {
Aws struct { Aws struct {
AccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID"` // WEB_API_AWS_AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY_ID AccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID"` // WEB_API_AWS_AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY_ID
SecretAccessKey string `envconfig:"AWS_SECRET_ACCESS_KEY" json:"-"` // don't print SecretAccessKey string `envconfig:"AWS_SECRET_ACCESS_KEY" json:"-"` // don't print
Region string `default:"us-west-2" envconfig:"AWS_REGION"` Region string `default:"us-west-2" envconfig:"AWS_REGION"`
UseRole bool `envconfig:"AWS_USE_ROLE"` UseRole bool `envconfig:"AWS_USE_ROLE"`
} }
} }
@ -65,7 +64,6 @@ func New() *Test {
log.Fatalf("startup : Parsing Config : %+v", err) log.Fatalf("startup : Parsing Config : %+v", err)
} }
// AWS access keys are required, if roles are enabled, remove any placeholders. // AWS access keys are required, if roles are enabled, remove any placeholders.
if cfg.Aws.UseRole { if cfg.Aws.UseRole {
cfg.Aws.AccessKeyID = "" cfg.Aws.AccessKeyID = ""
@ -97,7 +95,6 @@ func New() *Test {
log.Printf("startup : Config : %v\n", string(cfgJSON)) log.Printf("startup : Config : %v\n", string(cfgJSON))
} }
// ============================================================ // ============================================================
// Init AWS Session // Init AWS Session
var awsSession *session.Session var awsSession *session.Session
@ -118,7 +115,6 @@ func New() *Test {
log.Printf("startup : AWS : Using static credentials\n") log.Printf("startup : AWS : Using static credentials\n")
} }
// ============================================================ // ============================================================
// Startup Postgres container // Startup Postgres container

View File

@ -16,7 +16,7 @@ import (
// Headers // Headers
const ( const (
HeaderAccept = "Accept" HeaderAccept = "Accept"
HeaderUpgrade = "Upgrade" HeaderUpgrade = "Upgrade"
HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedFor = "X-Forwarded-For"
HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProto = "X-Forwarded-Proto"

View File

@ -1,6 +1,7 @@
package cicd package cicd
import ( import (
"context"
"encoding/json" "encoding/json"
"log" "log"
"path/filepath" "path/filepath"
@ -144,7 +145,7 @@ func NewMigrateRequest(log *log.Logger, flags MigrateFlags) (*migrateRequest, er
} }
// Run is the main entrypoint for migration of database schema for a given target environment. // Run is the main entrypoint for migration of database schema for a given target environment.
func Migrate(log *log.Logger, req *migrateRequest) error { func Migrate(log *log.Logger, ctx context.Context, req *migrateRequest) error {
// Load the database details. // Load the database details.
var db DB var db DB
@ -200,7 +201,7 @@ func Migrate(log *log.Logger, req *migrateRequest) error {
// Start Migrations // Start Migrations
log.Printf("\t\tStart migrations.") log.Printf("\t\tStart migrations.")
if err = schema.Migrate(masterDb, log, false); err != nil { if err = schema.Migrate(ctx, masterDb, log, false); err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }

View File

@ -571,12 +571,12 @@ func NewServiceDeployRequest(log *log.Logger, flags ServiceDeployFlags) (*servic
if req.S3BucketPublicName != "" || req.S3BucketPrivateName != "" { if req.S3BucketPublicName != "" || req.S3BucketPrivateName != "" {
var bpr []string var bpr []string
if req.S3BucketPublicName != "" { if req.S3BucketPublicName != "" {
bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPublicName ) bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPublicName)
bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPublicName + "/*" ) bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPublicName+"/*")
} }
if req.S3BucketPrivateName != "" { if req.S3BucketPrivateName != "" {
bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPrivateName ) bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPrivateName)
bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPrivateName + "/*" ) bpr = append(bpr, "arn:aws:s3:::"+req.S3BucketPrivateName+"/*")
} }
bp := IamStatementEntry{ bp := IamStatementEntry{
@ -918,7 +918,7 @@ func NewServiceDeployRequest(log *log.Logger, flags ServiceDeployFlags) (*servic
} }
// Run is the main entrypoint for deploying a service for a given target environment. // Run is the main entrypoint for deploying a service for a given target environment.
func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error { func ServiceDeploy(log *log.Logger, ctx context.Context, req *serviceDeployRequest) error {
startTime := time.Now() startTime := time.Now()
@ -1533,7 +1533,7 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
// Start the database migrations. // Start the database migrations.
log.Printf("\t\tStart migrations.") log.Printf("\t\tStart migrations.")
if err = schema.Migrate(masterDb, log, false); err != nil { if err = schema.Migrate(ctx, masterDb, log, false); err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
log.Printf("\t\tFinished migrations.") log.Printf("\t\tFinished migrations.")

View File

@ -1,10 +1,13 @@
package main package main
import ( import (
"context"
"expvar" "expvar"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/web/webcontext"
"log" "log"
"os" "os"
"strings" "strings"
"time"
"geeks-accelerator/oss/saas-starter-kit/tools/devops/cmd/cicd" "geeks-accelerator/oss/saas-starter-kit/tools/devops/cmd/cicd"
_ "github.com/lib/pq" _ "github.com/lib/pq"
@ -111,7 +114,16 @@ func main() {
if err != nil { if err != nil {
return err return err
} }
return cicd.ServiceDeploy(log, req)
// Set the context with the required values to
// process the request.
v := webcontext.Values{
Now: time.Now(),
Env: req.Env,
}
ctx := context.WithValue(context.Background(), webcontext.KeyValues, &v)
return cicd.ServiceDeploy(log, ctx, req)
}, },
}, },
{ {
@ -127,7 +139,16 @@ func main() {
if err != nil { if err != nil {
return err return err
} }
return cicd.Migrate(log, req)
// Set the context with the required values to
// process the request.
v := webcontext.Values{
Now: time.Now(),
Env: req.Env,
}
ctx := context.WithValue(context.Background(), webcontext.KeyValues, &v)
return cicd.Migrate(log, ctx, req)
}, },
}, },
} }