diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 11963a1..58df7ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -96,6 +96,7 @@ webapp:deploy:dev: STATIC_FILES_IMG_RESIZE: 'true' AWS_USE_ROLE: 'true' EMAIL_SENDER: 'lee+saas-starter-kit@geeksinthewoods.com' + WEB_API_BASE_URL: https://api.eproc.tech webapi:build:dev: <<: *build_tmpl @@ -136,6 +137,7 @@ webapi:deploy:dev: STATIC_FILES_IMG_RESIZE: 'false' AWS_USE_ROLE: 'true' EMAIL_SENDER: 'lee+saas-starter-kit@geeksinthewoods.com' + WEB_APP_BASE_URL: https://eproc.tech #ddlogscollector:deploy:stage: # <<: *deploy_stage_tmpl diff --git a/cmd/web-api/ecs-task-definition.json b/cmd/web-api/ecs-task-definition.json index c003b27..dc78985 100644 --- a/cmd/web-api/ecs-task-definition.json +++ b/cmd/web-api/ecs-task-definition.json @@ -39,6 +39,7 @@ {"name": "WEB_API_SERVICE_HOST_NAMES", "value": "{HOST_NAMES}"}, {"name": "WEB_API_SERVICE_ENABLE_HTTPS", "value": "{HTTPS_ENABLED}"}, {"name": "WEB_API_SERVICE_EMAIL_SENDER", "value": "{EMAIL_SENDER}"}, + {"name": "WEB_API_SERVICE_WEB_APP_BASE_URL", "value": "{WEB_APP_BASE_URL}"}, {"name": "WEB_API_REDIS_HOST", "value": "{CACHE_HOST}"}, {"name": "WEB_API_DB_HOST", "value": "{DB_HOST}"}, {"name": "WEB_API_DB_USER", "value": "{DB_USER}"}, diff --git a/cmd/web-app/ecs-task-definition.json b/cmd/web-app/ecs-task-definition.json index bc8f1d3..1132f7a 100644 --- a/cmd/web-app/ecs-task-definition.json +++ b/cmd/web-app/ecs-task-definition.json @@ -43,6 +43,7 @@ {"name": "WEB_APP_SERVICE_STATICFILES_CLOUDFRONT_ENABLED", "value": "{STATIC_FILES_CLOUDFRONT_ENABLED}"}, {"name": "WEB_APP_SERVICE_STATICFILES_IMG_RESIZE_ENABLED", "value": "{STATIC_FILES_IMG_RESIZE_ENABLED}"}, {"name": "WEB_APP_SERVICE_EMAIL_SENDER", "value": "{EMAIL_SENDER}"}, + {"name": "WEB_APP_SERVICE_WEB_API_BASE_URL", "value": "{WEB_API_BASE_URL}"}, {"name": "WEB_APP_REDIS_HOST", "value": "{CACHE_HOST}"}, {"name": "WEB_APP_DB_HOST", "value": "{DB_HOST}"}, {"name": "WEB_APP_DB_USER", "value": "{DB_USER}"}, diff --git a/cmd/web-app/main.go b/cmd/web-app/main.go index 3a15f03..e1dd427 100644 --- a/cmd/web-app/main.go +++ b/cmd/web-app/main.go @@ -487,7 +487,7 @@ func main() { staticS3UrlFormatter = func(p string) string { // When the path starts with a forward slash its referencing a local file, // make sure the static file prefix is included - if strings.HasPrefix(p, "/") { + if strings.HasPrefix(p, "/") || !strings.HasPrefix(p, "://") { p = filepath.Join(cfg.Service.StaticFiles.S3Prefix, p) } return s3UrlFormatter(p) @@ -565,7 +565,7 @@ func main() { "SiteAssetUrl": func(p string) string { var u string if staticUrlFormatter != nil { - u = staticUrlFormatter(filepath.Join(cfg.Service.Name, p)) + u = staticUrlFormatter(p) } else { if !strings.HasPrefix(p, "/") { p = "/" + p diff --git a/tools/devops/cmd/cicd/s3_batch_upload.go b/tools/devops/cmd/cicd/s3_batch_upload.go index 8ce03e4..dd09c98 100644 --- a/tools/devops/cmd/cicd/s3_batch_upload.go +++ b/tools/devops/cmd/cicd/s3_batch_upload.go @@ -2,13 +2,14 @@ package cicd import ( "bytes" - "net/http" - "os" - "path/filepath" - + "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/pkg/errors" + "io" + "net/http" + "os" + "path/filepath" ) // DirectoryIterator represents an iterator of a specified directory @@ -76,11 +77,20 @@ func (di *DirectoryIterator) UploadObject() s3manager.BatchUploadObject { } // Get file size and read the file content into a buffer - fileInfo, _ := f.Stat() + fileInfo, err := f.Stat() + if err != nil { + fmt.Println(err) + } var size int64 = fileInfo.Size() buffer := make([]byte, size) f.Read(buffer) + f.Seek(0, io.SeekStart) + + ctBuf := make([]byte, 512) + f.Read(ctBuf) + contentType := http.DetectContentType(ctBuf) + nextPath, _ := filepath.Rel(di.dir, di.next.path) return s3manager.BatchUploadObject{ @@ -88,7 +98,7 @@ func (di *DirectoryIterator) UploadObject() s3manager.BatchUploadObject { Bucket: aws.String(di.bucket), Key: aws.String(filepath.Join(di.keyPrefix, nextPath)), Body: bytes.NewReader(buffer), - ContentType: aws.String(http.DetectContentType(buffer)), + ContentType: aws.String(contentType), ACL: acl, }, After: func() error {