Skip to content

Commit

Permalink
Bump version, fix s3 object saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Maya Sergeeva committed Oct 3, 2022
1 parent 3244f57 commit 8d00cb7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGE_NAME = spacetabio/prerender-go
IMAGE_VERSION = 0.3.1
IMAGE_VERSION = v1.0.0

deps:
go mod vendor
Expand Down Expand Up @@ -83,4 +83,6 @@ image_build:
docker build -t ${IMAGE_NAME}:${IMAGE_VERSION} .

image_push:
docker push ${IMAGE_NAME}:${IMAGE_VERSION}
docker push ${IMAGE_NAME}:${IMAGE_VERSION}

image: image_build image_push
2 changes: 1 addition & 1 deletion configuration/defaults/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defaults:
alias: "prerender"
name: "SPA prerender"
about: "Приложение для рендера SPA приложений как html странички"
version: "0.4.0"
version: "1.0.1"
docs: "---"
contacts: "[email protected]"
copyright: "SpaceTab © 2022"
4 changes: 1 addition & 3 deletions pkg/repository/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package repository

import (
"errors"
"strings"

cfg "github.com/spacetab-io/prerender-go/configuration"
"github.com/spacetab-io/prerender-go/pkg/repository/files"
Expand All @@ -20,9 +19,8 @@ var ErrUnknownType = errors.New("storage type is unknown or not set")
func NewRepository(storageCfg cfg.StorageConfig) (service.Repository, error) {
switch storageCfg.Type {
case LocalStorage:
return files.NewStorage(strings.TrimRight(storageCfg.Local.StoragePath, "/")), nil
return files.NewStorage(storageCfg.Local.StoragePath), nil
case S3Storage:
//return bucket.NewRepository(storageCfg.S3)
return s3.NewStorage(storageCfg.S3)
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/repository/files/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package files

import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/spacetab-io/prerender-go/pkg/models"
)
Expand All @@ -15,10 +17,10 @@ type storage struct {
}

func NewStorage(folderPath string) *storage { //nolint:golint
return &storage{folderPath}
return &storage{path: strings.TrimRight(folderPath, "/")}
}

func (s storage) SaveData(pd *models.PageData) error {
func (s storage) SaveData(_ context.Context, pd *models.PageData) error {
if pd == nil {
return errors.New("nil page data")
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/repository/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand All @@ -25,7 +26,7 @@ func NewStorage(cfg cfg.S3Config) (*storage, error) { //nolint:golint
if service == s3.ServiceID {
return aws.Endpoint{
PartitionID: cfg.Endpoint.PartitionID,
URL: cfg.Endpoint.URL,
URL: strings.TrimRight(cfg.Endpoint.URL, "/"),
SigningName: cfg.Endpoint.SigningName,
SigningRegion: cfg.Endpoint.SigningRegion,
SigningMethod: cfg.Endpoint.SigningMethod,
Expand All @@ -36,7 +37,6 @@ func NewStorage(cfg cfg.S3Config) (*storage, error) { //nolint:golint
return aws.Endpoint{}, fmt.Errorf("unknown endpoint requested")
})

// Подгружаем конфигрурацию из ~/.aws/*
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithEndpointResolverWithOptions(customResolver),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
Expand All @@ -55,11 +55,11 @@ func NewStorage(cfg cfg.S3Config) (*storage, error) { //nolint:golint
return s, nil
}

func (s storage) SaveData(pd *models.PageData) error {
func (s *storage) SaveData(ctx context.Context, pd *models.PageData) error {
// Upload the file to S3.
_, err := s.client.PutObject(context.TODO(), &s3.PutObjectInput{
Bucket: aws.String(s.cfg.Bucket.Name),
Key: aws.String(s.cfg.Bucket.Folder + pd.FileName),
_, err := s.client.PutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(strings.Trim(s.cfg.Bucket.Name, "/")),
Key: aws.String(fmt.Sprintf("%s/%s", strings.Trim(s.cfg.Bucket.Folder, "/"), pd.FileName)),
Body: bytes.NewReader(pd.Body),
ContentType: aws.String("text/html; charset=utf-8"),
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ type Service interface {
}

type Repository interface {
SaveData(pd *models.PageData) error
SaveData(ctx context.Context, pd *models.PageData) error
}
2 changes: 1 addition & 1 deletion pkg/service/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *service) RenderPages(pages []*models.PageData, maxWorkers int) error {

p.SuccessRender = true

if err := s.r.SaveData(p); err != nil {
if err := s.r.SaveData(ctx, p); err != nil {
log.Printf("save data error: %v", err)
} else {
p.SuccessStoring = true
Expand Down

0 comments on commit 8d00cb7

Please sign in to comment.