From cb0080349da4c0e26c50ebecb141b51009c1f813 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Mon, 28 Aug 2017 23:31:49 +0200 Subject: [PATCH 1/2] Restructuring of build process --- .dockerignore | 2 + .drone.yml | 99 ++++++++++++++++++++++++++++++------- .drone.yml.sig | 1 - .gitignore | 3 +- DOCS.md | 119 --------------------------------------------- Dockerfile | 25 +++++++--- Dockerfile.arm | 19 ++++++++ Dockerfile.arm64 | 19 ++++++++ Dockerfile.armhf | 10 ---- Dockerfile.windows | 13 +++++ MAINTAINERS | 46 ------------------ README.md | 21 +++----- logo.svg | 17 ------- main.go | 2 +- types.go | 4 +- 15 files changed, 164 insertions(+), 236 deletions(-) create mode 100644 .dockerignore delete mode 100644 .drone.yml.sig delete mode 100644 DOCS.md create mode 100644 Dockerfile.arm create mode 100644 Dockerfile.arm64 delete mode 100644 Dockerfile.armhf create mode 100644 Dockerfile.windows delete mode 100644 MAINTAINERS delete mode 100644 logo.svg diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c13ca3f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +* +!release/ diff --git a/.drone.yml b/.drone.yml index 34e9c38..749b94c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,33 +1,96 @@ workspace: - path: src/github.com/drone-plugins/drone-s3-sync base: /go + path: src/github.com/drone-plugins/drone-s3-sync pipeline: test: - image: golang:1.6 - environment: - - CGO_ENABLED=0 + image: golang:1.9 commands: - go vet - go test -cover -coverprofile=coverage.out - - go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a -tags netgo - publish: + build_linux_amd64: + image: golang:1.9 + group: build + environment: + - GOOS=linux + - GOARCH=amd64 + - CGO_ENABLED=0 + commands: + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/amd64/drone-s3-sync + + build_linux_arm64: + image: golang:1.9 + group: build + environment: + - GOOS=linux + - GOARCH=arm64 + - CGO_ENABLED=0 + commands: + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm64/drone-s3-sync + + build_linux_arm: + image: golang:1.9 + group: build + environment: + - GOOS=linux + - GOARCH=arm + - CGO_ENABLED=0 + - GOARM=7 + commands: + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm/drone-s3-sync + + # build_windows_amd64: + # image: golang:1.9-nanoserver + # group: build + # environment: + # - GOOS=windows + # - GOARCH=amd64 + # - CGO_ENABLED=0 + # commands: + # - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/windows/amd64/drone-s3-sync + + publish_linux_amd64: image: plugins/docker repo: plugins/s3-sync - tags: [ "latest", "1.1", "1" ] + tags: [ latest, 1.1.0, 1.1, 1 ] + secrets: [ docker_username, docker_password ] when: branch: master event: push -plugin: - name: S3 Sync - desc: Sync a directory with an Amazon S3 Bucket - type: publish - image: plugins/s3-sync - labels: - - publish - - artifacts - - amazon - - aws - - s3 + publish_linux_arm64: + image: plugins/docker + repo: plugins/s3-sync + tags: [ linux-arm64 ] + secrets: [ docker_username, docker_password ] + dockerfile: Dockerfile.arm64 + when: + branch: master + event: push + + publish_linux_arm: + image: plugins/docker + repo: plugins/s3-sync + tags: [ linux-arm ] + secrets: [ docker_username, docker_password ] + dockerfile: Dockerfile.arm + when: + branch: master + event: push + + # publish_windows_amd64: + # image: plugins/docker + # repo: plugins/s3-sync + # tags: [ windows-amd64 ] + # secrets: [ docker_username, docker_password ] + # dockerfile: Dockerfile.windows + # when: + # branch: master + # event: push + + # microbadger: + # image: plugins/webhook + # secrets: [ webhook_url ] + # when: + # status: [ success ] diff --git a/.drone.yml.sig b/.drone.yml.sig deleted file mode 100644 index f42ca01..0000000 --- a/.drone.yml.sig +++ /dev/null @@ -1 +0,0 @@ -eyJhbGciOiJIUzI1NiJ9.d29ya3NwYWNlOgogIHBhdGg6IHNyYy9naXRodWIuY29tL2Ryb25lLXBsdWdpbnMvZHJvbmUtczMtc3luYwogIGJhc2U6IC9nbwoKcGlwZWxpbmU6CiAgdGVzdDoKICAgIGltYWdlOiBnb2xhbmc6MS42CiAgICBlbnZpcm9ubWVudDoKICAgICAgLSBDR09fRU5BQkxFRD0wCiAgICBjb21tYW5kczoKICAgICAgLSBnbyB2ZXQKICAgICAgLSBnbyB0ZXN0IC1jb3ZlciAtY292ZXJwcm9maWxlPWNvdmVyYWdlLm91dAogICAgICAtIGdvIGJ1aWxkIC1sZGZsYWdzICItcyAtdyAtWCBtYWluLmJ1aWxkPSREUk9ORV9CVUlMRF9OVU1CRVIiIC1hIC10YWdzIG5ldGdvCgogIHB1Ymxpc2g6CiAgICBpbWFnZTogcGx1Z2lucy9kb2NrZXIKICAgIHJlcG86IHBsdWdpbnMvczMtc3luYwogICAgdGFnczogWyAibGF0ZXN0IiwgIjEuMSIsICIxIiBdCiAgICB3aGVuOgogICAgICBicmFuY2g6IG1hc3RlcgogICAgICBldmVudDogcHVzaAoKcGx1Z2luOgogIG5hbWU6IFMzIFN5bmMKICBkZXNjOiBTeW5jIGEgZGlyZWN0b3J5IHdpdGggYW4gQW1hem9uIFMzIEJ1Y2tldAogIHR5cGU6IHB1Ymxpc2gKICBpbWFnZTogcGx1Z2lucy9zMy1zeW5jCiAgbGFiZWxzOgogICAgLSBwdWJsaXNoCiAgICAtIGFydGlmYWN0cwogICAgLSBhbWF6b24KICAgIC0gYXdzCiAgICAtIHMzCg.qiRFZIEl1LP7LkwrOqCFdIG4-NZ4QQt9ivotWUCxxiQ \ No newline at end of file diff --git a/.gitignore b/.gitignore index efc8a04..3484f11 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,6 @@ _testmain.go *.prof .env +release/* coverage.out -drone-s3-sync \ No newline at end of file +drone-s3-sync diff --git a/DOCS.md b/DOCS.md deleted file mode 100644 index 03adacf..0000000 --- a/DOCS.md +++ /dev/null @@ -1,119 +0,0 @@ -Use the S3 sync plugin to synchronize files and folders with an Amazon S3 bucket. The following parameters are used to configure this plugin: - -* `access_key` - amazon key -* `secret_key` - amazon secret key -* `bucket` - bucket name -* `region` - bucket region (`us-east-1`, `eu-west-1`, etc) -* `acl` - access to files that are uploaded (`private`, `public-read`, etc) -* `source` - location of folder to sync -* `target` - target folder in your S3 bucket -* `delete` - deletes files in the target not found in the source -* `content_type` - override default mime-types to use this value -* `content_encoding` - override default content encoding header for files -* `cache_control` - override default cache control header for files -* `metadata` - set custom metadata -* `redirects` - targets that should redirect elsewhere -* `cloudfront_distribution_id` - (optional) the cloudfront distribution id to invalidate after syncing - -The following is a sample S3 configuration in your .drone.yml file: - -```yaml -publish: - s3_sync: - acl: public-read - region: "us-east-1" - bucket: "my-bucket.s3-website-us-east-1.amazonaws.com" - access_key: "970d28f4dd477bc184fbd10b376de753" - secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c" - source: folder/to/archive - target: /target/location - delete: true - cloudfront_distribution_id: "9c5785d3ece6a9cdefa4" -``` - -The `acl`, `content_type`, `cache_control`, and `content_encoding` parameters can be passed as a string value to apply to all files, or as a map to apply to a subset of files. - -For example: - -```yaml -publish: - s3_sync: - acl: - "public/*": public-read - "private/*": private - content_type: - ".svg": image/svg+xml - content_encoding: - ".js": gzip - ".css": gzip - cache_control: "public, max-age: 31536000" - region: "us-east-1" - bucket: "my-bucket.s3-website-us-east-1.amazonaws.com" - access_key: "970d28f4dd477bc184fbd10b376de753" - secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c" - source: folder/to/archive - target: /target/location - delete: true -``` - -In the case of `acl` the key of the map is a glob. If there are no matches in your settings for a given file, the default is `"private"`. - -The `content_type` field the key is an extension including the leading dot `.`. If you want to set a content type for files with no extension, set the key to the empty string `""`. If there are no matches for the `content_type` of any file, one will automatically be determined for you. - -In the `content_encoding` field the key is an extension including the leading dot `.`. If you want to set a encoding type for files with no extension, set the key -to th empty string `""`. If there are no matches for the `content_encoding` of a file, no content-encoding header will be added. - -In the `cache_control` field the key is an extension including the leading dot `.`. If you want to set cache control for files with no extension, set the key -to the empty string `""`. If there are no matches for the `cache_control` of a file, no cache-control header will be added. - -The `metadata` field can be set as either an object where the keys are the metadata headers: - -```yaml -publish: - s3_sync: - acl: public-read - region: "us-east-1" - bucket: "my-bucket.s3-website-us-east-1.amazonaws.com" - access_key: "970d28f4dd477bc184fbd10b376de753" - secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c" - source: folder/to/archive - target: /target/location - delete: true - metadata: - custom-meta: "abc123" -``` - -Or you can specify metadata for file patterns by using a glob: - -```yaml -publish: - s3_sync: - acl: public-read - region: "us-east-1" - bucket: "my-bucket.s3-website-us-east-1.amazonaws.com" - access_key: "970d28f4dd477bc184fbd10b376de753" - secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c" - source: folder/to/archive - target: /target/location - delete: true - metadata: - "*.png": - CustomMeta: "abc123" -``` - -Additionally, you can specify redirect targets for files that don't exist by using the `redirects` key: - -```yaml -publish: - s3_sync: - acl: public-read - region: "us-east-1" - bucket: "my-bucket.s3-website-us-east-1.amazonaws.com" - access_key: "970d28f4dd477bc184fbd10b376de753" - secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c" - source: folder/to/archive - target: /target/location - delete: true - redirects: - some/missing/file: /somewhere/that/actually/exists -``` diff --git a/Dockerfile b/Dockerfile index f3a5ab0..20ab942 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,19 @@ -FROM alpine:3.4 +FROM alpine:3.6 as alpine +RUN apk add -U --no-cache ca-certificates mailcap -RUN apk update && \ - apk add \ - ca-certificates \ - mailcap && \ - rm -rf /var/cache/apk/* +FROM scratch +MAINTAINER Drone.IO Community -ADD drone-s3-sync /bin/ -ENTRYPOINT ["/bin/drone-s3-sync"] +ENV GODEBUG=netdns=go + +COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=alpine /etc/mime.types /etc/ + +LABEL org.label-schema.version=latest +LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-s3-sync.git" +LABEL org.label-schema.name="Drone S3 Sync" +LABEL org.label-schema.vendor="Drone.IO Community" +LABEL org.label-schema.schema-version="1.0" + +ADD release/linux/amd64/drone-s3-sync /bin/ +ENTRYPOINT [ "/bin/drone-s3-sync" ] diff --git a/Dockerfile.arm b/Dockerfile.arm new file mode 100644 index 0000000..a28f4bc --- /dev/null +++ b/Dockerfile.arm @@ -0,0 +1,19 @@ +FROM alpine:3.6 as alpine +RUN apk add -U --no-cache ca-certificates mailcap + +FROM scratch +MAINTAINER Drone.IO Community + +ENV GODEBUG=netdns=go + +COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=alpine /etc/mime.types /etc/ + +LABEL org.label-schema.version=latest +LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-s3-sync.git" +LABEL org.label-schema.name="Drone S3 Sync" +LABEL org.label-schema.vendor="Drone.IO Community" +LABEL org.label-schema.schema-version="1.0" + +ADD release/linux/arm/drone-s3-sync /bin/ +ENTRYPOINT [ "/bin/drone-s3-sync" ] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 0000000..dde72f4 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,19 @@ +FROM alpine:3.6 as alpine +RUN apk add -U --no-cache ca-certificates mailcap + +FROM scratch +MAINTAINER Drone.IO Community + +ENV GODEBUG=netdns=go + +COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=alpine /etc/mime.types /etc/ + +LABEL org.label-schema.version=latest +LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-s3-sync.git" +LABEL org.label-schema.name="Drone S3 Sync" +LABEL org.label-schema.vendor="Drone.IO Community" +LABEL org.label-schema.schema-version="1.0" + +ADD release/linux/arm64/drone-s3-sync /bin/ +ENTRYPOINT [ "/bin/drone-s3-sync" ] diff --git a/Dockerfile.armhf b/Dockerfile.armhf deleted file mode 100644 index 1e93f1b..0000000 --- a/Dockerfile.armhf +++ /dev/null @@ -1,10 +0,0 @@ -FROM armhfbuild/alpine:3.4 - -RUN apk update && \ - apk add \ - ca-certificates \ - mailcap && \ - rm -rf /var/cache/apk/* - -ADD drone-s3-sync /bin/ -ENTRYPOINT ["/bin/drone-s3-sync"] diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000..d719383 --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,13 @@ +FROM microsoft/nanoserver:latest +MAINTAINER Drone.IO Community + +ENV GODEBUG=netdns=go + +LABEL org.label-schema.version=latest +LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-s3-sync.git" +LABEL org.label-schema.name="Drone S3 Sync" +LABEL org.label-schema.vendor="Drone.IO Community" +LABEL org.label-schema.schema-version="1.0" + +ADD release/windows/amd64/drone-s3-sync /bin/ +ENTRYPOINT [ "/bin/drone-s3-sync" ] diff --git a/MAINTAINERS b/MAINTAINERS deleted file mode 100644 index 0ecaf19..0000000 --- a/MAINTAINERS +++ /dev/null @@ -1,46 +0,0 @@ -[people] - [people.bradrydzewski] - name = "Brad Rydzewski" - email = "brad@drone.io" - login = "bradrydzewski" - [people.Bugagazavr] - name = "Kirill" - email = "" - login = "Bugagazavr" - [people.donny-dont] - name = "Don Olmstead" - email = "donny-dont@gmail.com" - login = "donny-dont" - [people.jackspirou] - name = "Jack Spirou" - email = "" - login = "jackspirou" - [people.msteinert] - name = "Mike Steinert" - email = "" - login = "msteinert" - [people.nlf] - name = "Nathan LaFreniere" - email = "" - login = "nlf" - [people.tboerger] - name = "Thomas Boerger" - email = "thomas@webhippie.de" - login = "tboerger" - [people.athieriot] - name = "Aurélien Thieriot" - email = "a.thieriot@gmail.com" - login = "athieriot" - -[org] - [org.core] - people = [ - "bradrydzewski", - "Bugagazavr", - "donny-dont", - "jackspirou", - "msteinert", - "nlf", - "tboerger", - "athieriot" - ] diff --git a/README.md b/README.md index b46ad48..2912dd8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # drone-s3-sync [![Build Status](http://beta.drone.io/api/badges/drone-plugins/drone-s3-sync/status.svg)](http://beta.drone.io/drone-plugins/drone-s3-sync) +[![Join the chat at https://gitter.im/drone/drone](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/drone/drone) +[![Go Doc](https://godoc.org/github.com/drone-plugins/drone-s3-sync?status.svg)](http://godoc.org/github.com/drone-plugins/drone-s3-sync) +[![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-s3-sync)](https://goreportcard.com/report/github.com/drone-plugins/drone-s3-sync) +[![](https://images.microbadger.com/badges/image/plugins/s3-sync.svg)](https://microbadger.com/images/plugins/s3-sync "Get your own image badge on microbadger.com") -Drone plugin to synchronize a directory with an Amazon S3 Bucket. For the -usage information and a listing of the available options please take a look at -[the docs](DOCS.md). +Drone plugin to synchronize a directory with an Amazon S3 Bucket. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-s3-sync/). ## Build @@ -12,7 +14,6 @@ Build the binary with the following commands: ``` go build -go test ``` ## Docker @@ -20,16 +21,8 @@ go test Build the Docker image with the following commands: ``` -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -docker build --rm=true -t plugins/s3-sync . -``` - -Please note incorrectly building the image for the correct x64 linux and with -CGO disabled will result in an error when running the Docker image: - -``` -docker: Error response from daemon: Container command -'/bin/drone-s3-sync' not found or does not exist.. +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-s3-sync +docker build --rm -t plugins/s3-sync . ``` ## Usage diff --git a/logo.svg b/logo.svg deleted file mode 100644 index 70a7843..0000000 --- a/logo.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/main.go b/main.go index 11e5b7a..c844284 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ func main() { app.Name = "s3 sync plugin" app.Usage = "s3 sync plugin" app.Action = run - app.Version = fmt.Sprintf("1.0.%s", build) + app.Version = fmt.Sprintf("1.1.0+%s", build) app.Flags = []cli.Flag{ cli.StringFlag{ Name: "access-key", diff --git a/types.go b/types.go index 4bad815..51114ac 100644 --- a/types.go +++ b/types.go @@ -1,6 +1,8 @@ package main -import "encoding/json" +import ( + "encoding/json" +) type DeepStringMapFlag struct { parts map[string]map[string]string From b541ced6f781c6ef70bb7daf306bc1592bace8fd Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 29 Aug 2017 23:04:22 +0200 Subject: [PATCH 2/2] Dropped netgo build tag, default since go 1.5 --- .drone.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 749b94c..76bb8f2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ pipeline: - GOARCH=amd64 - CGO_ENABLED=0 commands: - - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/amd64/drone-s3-sync + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/amd64/drone-s3-sync build_linux_arm64: image: golang:1.9 @@ -27,7 +27,7 @@ pipeline: - GOARCH=arm64 - CGO_ENABLED=0 commands: - - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm64/drone-s3-sync + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm64/drone-s3-sync build_linux_arm: image: golang:1.9 @@ -38,7 +38,7 @@ pipeline: - CGO_ENABLED=0 - GOARM=7 commands: - - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm/drone-s3-sync + - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/linux/arm/drone-s3-sync # build_windows_amd64: # image: golang:1.9-nanoserver @@ -48,7 +48,7 @@ pipeline: # - GOARCH=amd64 # - CGO_ENABLED=0 # commands: - # - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/windows/amd64/drone-s3-sync + # - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/windows/amd64/drone-s3-sync publish_linux_amd64: image: plugins/docker