Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add goreleaser to help multi arch build #16

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
dynamodb-sync

.idea
dist/
25 changes: 25 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

version: 2

before:
hooks:
- rm -rf ./dist
- go mod tidy
- go generate ./...

builds:
- env: [CGO_ENABLED=0]
goos:
- linux
goarch:
- amd64
- arm64

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/thumbtack/dynamodb-sync
go 1.22

require (
github.com/aws/aws-sdk-go v1.50.32
github.com/aws/aws-sdk-go v1.54.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
golang.org/x/time v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aws/aws-sdk-go v1.50.32 h1:POt81DvegnpQKM4DMDLlHz1CO6OBnEoQ1gRhYFd7QRY=
github.com/aws/aws-sdk-go v1.50.32/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.54.1 h1:+ULL7oLC+v3T00fOMIohUarPI3SR3oyDd6FBEvgdhvs=
github.com/aws/aws-sdk-go v1.54.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 Thumbtack, Inc.
Copyright 2018-2024 Thumbtack, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (ss *syncState) isFreshStart() bool {
"dst table": ss.checkpointPK.dstTable,
"State Timestamp": ss.timestamp,
}).Info("Checking if fresh start")
return ss.timestamp.IsZero() || time.Now().Sub(ss.timestamp) > streamRetentionHours
return ss.timestamp.IsZero() || time.Since(ss.timestamp) > streamRetentionHours
}

func (ss *syncState) replicate(quit <-chan bool) {
Expand Down
7 changes: 2 additions & 5 deletions stream.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"time"

Expand All @@ -17,10 +16,8 @@ func (ss *syncState) getStreamArn() (string, error) {
TableName: aws.String(ss.tableConfig.SrcTable),
})
if err != nil || describeTableResult.Table.StreamSpecification == nil {
return "", errors.New(fmt.Sprintf(
"Failed to get StreamARN for table %s. Check if stream is enabled",
ss.checkpointPK.sourceTable),
)
return "", fmt.Errorf("failed to get StreamARN for table %s. Check if stream is enabled",
ss.checkpointPK.sourceTable)
}
streamArn := describeTableResult.Table.LatestStreamArn
logger.WithFields(logging.Fields{
Expand Down
21 changes: 9 additions & 12 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ func increaseCapacity(
}).Error("failed to increase capacity")
return err
}
waitForTableUpdate(tableName, dynamo)
return nil
return waitForTableUpdate(tableName, dynamo)
}

func decreaseCapacity(
Expand Down Expand Up @@ -243,8 +242,7 @@ func decreaseCapacity(
}).Error("failed to decrease capacity")
return err
}
waitForTableUpdate(tableName, dynamo)
return nil
return waitForTableUpdate(tableName, dynamo)
}

func generateGsiUpdate(
Expand All @@ -271,7 +269,7 @@ func generateGsiUpdate(
return result
}

func waitForTableUpdate(tableName string, dynamo *dynamodb.DynamoDB) {
func waitForTableUpdate(tableName string, dynamo *dynamodb.DynamoDB) error {
status := ""
statusInput := &dynamodb.DescribeTableInput{
TableName: aws.String(tableName),
Expand All @@ -284,20 +282,19 @@ func waitForTableUpdate(tableName string, dynamo *dynamodb.DynamoDB) {
"error": err,
}).Error("failed to get the table status")
// likely an internal error from DDB, nothing can be done here
break
return err
} else {
status = *output.Table.TableStatus
logger.WithFields(logging.Fields{
"table": tableName,
}).Debug("Updating table throughput")
time.Sleep(1 * time.Second)
time.Sleep(3 * time.Second)
}
}
if status == "ACTIVE" {
logger.WithFields(logging.Fields{
"Table": tableName,
}).Info("Successfully updated table throughput")
}
logger.WithFields(logging.Fields{
"Table": tableName,
}).Info("Successfully updated table throughput")
return nil
}

// getCapacity returns the read and write capacity of the given table and its gsi
Expand Down
3 changes: 1 addition & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -44,7 +43,7 @@ func getSession(region, endpoint string, httpClient *http.Client) *session.Sessi
// parseConfigFile reads and parses the config file
func parseConfigFile(filepath string) (configs []*syncConfig, err error) {
var data []byte
data, err = ioutil.ReadFile(filepath)
data, err = os.ReadFile(filepath)
if err == nil {
err = json.Unmarshal(data, &configs)
}
Expand Down
Loading