1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-08-08 22:36:41 +02:00

fix web-app static file prefix for s3

This commit is contained in:
Lee Brown
2019-07-14 23:53:31 -08:00
parent 5df14e5162
commit cf77e9d9eb
3 changed files with 36 additions and 5 deletions

View File

@ -535,7 +535,6 @@ func main() {
log.Printf("main : Graceful shutdown did not complete in %v : %v", cfg.Service.ShutdownTimeout, err) log.Printf("main : Graceful shutdown did not complete in %v : %v", cfg.Service.ShutdownTimeout, err)
err = api.Close() err = api.Close()
} }
} }
// Log the status of this shutdown. // Log the status of this shutdown.

View File

@ -148,7 +148,16 @@ func releaseTag(env, serviceName string) string {
// Generate tags for the release image. // Generate tags for the release image.
var releaseTag string var releaseTag string
if v := os.Getenv("CI_COMMIT_REF_NAME"); v != "" { if v := os.Getenv("BUILDINFO_CI_COMMIT_SHA"); v != "" {
tag2 := tag1 + "-" + v[0:8]
releaseTag = tag2
} else if v := os.Getenv("CI_COMMIT_SHA"); v != "" {
tag2 := tag1 + "-" + v[0:8]
releaseTag = tag2
} else if v := os.Getenv("BUILDINFO_CI_COMMIT_REF_NAME"); v != "" {
tag2 := tag1 + "-" + v
releaseTag = tag2
} else if v := os.Getenv("CI_COMMIT_REF_NAME"); v != "" {
tag2 := tag1 + "-" + v tag2 := tag1 + "-" + v
releaseTag = tag2 releaseTag = tag2
} else { } else {

View File

@ -7,7 +7,6 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/aws/aws-sdk-go/service/cloudfront"
"io/ioutil" "io/ioutil"
"log" "log"
"net/url" "net/url"
@ -18,6 +17,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/aws/aws-sdk-go/service/cloudfront"
"geeks-accelerator/oss/saas-starter-kit/internal/platform/tests" "geeks-accelerator/oss/saas-starter-kit/internal/platform/tests"
"geeks-accelerator/oss/saas-starter-kit/internal/schema" "geeks-accelerator/oss/saas-starter-kit/internal/schema"
"geeks-accelerator/oss/saas-starter-kit/tools/devops/internal/retry" "geeks-accelerator/oss/saas-starter-kit/tools/devops/internal/retry"
@ -328,6 +328,7 @@ func NewServiceDeployRequest(log *log.Logger, flags ServiceDeployFlags) (*servic
PriceClass: aws.String("PriceClass_All"), PriceClass: aws.String("PriceClass_All"),
CallerReference: aws.String("devops-deploy"), CallerReference: aws.String("devops-deploy"),
} }
req.CloudfrontPublic = nil
} }
} }
@ -1067,6 +1068,28 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
log.Printf("\t%s\tS3 buckets configured successfully.\n", tests.Success) log.Printf("\t%s\tS3 buckets configured successfully.\n", tests.Success)
} }
if req.CloudfrontPublic != nil {
log.Println("Cloudfront - Setup Distribution")
svc := cloudfront.New(req.awsSession())
_, err := svc.CreateDistribution(&cloudfront.CreateDistributionInput{
DistributionConfig: req.CloudfrontPublic,
} )
if err != nil {
if aerr, ok := err.(awserr.Error); !ok || (aerr.Code() != cloudfront.ErrCodeDistributionAlreadyExists) {
return errors.Wrapf(err, "Failed to create cloudfront distribution '%s'", *req.CloudfrontPublic.DefaultCacheBehavior.TargetOriginId)
}
// If bucket found during create, returns it.
log.Printf("\t\tFound: %s.", *req.CloudfrontPublic.DefaultCacheBehavior.TargetOriginId)
} else {
// If no bucket found during create, create new one.
log.Printf("\t\tCreated: %s.", *req.CloudfrontPublic.DefaultCacheBehavior.TargetOriginId)
}
}
// Find the default VPC and associated subnets. // Find the default VPC and associated subnets.
// Custom subnets outside of the default VPC are not currently supported. // Custom subnets outside of the default VPC are not currently supported.
var projectSubnetsIDs []string var projectSubnetsIDs []string
@ -3254,7 +3277,7 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
// When static files are enabled to be to stored on S3, we need to upload all of them. // When static files are enabled to be to stored on S3, we need to upload all of them.
if req.StaticFilesS3Enable { if req.StaticFilesS3Enable {
log.Println("\tSync static files to public S3 bucket") log.Println("\tUpload static files to public S3 bucket")
staticDir := filepath.Join(req.ServiceDir, "static") staticDir := filepath.Join(req.ServiceDir, "static")
@ -3263,7 +3286,7 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
return errors.Wrapf(err, "Failed to sync static files from %s to s3://%s/%s", staticDir, req.S3BucketPublicName, req.StaticFilesS3Prefix) return errors.Wrapf(err, "Failed to sync static files from %s to s3://%s/%s", staticDir, req.S3BucketPublicName, req.StaticFilesS3Prefix)
} }
log.Printf("\t%s\tFiles uploaded.\n", tests.Success) log.Printf("\t%s\tFiles uploaded to s3://%s/%s.\n", tests.Success, req.S3BucketPublicName, req.StaticFilesS3Prefix)
} }
// Wait for the updated or created service to enter a stable state. // Wait for the updated or created service to enter a stable state.