Skip to content

Commit

Permalink
Update to be an aws-cli wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Jun 15, 2022
1 parent 02accdb commit 0a81468
Show file tree
Hide file tree
Showing 380 changed files with 16,467 additions and 123,273 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM alpine:latest

RUN apk add --no-cache ca-certificates

RUN adduser -D -u 1000 skpr
FROM docker.io/amazon/aws-cli:2.1.27

COPY s3-sync /usr/local/bin/
RUN chmod +x /usr/local/bin/s3-sync

RUN adduser -D -u 1000 skpr
USER skpr

ENTRYPOINT ["/usr/local/bin/s3-sync"]
12 changes: 4 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ module github.com/skpr/s3-sync

go 1.17

replace github.com/seqsense/s3sync => github.com/skpr/s3sync v1.8.2-0.20220203223008-e72bb50af2a9

require (
github.com/aws/aws-sdk-go v1.42.45
github.com/seqsense/s3sync v1.8.1
github.com/stretchr/testify v1.4.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/gabriel-vasile/mimetype v1.4.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
30 changes: 4 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,15 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/aws/aws-sdk-go v1.42.30/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/aws/aws-sdk-go v1.42.45 h1:rzYlmOX2EqdsYKvo0WBBffuff3BuckL1UB2KyzWhXyQ=
github.com/aws/aws-sdk-go v1.42.45/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.0 h1:Cn9dkdYsMIu56tGho+fqzh7XmvY2YyGU0FnbhiOsEro=
github.com/gabriel-vasile/mimetype v1.4.0/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/seqsense/s3sync v1.8.1 h1:eUEQ1aeDXaQjsoMrQdDZ4ZL2yTXWHWKWyUigpk2mr5k=
github.com/seqsense/s3sync v1.8.1/go.mod h1:yVAPljnzE70ZLhn2OCaI35/59UpIl8RXYRvyU/Tthgs=
github.com/skpr/s3sync v1.8.2-0.20220128231708-807c5cca87ba h1:SUvIm1ga+zlQQl9Nj7q+yzreHKnKlflarOF2ySdkCT4=
github.com/skpr/s3sync v1.8.2-0.20220128231708-807c5cca87ba/go.mod h1:xWj9s4Od/L9i6aJJfUYBfaxKAyETAm2zgLVX2FuQ+Ds=
github.com/skpr/s3sync v1.8.2-0.20220203223008-e72bb50af2a9 h1:BRdWrZmdB1Uv0YOC9DpLFcKB9lEePgnyKBvAVRP4SDg=
github.com/skpr/s3sync v1.8.2-0.20220203223008-e72bb50af2a9/go.mod h1:xWj9s4Od/L9i6aJJfUYBfaxKAyETAm2zgLVX2FuQ+Ds=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
48 changes: 23 additions & 25 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package main

import (
"os"
"os/exec"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/seqsense/s3sync"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
cliRegion = kingpin.Flag("region", "When transferring objects from an s3 bucket to an s3 bucket, this specifies the region of the source bucket").Default(endpoints.ApSoutheast2RegionID).String()
cliRegion = kingpin.Flag("region", "When transferring objects from an s3 bucket to an s3 bucket, this specifies the region of the source bucket").Default("ap-southeast-2").String()
cliEndpoint = kingpin.Flag("endpoint", "Override command's default URL with the given URL").Envar("SKPR_S3_SYNC_ENDPOINT").String()
cliParallel = kingpin.Flag("parallel", "Sets maximum number of parallel file sync jobs").Envar("SKPR_S3_SYNC_PARALLEL").Default("16").Int()
cliDelete = kingpin.Flag("delete", "Delete files which are not listed in the source").Envar("SKPR_S3_SYNC_DELETE").Bool()
cliExclude = kingpin.Flag("exclude", "Exclude paths from the list to be synced").Envar("SKPR_S3_SYNC_EXCLUDE").String()
cliSource = kingpin.Arg("source", "Source files which are synced (local or S3 path)").Required().String()
Expand All @@ -23,34 +20,35 @@ var (
func main() {
kingpin.Parse()

config := &aws.Config{
Region: cliRegion,
Endpoint: cliEndpoint,
}
args := buildArgs(*cliEndpoint, *cliSource, *cliTarget, *cliExclude)

cmd := exec.Command("aws", args...)

sess, err := session.NewSession(config)
if err != nil {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
panic(err)
}
}

var options []s3sync.Option
// Command which is compatible with the AWS S3 sync command line interface.
func buildArgs(endpoint, source, target, exclude string) []string {
args := []string{"s3"}

if *cliDelete {
options = append(options, s3sync.WithDelete())
if endpoint != "" {
args = append(args, "--endpoint-url", endpoint)
}

if *cliParallel > 0 {
options = append(options, s3sync.WithParallel(*cliParallel))
}
args = append(args, "sync")

for _, exclude := range strings.Split(*cliExclude, ",") {
options = append(options, s3sync.WithExcludePattern(exclude))
if exclude != "" {
for _, e := range strings.Split(exclude, ",") {
args = append(args, "--exclude", e)
}
}

syncManager := s3sync.New(sess, options...)
args = append(args, source, target)

err = syncManager.Sync(*cliSource, *cliTarget)
if err != nil {
panic(err)
}
return args
}
22 changes: 22 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestBuildArgsWithEndpoint(t *testing.T) {
command := buildArgs("127.0.0.1", "foo", "bar", "")
assert.Equal(t, []string{"s3", "--endpoint-url", "127.0.0.1", "sync", "foo", "bar"}, command)
}

func TestBuildArgsdWithExcludes(t *testing.T) {
command := buildArgs("", "foo", "bar", "/stuff,/things")
assert.Equal(t, []string{"s3", "sync", "--exclude", "/stuff", "--exclude", "/things", "foo", "bar"}, command)
}

func TestBuildArgsWithAll(t *testing.T) {
command := buildArgs("127.0.0.1", "foo", "bar", "/stuff,/things")
assert.Equal(t, []string{"s3", "--endpoint-url", "127.0.0.1", "sync", "--exclude", "/stuff", "--exclude", "/things", "foo", "bar"}, command)
}
3 changes: 0 additions & 3 deletions vendor/github.com/aws/aws-sdk-go/NOTICE.txt

This file was deleted.

93 changes: 0 additions & 93 deletions vendor/github.com/aws/aws-sdk-go/aws/arn/arn.go

This file was deleted.

Loading

0 comments on commit 0a81468

Please sign in to comment.