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

fix devops upload content type

This commit is contained in:
Lee Brown
2019-08-07 13:10:17 -08:00
parent 69a2a40369
commit e8f0f68d20
5 changed files with 22 additions and 8 deletions

View File

@@ -96,6 +96,7 @@ webapp:deploy:dev:
STATIC_FILES_IMG_RESIZE: 'true' STATIC_FILES_IMG_RESIZE: 'true'
AWS_USE_ROLE: 'true' AWS_USE_ROLE: 'true'
EMAIL_SENDER: 'lee+saas-starter-kit@geeksinthewoods.com' EMAIL_SENDER: 'lee+saas-starter-kit@geeksinthewoods.com'
WEB_API_BASE_URL: https://api.eproc.tech
webapi:build:dev: webapi:build:dev:
<<: *build_tmpl <<: *build_tmpl
@@ -136,6 +137,7 @@ webapi:deploy:dev:
STATIC_FILES_IMG_RESIZE: 'false' STATIC_FILES_IMG_RESIZE: 'false'
AWS_USE_ROLE: 'true' AWS_USE_ROLE: 'true'
EMAIL_SENDER: 'lee+saas-starter-kit@geeksinthewoods.com' EMAIL_SENDER: 'lee+saas-starter-kit@geeksinthewoods.com'
WEB_APP_BASE_URL: https://eproc.tech
#ddlogscollector:deploy:stage: #ddlogscollector:deploy:stage:
# <<: *deploy_stage_tmpl # <<: *deploy_stage_tmpl

View File

@@ -39,6 +39,7 @@
{"name": "WEB_API_SERVICE_HOST_NAMES", "value": "{HOST_NAMES}"}, {"name": "WEB_API_SERVICE_HOST_NAMES", "value": "{HOST_NAMES}"},
{"name": "WEB_API_SERVICE_ENABLE_HTTPS", "value": "{HTTPS_ENABLED}"}, {"name": "WEB_API_SERVICE_ENABLE_HTTPS", "value": "{HTTPS_ENABLED}"},
{"name": "WEB_API_SERVICE_EMAIL_SENDER", "value": "{EMAIL_SENDER}"}, {"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_REDIS_HOST", "value": "{CACHE_HOST}"},
{"name": "WEB_API_DB_HOST", "value": "{DB_HOST}"}, {"name": "WEB_API_DB_HOST", "value": "{DB_HOST}"},
{"name": "WEB_API_DB_USER", "value": "{DB_USER}"}, {"name": "WEB_API_DB_USER", "value": "{DB_USER}"},

View File

@@ -43,6 +43,7 @@
{"name": "WEB_APP_SERVICE_STATICFILES_CLOUDFRONT_ENABLED", "value": "{STATIC_FILES_CLOUDFRONT_ENABLED}"}, {"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_STATICFILES_IMG_RESIZE_ENABLED", "value": "{STATIC_FILES_IMG_RESIZE_ENABLED}"},
{"name": "WEB_APP_SERVICE_EMAIL_SENDER", "value": "{EMAIL_SENDER}"}, {"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_REDIS_HOST", "value": "{CACHE_HOST}"},
{"name": "WEB_APP_DB_HOST", "value": "{DB_HOST}"}, {"name": "WEB_APP_DB_HOST", "value": "{DB_HOST}"},
{"name": "WEB_APP_DB_USER", "value": "{DB_USER}"}, {"name": "WEB_APP_DB_USER", "value": "{DB_USER}"},

View File

@@ -487,7 +487,7 @@ func main() {
staticS3UrlFormatter = func(p string) string { staticS3UrlFormatter = func(p string) string {
// When the path starts with a forward slash its referencing a local file, // When the path starts with a forward slash its referencing a local file,
// make sure the static file prefix is included // 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) p = filepath.Join(cfg.Service.StaticFiles.S3Prefix, p)
} }
return s3UrlFormatter(p) return s3UrlFormatter(p)
@@ -565,7 +565,7 @@ func main() {
"SiteAssetUrl": func(p string) string { "SiteAssetUrl": func(p string) string {
var u string var u string
if staticUrlFormatter != nil { if staticUrlFormatter != nil {
u = staticUrlFormatter(filepath.Join(cfg.Service.Name, p)) u = staticUrlFormatter(p)
} else { } else {
if !strings.HasPrefix(p, "/") { if !strings.HasPrefix(p, "/") {
p = "/" + p p = "/" + p

View File

@@ -2,13 +2,14 @@ package cicd
import ( import (
"bytes" "bytes"
"net/http" "fmt"
"os"
"path/filepath"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/pkg/errors" "github.com/pkg/errors"
"io"
"net/http"
"os"
"path/filepath"
) )
// DirectoryIterator represents an iterator of a specified directory // 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 // 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() var size int64 = fileInfo.Size()
buffer := make([]byte, size) buffer := make([]byte, size)
f.Read(buffer) 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) nextPath, _ := filepath.Rel(di.dir, di.next.path)
return s3manager.BatchUploadObject{ return s3manager.BatchUploadObject{
@@ -88,7 +98,7 @@ func (di *DirectoryIterator) UploadObject() s3manager.BatchUploadObject {
Bucket: aws.String(di.bucket), Bucket: aws.String(di.bucket),
Key: aws.String(filepath.Join(di.keyPrefix, nextPath)), Key: aws.String(filepath.Join(di.keyPrefix, nextPath)),
Body: bytes.NewReader(buffer), Body: bytes.NewReader(buffer),
ContentType: aws.String(http.DetectContentType(buffer)), ContentType: aws.String(contentType),
ACL: acl, ACL: acl,
}, },
After: func() error { After: func() error {