diff --git a/cmd/web-api/main.go b/cmd/web-api/main.go index e684037..bf36035 100644 --- a/cmd/web-api/main.go +++ b/cmd/web-api/main.go @@ -535,7 +535,6 @@ func main() { log.Printf("main : Graceful shutdown did not complete in %v : %v", cfg.Service.ShutdownTimeout, err) err = api.Close() } - } // Log the status of this shutdown. diff --git a/tools/devops/cmd/cicd/service.go b/tools/devops/cmd/cicd/service.go index e681f23..84a7087 100644 --- a/tools/devops/cmd/cicd/service.go +++ b/tools/devops/cmd/cicd/service.go @@ -148,7 +148,16 @@ func releaseTag(env, serviceName string) string { // Generate tags for the release image. 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 releaseTag = tag2 } else { diff --git a/tools/devops/cmd/cicd/service_deploy.go b/tools/devops/cmd/cicd/service_deploy.go index add327b..8cb50dc 100644 --- a/tools/devops/cmd/cicd/service_deploy.go +++ b/tools/devops/cmd/cicd/service_deploy.go @@ -7,7 +7,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/aws/aws-sdk-go/service/cloudfront" "io/ioutil" "log" "net/url" @@ -18,6 +17,7 @@ import ( "strings" "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/schema" "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"), 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) } + 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. // Custom subnets outside of the default VPC are not currently supported. 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. 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") @@ -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) } - 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.