├── .dockerignore ├── .github ├── pull_request_template.md ├── issue_template.md └── settings.yml ├── storage └── s3 │ ├── s3_test.go │ └── s3.go ├── .gitignore ├── docker ├── Dockerfile.linux.amd64 ├── Dockerfile.linux.arm64 ├── Dockerfile.windows.1809 ├── Dockerfile.windows.ltsc2022 └── manifest.tmpl ├── plugin ├── plugin_test.go ├── impl_test.go ├── plugin.go └── impl.go ├── go.mod ├── README.md ├── .drone.yml ├── main.go ├── go.sum └── LICENSE /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !release/ 3 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /storage/s3/s3_test.go: -------------------------------------------------------------------------------- 1 | package s3 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /release/ 2 | /drone-s3-cache* 3 | /.idea 4 | 5 | coverage.out 6 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.amd64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone S3 Cache" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/amd64/drone-s3-cache /bin/ 9 | ENTRYPOINT [ "/bin/drone-s3-cache" ] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.arm64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone S3 Cache" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/arm64/drone-s3-cache /bin/ 9 | ENTRYPOINT [ "/bin/drone-s3-cache" ] 10 | -------------------------------------------------------------------------------- /plugin/plugin_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestPlugin(t *testing.T) { 13 | t.Skip() 14 | } 15 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.1809: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-1809-amd64 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone S3 Cache" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-s3-cache.exe C:/bin/drone-s3-cache.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-s3-cache.exe" ] 11 | -------------------------------------------------------------------------------- /plugin/impl_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestValidate(t *testing.T) { 13 | t.Skip() 14 | } 15 | 16 | func TestExecute(t *testing.T) { 17 | t.Skip() 18 | } 19 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.ltsc2022: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone S3 Cache" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-s3-cache.exe C:/bin/drone-s3-cache.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-s3-cache.exe" ] 11 | -------------------------------------------------------------------------------- /plugin/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "github.com/drone-plugins/drone-plugin-lib/drone" 10 | ) 11 | 12 | // Plugin implements drone.Plugin to provide the plugin implementation. 13 | type Plugin struct { 14 | settings Settings 15 | pipeline drone.Pipeline 16 | network drone.Network 17 | } 18 | 19 | // New initializes a plugin from the given Settings, Pipeline, and Network. 20 | func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin { 21 | return &Plugin{ 22 | settings: settings, 23 | pipeline: pipeline, 24 | network: network, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docker/manifest.tmpl: -------------------------------------------------------------------------------- 1 | image: plugins/s3-cache:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} 2 | 3 | {{#if build.tags}} 4 | tags: 5 | {{#each build.tags}} 6 | - {{this}} 7 | {{/each}} 8 | {{/if}} 9 | 10 | manifests: 11 | - image: plugins/s3-cache:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 12 | platform: 13 | architecture: amd64 14 | os: linux 15 | - image: plugins/s3-cache:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 16 | platform: 17 | architecture: arm64 18 | os: linux 19 | variant: v8 20 | - image: plugins/s3-cache:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 21 | platform: 22 | architecture: amd64 23 | os: windows 24 | version: 1809 25 | - image: plugins/s3-cache:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 26 | platform: 27 | architecture: amd64 28 | os: windows 29 | version: ltsc2022 30 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/drone-plugins/drone-s3-cache 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/drone-plugins/drone-plugin-lib v0.4.0 7 | github.com/drone/drone-cache-lib v0.0.0-20200806063744-981868645a25 8 | github.com/dustin/go-humanize v1.0.0 9 | github.com/joho/godotenv v1.4.0 10 | github.com/minio/minio-go/v7 v7.0.45 11 | github.com/sirupsen/logrus v1.9.0 12 | github.com/urfave/cli/v2 v2.23.6 13 | ) 14 | 15 | require ( 16 | github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect 17 | github.com/google/uuid v1.3.0 // indirect 18 | github.com/json-iterator/go v1.1.12 // indirect 19 | github.com/klauspost/compress v1.15.9 // indirect 20 | github.com/klauspost/cpuid/v2 v2.1.0 // indirect 21 | github.com/minio/md5-simd v1.1.2 // indirect 22 | github.com/minio/sha256-simd v1.0.0 // indirect 23 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 24 | github.com/modern-go/reflect2 v1.0.2 // indirect 25 | github.com/rs/xid v1.4.0 // indirect 26 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 27 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect 28 | golang.org/x/crypto v0.4.0 // indirect 29 | golang.org/x/net v0.4.0 // indirect 30 | golang.org/x/sys v0.3.0 // indirect 31 | golang.org/x/text v0.5.0 // indirect 32 | gopkg.in/ini.v1 v1.67.0 // indirect 33 | ) 34 | -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | repository: 2 | name: drone-s3-cache 3 | description: Caches build artifacts to S3 compatible storage backends 4 | homepage: http://plugins.drone.io/drone-plugins/drone-s3-cache 5 | topics: drone, drone-plugin 6 | 7 | private: false 8 | has_issues: true 9 | has_wiki: false 10 | has_downloads: false 11 | 12 | default_branch: master 13 | 14 | allow_squash_merge: true 15 | allow_merge_commit: true 16 | allow_rebase_merge: true 17 | 18 | labels: 19 | - name: bug 20 | color: d73a4a 21 | description: Something isn't working 22 | - name: duplicate 23 | color: cfd3d7 24 | description: This issue or pull request already exists 25 | - name: enhancement 26 | color: a2eeef 27 | description: New feature or request 28 | - name: good first issue 29 | color: 7057ff 30 | description: Good for newcomers 31 | - name: help wanted 32 | color: 008672 33 | description: Extra attention is needed 34 | - name: invalid 35 | color: e4e669 36 | description: This doesn't seem right 37 | - name: question 38 | color: d876e3 39 | description: Further information is requested 40 | - name: renovate 41 | color: e99695 42 | description: Automated action from Renovate 43 | - name: wontfix 44 | color: ffffff 45 | description: This will not be worked on 46 | 47 | teams: 48 | - name: Admins 49 | permission: admin 50 | - name: Captain 51 | permission: admin 52 | - name: Maintainers 53 | permission: push 54 | 55 | branches: 56 | - name: master 57 | protection: 58 | required_pull_request_reviews: 59 | required_approving_review_count: 1 60 | dismiss_stale_reviews: false 61 | require_code_owner_reviews: false 62 | dismissal_restrictions: 63 | teams: 64 | - Admins 65 | - Captain 66 | required_status_checks: 67 | strict: true 68 | contexts: 69 | - continuous-integration/drone/pr 70 | enforce_admins: false 71 | restrictions: 72 | users: [] 73 | teams: [] 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # drone-s3-cache 2 | 3 | [![Build Status](http://cloud.drone.io/api/badges/drone-plugins/drone-s3-cache/status.svg)](http://cloud.drone.io/drone-plugins/drone-s3-cache) 4 | [![Gitter chat](https://badges.gitter.im/drone/drone.png)](https://gitter.im/drone/drone) 5 | [![Join the discussion at https://discourse.drone.io](https://img.shields.io/badge/discourse-forum-orange.svg)](https://discourse.drone.io) 6 | [![Drone questions at https://stackoverflow.com](https://img.shields.io/badge/drone-stackoverflow-orange.svg)](https://stackoverflow.com/questions/tagged/drone.io) 7 | [![](https://images.microbadger.com/badges/image/plugins/s3-cache.svg)](https://microbadger.com/images/plugins/s3-cache "Get your own image badge on microbadger.com") 8 | [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-s3-cache?status.svg)](http://godoc.org/github.com/drone-plugins/drone-s3-cache) 9 | [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-s3-cache)](https://goreportcard.com/report/github.com/drone-plugins/drone-s3-cache) 10 | 11 | Drone plugin that allows you to cache directories within the build workspace, this plugin is backed by S3 compatible storages. 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-cache/). 12 | 13 | ## Build 14 | 15 | Build the binary with the following command: 16 | 17 | ```console 18 | export GOOS=linux 19 | export GOARCH=amd64 20 | export CGO_ENABLED=0 21 | export GO111MODULE=on 22 | 23 | go build -v -a -tags netgo -o release/linux/amd64/drone-s3-cache 24 | ``` 25 | 26 | ## Docker 27 | 28 | Build the Docker image with the following command: 29 | 30 | ```console 31 | docker build \ 32 | --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ 33 | --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ 34 | --file docker/Dockerfile.linux.amd64 --tag plugins/s3-cache . 35 | ``` 36 | 37 | ## Usage 38 | 39 | ```console 40 | docker run --rm \ 41 | -e PLUGIN_FLUSH=true \ 42 | -e PLUGIN_ENDPOINT="http://minio.company.com" \ 43 | -e PLUGIN_ACCESS_KEY="myaccesskey" \ 44 | -e PLUGIN_SECRET_KEY="mysecretKey" \ 45 | -v $(pwd):$(pwd) \ 46 | -w $(pwd) \ 47 | plugins/s3-cache 48 | 49 | docker run --rm \ 50 | -e PLUGIN_RESTORE=true \ 51 | -e PLUGIN_ENDPOINT="http://minio.company.com" \ 52 | -e PLUGIN_ACCESS_KEY="myaccesskey" \ 53 | -e PLUGIN_SECRET_KEY="mysecretKey" \ 54 | -e DRONE_REPO_OWNER="foo" \ 55 | -e DRONE_REPO_NAME="bar" \ 56 | -e DRONE_COMMIT_BRANCH="test" \ 57 | -v $(pwd):$(pwd) \ 58 | -w $(pwd) \ 59 | plugins/s3-cache 60 | 61 | docker run -it --rm \ 62 | -v $(pwd):$(pwd) \ 63 | -w $(pwd) \ 64 | alpine:latest sh -c "mkdir -p cache && echo 'testing cache' >> cache/test && cat cache/test" 65 | 66 | docker run --rm \ 67 | -e PLUGIN_REBUILD=true \ 68 | -e PLUGIN_MOUNT=".bundler" \ 69 | -e PLUGIN_ENDPOINT="http://minio.company.com" \ 70 | -e PLUGIN_ACCESS_KEY="myaccesskey" \ 71 | -e PLUGIN_SECRET_KEY="mysecretKey" \ 72 | -e DRONE_REPO_OWNER="foo" \ 73 | -e DRONE_REPO_NAME="bar" \ 74 | -e DRONE_COMMIT_BRANCH="test" \ 75 | -v $(pwd):$(pwd) \ 76 | -w $(pwd) \ 77 | plugins/s3-cache 78 | ``` 79 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | kind: pipeline 2 | type: vm 3 | name: testing 4 | platform: 5 | os: linux 6 | arch: amd64 7 | pool: 8 | use: ubuntu 9 | 10 | steps: 11 | - name: lint 12 | image: golang:1.19 13 | pull: always 14 | commands: 15 | - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 16 | - golangci-lint version 17 | - golangci-lint run 18 | volumes: 19 | - name: gopath 20 | path: "/go" 21 | - name: test 22 | image: golang:1.19 23 | commands: 24 | - go test -cover ./... 25 | volumes: 26 | - name: gopath 27 | path: "/go" 28 | volumes: 29 | - name: gopath 30 | temp: {} 31 | trigger: 32 | ref: 33 | - refs/heads/master 34 | - refs/tags/** 35 | - refs/pull/** 36 | 37 | --- 38 | kind: pipeline 39 | type: vm 40 | name: linux-amd64 41 | platform: 42 | os: linux 43 | arch: amd64 44 | pool: 45 | use: ubuntu 46 | 47 | steps: 48 | - name: environment 49 | image: golang:1.19 50 | pull: always 51 | environment: 52 | CGO_ENABLED: "0" 53 | commands: 54 | - go version 55 | - go env 56 | - name: build 57 | image: golang:1.19 58 | environment: 59 | CGO_ENABLED: "0" 60 | commands: 61 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-s3-cache . 62 | - name: docker 63 | image: plugins/docker 64 | settings: 65 | dockerfile: docker/Dockerfile.linux.amd64 66 | repo: plugins/s3-cache 67 | username: 68 | from_secret: docker_username 69 | password: 70 | from_secret: docker_password 71 | auto_tag: true 72 | auto_tag_suffix: linux-amd64 73 | depends_on: 74 | - testing 75 | trigger: 76 | ref: 77 | - refs/heads/master 78 | - refs/tags/** 79 | - refs/pull/** 80 | 81 | --- 82 | kind: pipeline 83 | type: vm 84 | name: linux-arm64 85 | platform: 86 | os: linux 87 | arch: arm64 88 | pool: 89 | use: ubuntu_arm64 90 | 91 | steps: 92 | - name: environment 93 | image: golang:1.19 94 | pull: always 95 | environment: 96 | CGO_ENABLED: "0" 97 | commands: 98 | - go version 99 | - go env 100 | - name: build 101 | image: golang:1.19 102 | environment: 103 | CGO_ENABLED: "0" 104 | commands: 105 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-s3-cache . 106 | - name: docker 107 | image: plugins/docker 108 | settings: 109 | dockerfile: docker/Dockerfile.linux.arm64 110 | repo: plugins/s3-cache 111 | username: 112 | from_secret: docker_username 113 | password: 114 | from_secret: docker_password 115 | auto_tag: true 116 | auto_tag_suffix: linux-arm64 117 | depends_on: 118 | - testing 119 | trigger: 120 | ref: 121 | - refs/heads/master 122 | - refs/tags/** 123 | - refs/pull/** 124 | 125 | --- 126 | kind: pipeline 127 | type: vm 128 | name: windows-1809 129 | platform: 130 | os: windows 131 | arch: amd64 132 | pool: 133 | use: windows 134 | 135 | steps: 136 | - name: environment 137 | image: golang:1.19 138 | pull: always 139 | environment: 140 | CGO_ENABLED: "0" 141 | commands: 142 | - go version 143 | - go env 144 | - name: build 145 | image: golang:1.19 146 | environment: 147 | CGO_ENABLED: "0" 148 | commands: 149 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-s3-cache.exe . 150 | - name: docker 151 | image: plugins/docker 152 | settings: 153 | dockerfile: docker/Dockerfile.windows.1809 154 | repo: plugins/s3-cache 155 | username: 156 | from_secret: docker_username 157 | password: 158 | from_secret: docker_password 159 | auto_tag: true 160 | auto_tag_suffix: windows-1809-amd64 161 | daemon_off: true 162 | purge: false 163 | when: 164 | ref: 165 | - refs/heads/master 166 | - refs/tags/** 167 | depends_on: 168 | - testing 169 | trigger: 170 | ref: 171 | - refs/heads/master 172 | - refs/tags/** 173 | - refs/pull/** 174 | 175 | --- 176 | kind: pipeline 177 | type: vm 178 | name: windows-ltsc2022 179 | platform: 180 | os: windows 181 | arch: amd64 182 | pool: 183 | use: windows-2022 184 | 185 | steps: 186 | - name: environment 187 | image: golang:1.19 188 | pull: always 189 | environment: 190 | CGO_ENABLED: "0" 191 | commands: 192 | - go version 193 | - go env 194 | - name: build 195 | image: golang:1.19 196 | environment: 197 | CGO_ENABLED: "0" 198 | commands: 199 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-s3-cache.exe . 200 | - name: docker 201 | image: plugins/docker 202 | settings: 203 | dockerfile: docker/Dockerfile.windows.ltsc2022 204 | repo: plugins/s3-cache 205 | username: 206 | from_secret: docker_username 207 | password: 208 | from_secret: docker_password 209 | auto_tag: true 210 | auto_tag_suffix: windows-ltsc2022-amd64 211 | daemon_off: true 212 | purge: false 213 | when: 214 | ref: 215 | - refs/heads/master 216 | - refs/tags/** 217 | depends_on: 218 | - testing 219 | trigger: 220 | ref: 221 | - refs/heads/master 222 | - refs/tags/** 223 | - refs/pull/** 224 | 225 | --- 226 | kind: pipeline 227 | type: vm 228 | name: manifest 229 | platform: 230 | os: linux 231 | arch: amd64 232 | pool: 233 | use: ubuntu 234 | 235 | steps: 236 | - name: manifest 237 | image: plugins/manifest 238 | settings: 239 | auto_tag: "true" 240 | username: 241 | from_secret: docker_username 242 | password: 243 | from_secret: docker_password 244 | spec: docker/manifest.tmpl 245 | ignore_missing: true 246 | depends_on: 247 | - linux-amd64 248 | - linux-arm64 249 | - windows-1809 250 | - windows-ltsc2022 251 | trigger: 252 | ref: 253 | - refs/heads/master 254 | - refs/tags/** 255 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | // DO NOT MODIFY THIS FILE DIRECTLY 7 | 8 | package main 9 | 10 | import ( 11 | "os" 12 | 13 | "github.com/drone-plugins/drone-plugin-lib/errors" 14 | "github.com/drone-plugins/drone-plugin-lib/urfave" 15 | "github.com/drone-plugins/drone-s3-cache/plugin" 16 | "github.com/joho/godotenv" 17 | "github.com/urfave/cli/v2" 18 | ) 19 | 20 | var version = "unknown" 21 | 22 | func main() { 23 | settings := &plugin.Settings{} 24 | 25 | if _, err := os.Stat("/run/drone/env"); err == nil { 26 | _ = godotenv.Overload("/run/drone/env") 27 | } 28 | 29 | app := &cli.App{ 30 | Name: "drone-s3-cache", 31 | Usage: "cache build artifacts to s3 storage", 32 | Version: version, 33 | Flags: append(settingsFlags(settings), urfave.Flags()...), 34 | Action: run(settings), 35 | } 36 | 37 | if err := app.Run(os.Args); err != nil { 38 | errors.HandleExit(err) 39 | } 40 | } 41 | 42 | func run(settings *plugin.Settings) cli.ActionFunc { 43 | return func(ctx *cli.Context) error { 44 | urfave.LoggingFromContext(ctx) 45 | 46 | plugin := plugin.New( 47 | *settings, 48 | urfave.PipelineFromContext(ctx), 49 | urfave.NetworkFromContext(ctx), 50 | ) 51 | 52 | if err := plugin.Validate(); err != nil { 53 | if e, ok := err.(errors.ExitCoder); ok { 54 | return e 55 | } 56 | 57 | return errors.ExitMessagef("validation failed: %w", err) 58 | } 59 | 60 | if err := plugin.Execute(); err != nil { 61 | if e, ok := err.(errors.ExitCoder); ok { 62 | return e 63 | } 64 | 65 | return errors.ExitMessagef("execution failed: %w", err) 66 | } 67 | 68 | return nil 69 | } 70 | } 71 | 72 | // settingsFlags has the cli.Flags for the plugin.Settings. 73 | func settingsFlags(settings *plugin.Settings) []cli.Flag { 74 | return []cli.Flag{ 75 | // Cache information 76 | 77 | &cli.StringFlag{ 78 | Name: "mode", 79 | Usage: "set plugin mode (rebuild,restore,flush)", 80 | EnvVars: []string{"PLUGIN_MODE"}, 81 | Destination: &settings.Mode, 82 | }, 83 | &cli.StringFlag{ 84 | Name: "filename", 85 | Usage: "filename for the cache archive", 86 | EnvVars: []string{"PLUGIN_FILENAME"}, 87 | Destination: &settings.Filename, 88 | }, 89 | &cli.StringFlag{ 90 | Name: "root", 91 | Usage: "storage root of cache files", 92 | EnvVars: []string{"PLUGIN_ROOT"}, 93 | Destination: &settings.Root, 94 | }, 95 | &cli.StringFlag{ 96 | Name: "path", 97 | Usage: "path to cache files relative to root", 98 | EnvVars: []string{"PLUGIN_PATH"}, 99 | Destination: &settings.Path, 100 | }, 101 | &cli.StringFlag{ 102 | Name: "fallback-path", 103 | Usage: "path to default cache files relative to the root", 104 | EnvVars: []string{"PLUGIN_FALLBACK_PATH"}, 105 | Destination: &settings.FallbackPath, 106 | }, 107 | &cli.StringFlag{ 108 | Name: "flush-path", 109 | Usage: "path to flushable cache files relative to the root", 110 | EnvVars: []string{"PLUGIN_FLUSH_PATH"}, 111 | Destination: &settings.FlushPath, 112 | }, 113 | &cli.StringSliceFlag{ 114 | Name: "mount", 115 | Usage: "directories to cache", 116 | EnvVars: []string{"PLUGIN_MOUNT"}, 117 | Destination: &settings.Mount, 118 | }, 119 | &cli.IntFlag{ 120 | Name: "flush-age", 121 | Usage: "flush cache files older than # days", 122 | EnvVars: []string{"PLUGIN_FLUSH_AGE"}, 123 | Value: 30, 124 | Destination: &settings.FlushAge, 125 | }, 126 | 127 | // Cache information (deprecated) 128 | 129 | &cli.BoolFlag{ 130 | Name: "rebuild", 131 | Usage: "rebuild the cache directories", 132 | EnvVars: []string{"PLUGIN_REBUILD"}, 133 | Destination: &settings.Rebuild, 134 | }, 135 | &cli.BoolFlag{ 136 | Name: "restore", 137 | Usage: "restore the cache directories", 138 | EnvVars: []string{"PLUGIN_RESTORE"}, 139 | Destination: &settings.Restore, 140 | }, 141 | &cli.BoolFlag{ 142 | Name: "flush", 143 | Usage: "flush the cache", 144 | EnvVars: []string{"PLUGIN_FLUSH"}, 145 | Destination: &settings.Flush, 146 | }, 147 | 148 | // S3 information 149 | 150 | &cli.StringFlag{ 151 | Name: "endpoint", 152 | Usage: "s3 endpoint", 153 | EnvVars: []string{"PLUGIN_SERVER", "PLUGIN_ENDPOINT", "CACHE_S3_ENDPOINT", "CACHE_S3_SERVER", "S3_ENDPOINT"}, 154 | Destination: &settings.S3Options.Endpoint, 155 | }, 156 | &cli.StringFlag{ 157 | Name: "accelerated-endpoint", 158 | Usage: "s3 accelerated endpoint", 159 | EnvVars: []string{"PLUGIN_ACCELERATED_ENDPOINT", "CACHE_S3_ACCELERATED_ENDPOINT"}, 160 | Destination: &settings.S3Options.AcceleratedEndpoint, 161 | }, 162 | &cli.StringFlag{ 163 | Name: "access-key", 164 | Usage: "s3 access key", 165 | EnvVars: []string{"PLUGIN_ACCESS_KEY", "CACHE_S3_ACCESS_KEY", "AWS_ACCESS_KEY_ID"}, 166 | Destination: &settings.S3Options.Access, 167 | }, 168 | &cli.StringFlag{ 169 | Name: "secret-key", 170 | Usage: "s3 secret key", 171 | EnvVars: []string{"PLUGIN_SECRET_KEY", "CACHE_S3_SECRET_KEY", "AWS_SECRET_ACCESS_KEY"}, 172 | Destination: &settings.S3Options.Secret, 173 | }, 174 | &cli.StringFlag{ 175 | Name: "session-token", 176 | Usage: "s3 session token", 177 | EnvVars: []string{"PLUGIN_SESSION_TOKEN", "CACHE_S3_SESSION_TOKEN", "AWS_SESSION_TOKEN"}, 178 | Destination: &settings.S3Options.Token, 179 | }, 180 | &cli.StringFlag{ 181 | Name: "region", 182 | Usage: "s3 region", 183 | EnvVars: []string{"PLUGIN_REGION", "CACHE_S3_REGION"}, 184 | Destination: &settings.S3Options.Region, 185 | }, 186 | &cli.StringFlag{ 187 | Name: "file-credentials", 188 | Usage: "path to s3 credentials file", 189 | EnvVars: []string{"PLUGIN_FILE_CREDENTIALS", "CACHE_FILE_CREDENTIALS", "AWS_SHARED_CREDENTIALS_FILE"}, 190 | Destination: &settings.S3Options.FileCredentials, 191 | }, 192 | &cli.StringFlag{ 193 | Name: "profile", 194 | Usage: "s3 profile name", 195 | EnvVars: []string{"PLUGIN_PROFILE", "CACHE_S3_PROFILE", "AWS_PROFILE"}, 196 | Destination: &settings.S3Options.Profile, 197 | }, 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /storage/s3/s3.go: -------------------------------------------------------------------------------- 1 | package s3 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "io" 7 | "strings" 8 | 9 | "github.com/drone/drone-cache-lib/storage" 10 | "github.com/dustin/go-humanize" 11 | "github.com/minio/minio-go/v7" 12 | "github.com/minio/minio-go/v7/pkg/credentials" 13 | "github.com/sirupsen/logrus" 14 | ) 15 | 16 | // Options contains configuration for the S3 connection. 17 | type Options struct { 18 | Endpoint string 19 | AcceleratedEndpoint string 20 | Key string 21 | Secret string 22 | Access string 23 | Token string 24 | FileCredentials string 25 | Profile string 26 | 27 | // us-east-1 28 | // us-west-1 29 | // us-west-2 30 | // eu-west-1 31 | // ap-southeast-1 32 | // ap-southeast-2 33 | // ap-northeast-1 34 | // sa-east-1 35 | Region string 36 | 37 | UseSSL bool 38 | } 39 | 40 | type s3Storage struct { 41 | client *minio.Client 42 | opts *Options 43 | ctx context.Context 44 | } 45 | 46 | // New method creates an implementation of Storage with S3 as the backend. 47 | func New(opts *Options) (storage.Storage, error) { 48 | var creds *credentials.Credentials 49 | if len(opts.Access) != 0 && len(opts.Secret) != 0 { 50 | creds = credentials.NewStaticV4(opts.Access, opts.Secret, opts.Token) 51 | } else if len(opts.FileCredentials) != 0 { 52 | creds = credentials.NewFileAWSCredentials(opts.FileCredentials, opts.Profile) 53 | } else { 54 | creds = credentials.NewIAM("") 55 | 56 | // See if the IAM role can be retrieved 57 | _, err := creds.Get() 58 | if err != nil { 59 | return nil, fmt.Errorf("could not connect to %s using IAM role: %w", opts.Endpoint, err) 60 | } 61 | } 62 | client, err := minio.New(opts.Endpoint, &minio.Options{ 63 | Creds: creds, 64 | Secure: opts.UseSSL, 65 | Region: opts.Region, 66 | }) 67 | 68 | if err != nil { 69 | return nil, fmt.Errorf("could not connect to %s: %w", opts.Endpoint, err) 70 | } 71 | 72 | if opts.AcceleratedEndpoint != "" { 73 | client.SetS3TransferAccelerate(opts.AcceleratedEndpoint) 74 | } 75 | 76 | return &s3Storage{ 77 | client: client, 78 | opts: opts, 79 | ctx: context.Background(), 80 | }, nil 81 | } 82 | 83 | func (s *s3Storage) Get(p string, dst io.Writer) error { 84 | bucket, key := splitBucket(p) 85 | 86 | if len(bucket) == 0 || len(key) == 0 { 87 | return fmt.Errorf("invalid path %s", p) 88 | } 89 | 90 | logrus.WithFields(logrus.Fields{ 91 | "bucket": bucket, 92 | "key": key, 93 | }).Info("downloading file") 94 | 95 | exists, err := s.client.BucketExists(s.ctx, bucket) 96 | if err != nil { 97 | return fmt.Errorf("error when accessing bucket %s: %w", bucket, err) 98 | } else if !exists { 99 | return fmt.Errorf("bucket %s does not exist", bucket) 100 | } 101 | 102 | object, err := s.client.GetObject(s.ctx, bucket, key, minio.GetObjectOptions{}) 103 | if err != nil { 104 | return fmt.Errorf("could not retrieve %s from %s: %w", bucket, key, err) 105 | } 106 | 107 | numBytes, err := io.Copy(dst, object) 108 | if err != nil { 109 | return err 110 | } 111 | 112 | logrus.WithFields(logrus.Fields{ 113 | "bucket": bucket, 114 | "key": key, 115 | "size": humanize.Bytes(uint64(numBytes)), 116 | }).Info("file downloaded", bucket, key) 117 | return nil 118 | } 119 | 120 | func (s *s3Storage) Put(p string, src io.Reader) error { 121 | bucket, key := splitBucket(p) 122 | 123 | if len(bucket) == 0 || len(key) == 0 { 124 | return fmt.Errorf("invalid path %s", p) 125 | } 126 | 127 | logrus.WithFields(logrus.Fields{ 128 | "bucket": bucket, 129 | "key": key, 130 | }).Info("uploading file") 131 | 132 | exists, err := s.client.BucketExists(s.ctx, bucket) 133 | if err != nil { 134 | return fmt.Errorf("error when accessing bucket %s: %w", bucket, err) 135 | } else if !exists { 136 | return fmt.Errorf("bucket %s does not exist", bucket) 137 | } 138 | 139 | if !exists { 140 | if err = s.client.MakeBucket(s.ctx, bucket, minio.MakeBucketOptions{Region: s.opts.Region}); err != nil { 141 | return fmt.Errorf("could not create bucket %s: %w", bucket, err) 142 | } 143 | logrus.WithField("name", bucket).Info("bucket created") 144 | } else { 145 | logrus.WithField("name", bucket).Info("bucket found") 146 | } 147 | 148 | uploadInfo, err := s.client.PutObject(s.ctx, bucket, key, src, -1, minio.PutObjectOptions{ContentType: "application/tar"}) 149 | if err != nil { 150 | return fmt.Errorf("could not put file in bucket %s at %s: %w", bucket, key, err) 151 | } 152 | 153 | logrus.WithFields(logrus.Fields{ 154 | "bucket": bucket, 155 | "key": key, 156 | "size": uploadInfo, 157 | }).Info("file uploaded") 158 | return nil 159 | } 160 | 161 | func (s *s3Storage) List(p string) ([]storage.FileEntry, error) { 162 | bucket, key := splitBucket(p) 163 | 164 | if len(bucket) == 0 || len(key) == 0 { 165 | return nil, fmt.Errorf("invalid path %s", p) 166 | } 167 | 168 | logrus.WithFields(logrus.Fields{ 169 | "bucket": bucket, 170 | "key": key, 171 | }).Info("finding objects") 172 | 173 | exists, err := s.client.BucketExists(s.ctx, bucket) 174 | if err != nil { 175 | return nil, fmt.Errorf("error when accessing bucket %s: %w", bucket, err) 176 | } else if !exists { 177 | return nil, fmt.Errorf("bucket %s does not exist", bucket) 178 | } 179 | 180 | var objects []storage.FileEntry 181 | opts := minio.ListObjectsOptions{ 182 | Recursive: true, 183 | Prefix: key, 184 | } 185 | 186 | for object := range s.client.ListObjects(s.ctx, bucket, opts) { 187 | if object.Err != nil { 188 | return nil, fmt.Errorf("could not get file in bucket %s at %s: %w", bucket, object.Key, object.Err) 189 | } 190 | 191 | path := bucket + "/" + object.Key 192 | objects = append(objects, storage.FileEntry{ 193 | Path: path, 194 | Size: object.Size, 195 | LastModified: object.LastModified, 196 | }) 197 | logrus.WithFields(logrus.Fields{ 198 | "bucket": bucket, 199 | "key": object.Key, 200 | "size": humanize.Bytes(uint64(object.Size)), 201 | "last-modified": object.LastModified, 202 | }).Debug("found object") 203 | } 204 | 205 | logrus.WithFields(logrus.Fields{ 206 | "bucket": bucket, 207 | "key": key, 208 | "count": len(objects), 209 | }).Info("found objects") 210 | return objects, nil 211 | } 212 | 213 | func (s *s3Storage) Delete(p string) error { 214 | bucket, key := splitBucket(p) 215 | 216 | if len(bucket) == 0 || len(key) == 0 { 217 | return fmt.Errorf("invalid path %s", p) 218 | } 219 | 220 | logrus.WithFields(logrus.Fields{ 221 | "bucket": bucket, 222 | "key": key, 223 | }).Info("deleting object") 224 | 225 | exists, err := s.client.BucketExists(s.ctx, bucket) 226 | if err != nil { 227 | return fmt.Errorf("error when accessing bucket %s: %w", bucket, err) 228 | } else if !exists { 229 | return fmt.Errorf("bucket %s does not exist", bucket) 230 | } 231 | 232 | err = s.client.RemoveObject(s.ctx, bucket, key, minio.RemoveObjectOptions{}) 233 | if err != nil { 234 | return fmt.Errorf("could not delete file in %s at %s: %w", bucket, key, err) 235 | } 236 | return err 237 | } 238 | 239 | func splitBucket(p string) (string, string) { 240 | // Remove initial forward slash 241 | full := strings.TrimPrefix(p, "/") 242 | 243 | // Get first index 244 | i := strings.Index(full, "/") 245 | 246 | if i != -1 && len(full) != i+1 { 247 | // Bucket names need to be all lower case for the key it doesnt matter 248 | return strings.ToLower(full[0:i]), full[i+1:] 249 | } 250 | 251 | return "", "" 252 | } 253 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 3 | github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= 4 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 5 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 6 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc= 9 | github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8= 10 | github.com/drone/drone-cache-lib v0.0.0-20200806063744-981868645a25 h1:N+6U73tFu7x3t9+9dj7hetfgp/ZZ1J4bMU7amKiNh+c= 11 | github.com/drone/drone-cache-lib v0.0.0-20200806063744-981868645a25/go.mod h1:Np7bwqKAR0z64YNaQUsx+hxX8AjNQ74I8TbZmjNitr4= 12 | github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= 13 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= 14 | github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727 h1:eouy4stZdUKn7n98c1+rdUTxWMg+jvhP+oHt0K8fiug= 15 | github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= 16 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 17 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 18 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 19 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 20 | github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= 21 | github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= 22 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 23 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 24 | github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= 25 | github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= 26 | github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 27 | github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 28 | github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0= 29 | github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= 30 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 31 | github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 32 | github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= 33 | github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= 34 | github.com/minio/minio-go/v7 v7.0.45 h1:g4IeM9M9pW/Lo8AGGNOjBZYlvmtlE1N5TQEYWXRWzIs= 35 | github.com/minio/minio-go/v7 v7.0.45/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw= 36 | github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= 37 | github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= 38 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 39 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 40 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 41 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 42 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 43 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 44 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 45 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 46 | github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= 47 | github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= 48 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 49 | github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 50 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 51 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 52 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 53 | github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= 54 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 55 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 56 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 57 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 58 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 59 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 60 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 61 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 62 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 63 | github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= 64 | github.com/urfave/cli/v2 v2.23.6 h1:iWmtKD+prGo1nKUtLO0Wg4z9esfBM4rAV4QRLQiEmJ4= 65 | github.com/urfave/cli/v2 v2.23.6/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= 66 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= 67 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= 68 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 69 | golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= 70 | golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= 71 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 72 | golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= 73 | golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= 74 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 75 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 76 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 77 | golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 78 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 79 | golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= 80 | golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 81 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 82 | golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= 83 | golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 84 | golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 85 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 86 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 87 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 88 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 89 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 90 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 91 | gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= 92 | -------------------------------------------------------------------------------- /plugin/impl.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "fmt" 10 | "net/url" 11 | "os" 12 | pathutil "path" 13 | "strings" 14 | "time" 15 | 16 | "github.com/drone-plugins/drone-s3-cache/storage/s3" 17 | "github.com/drone/drone-cache-lib/archive/util" 18 | "github.com/drone/drone-cache-lib/cache" 19 | "github.com/drone/drone-cache-lib/storage" 20 | "github.com/sirupsen/logrus" 21 | "github.com/urfave/cli/v2" 22 | ) 23 | 24 | // Settings for the plugin. 25 | type Settings struct { 26 | Mode string 27 | Root string 28 | Filename string 29 | Path string 30 | FallbackPath string 31 | FlushPath string 32 | FlushAge int 33 | Mount cli.StringSlice 34 | Restore bool // DEPRECATED 35 | Rebuild bool // DEPRECATED 36 | Flush bool // DEPRECATED 37 | 38 | S3Options s3.Options 39 | mount []string 40 | } 41 | 42 | const ( 43 | restoreMode = "restore" 44 | rebuildMode = "rebuild" 45 | flushMode = "flush" 46 | 47 | awsDomain = "amazonaws.com" 48 | awsEndpoint = "https://s3." + awsDomain 49 | ) 50 | 51 | // Validate handles the settings validation of the plugin. 52 | func (p *Plugin) Validate() error { 53 | if err := p.validateMode(); err != nil { 54 | return err 55 | } 56 | return p.validateS3() 57 | } 58 | 59 | func (p *Plugin) validateMode() error { 60 | // Validate the mode 61 | mode := p.settings.Mode 62 | hasMode := p.settings.Rebuild || p.settings.Restore || p.settings.Flush 63 | if mode == "" { 64 | logrus.WithFields(logrus.Fields{ 65 | "rebuild": p.settings.Rebuild, 66 | "restore": p.settings.Restore, 67 | "flush": p.settings.Flush, 68 | }).Info("mode specified using boolean config") 69 | 70 | if !hasMode { 71 | return fmt.Errorf("no mode specified") 72 | } 73 | if multipleModesSpecified(p.settings.Rebuild, p.settings.Restore, p.settings.Flush) { 74 | return fmt.Errorf("multiple modes specified") 75 | } 76 | 77 | if p.settings.Rebuild { 78 | mode = rebuildMode 79 | } else if p.settings.Restore { 80 | mode = restoreMode 81 | } else { 82 | mode = flushMode 83 | } 84 | } else { 85 | if hasMode { 86 | return fmt.Errorf("mode specified multiple ways") 87 | } 88 | 89 | if mode != rebuildMode && mode != restoreMode && mode != flushMode { 90 | return fmt.Errorf("invalid mode %s specified", mode) 91 | } 92 | } 93 | 94 | logrus.WithField("mode", mode).Info("using mode") 95 | p.settings.Mode = mode 96 | 97 | if p.settings.Filename == "" { 98 | logrus.Debug("using default filename") 99 | p.settings.Filename = "archive.tar" 100 | } 101 | logrus.WithField("filename", p.settings.Filename).Debug("using filename") 102 | 103 | // Validate mode settings 104 | if mode != flushMode { 105 | if p.settings.Path == "" { 106 | logrus.WithFields(logrus.Fields{ 107 | "repo.owner": p.pipeline.Repo.Owner, 108 | "repo.name": p.pipeline.Repo.Name, 109 | "commit.branch": p.pipeline.Commit.Branch, 110 | }).Debug("creating default path") 111 | p.settings.Path = fmt.Sprintf( 112 | "%s/%s/%s", 113 | p.pipeline.Repo.Owner, 114 | p.pipeline.Repo.Name, 115 | p.pipeline.Commit.Branch, 116 | ) 117 | } 118 | logrus.WithField("path", p.settings.Path).Debug("using path") 119 | 120 | if mode == rebuildMode { 121 | mount := p.settings.Mount.Value() 122 | if len(mount) == 0 { 123 | return fmt.Errorf("cache not specified") 124 | } 125 | p.settings.mount = mount 126 | } else { 127 | if p.settings.FallbackPath == "" { 128 | logrus.WithFields(logrus.Fields{ 129 | "repo.owner": p.pipeline.Repo.Owner, 130 | "repo.name": p.pipeline.Repo.Name, 131 | "repo.branch": p.pipeline.Repo.Branch, 132 | }).Debug("creating default fallback path") 133 | p.settings.FallbackPath = fmt.Sprintf( 134 | "%s/%s/%s", 135 | p.pipeline.Repo.Owner, 136 | p.pipeline.Repo.Name, 137 | p.pipeline.Repo.Branch, 138 | ) 139 | } 140 | logrus.WithField("path", p.settings.FallbackPath).Debug("using path as fallback") 141 | } 142 | } else { 143 | if p.settings.FlushPath == "" { 144 | logrus.WithFields(logrus.Fields{ 145 | "repo.owner": p.pipeline.Repo.Owner, 146 | "repo.name": p.pipeline.Repo.Name, 147 | }).Debug("creating default flush path") 148 | p.settings.FlushPath = fmt.Sprintf( 149 | "%s/%s", 150 | p.pipeline.Repo.Owner, 151 | p.pipeline.Repo.Name, 152 | ) 153 | } 154 | logrus.WithField("path", p.settings.FlushPath).Debug("using path when flushing") 155 | } 156 | 157 | return nil 158 | } 159 | 160 | func (p *Plugin) validateS3() error { 161 | // Validate the endpoint 162 | endpoint := p.settings.S3Options.Endpoint 163 | isAWS := false 164 | bucket := "" 165 | region := "" 166 | 167 | if endpoint == "" { 168 | endpoint = awsEndpoint 169 | } 170 | 171 | s3url, err := url.Parse(endpoint) 172 | if err != nil { 173 | return fmt.Errorf("could not parse endpoint %s", endpoint) 174 | } 175 | 176 | // Check if additional information is encoded in the endpoint 177 | if h := s3url.Hostname(); strings.HasSuffix(h, awsDomain) { 178 | isAWS = true 179 | 180 | // Sub-domains can specify region and bucket 181 | d := strings.Split(h, ".") 182 | s3sub := 0 183 | 184 | switch len(d) { 185 | case 5: 186 | // Virtual hosted style access 187 | // https://bucket-name.s3.Region.amazonaws.com/ 188 | logrus.WithField("host", h).Debug("using virtual host style access") 189 | bucket = d[0] 190 | s3sub = 1 191 | region = d[2] 192 | case 4: 193 | // Path-style access 194 | // https://s3.Region.amazonaws.com/bucket-name 195 | logrus.WithField("host", h).Debug("using path style access") 196 | bucket = s3url.Path 197 | s3sub = 0 198 | region = d[1] 199 | case 3: 200 | // Just default url https://s3.Region.amazonaws.com 201 | default: 202 | return fmt.Errorf("unknown aws domain for url %s", endpoint) 203 | } 204 | 205 | if d[s3sub] != "s3" { 206 | return fmt.Errorf("unknown aws domain for url %s", endpoint) 207 | } 208 | 209 | // Normalize endpoint 210 | endpoint = awsEndpoint 211 | s3url, _ = url.Parse(endpoint) 212 | } 213 | 214 | // Check for s3 scheme 215 | if s3url.Scheme == "s3" { 216 | logrus.WithField("endpoint", endpoint).Debug("using s3 url") 217 | bucket = s3url.Hostname() 218 | 219 | // Normalize endpoint 220 | endpoint = awsEndpoint 221 | s3url, _ = url.Parse(endpoint) 222 | } 223 | 224 | var useSSL bool 225 | switch s3url.Scheme { 226 | case "https": 227 | endpoint = endpoint[8:] 228 | useSSL = true 229 | case "http": 230 | endpoint = endpoint[7:] 231 | useSSL = false 232 | default: 233 | return fmt.Errorf("unknown scheme for endpoint %s", endpoint) 234 | } 235 | 236 | if bucket != "" { 237 | logrus.WithField("bucket", bucket).Info("bucket found in S3 endpoint") 238 | if p.settings.Root != "" { 239 | return fmt.Errorf("bucket %s already specified in endpoint remove from root", bucket) 240 | } 241 | p.settings.Root = bucket 242 | } 243 | 244 | if region != "" { 245 | logrus.WithField("region", region).Info("region found in S3 endpoint") 246 | if p.settings.S3Options.Region != "" { 247 | return fmt.Errorf("region %s already specified in endpoint remove from config", region) 248 | } 249 | p.settings.S3Options.Region = region 250 | } 251 | s3Opts := p.settings.S3Options 252 | 253 | if (s3Opts.Access != "" || s3Opts.Secret != "") && s3Opts.FileCredentials != "" { 254 | return fmt.Errorf("only one credentials method should be used. Use either access-key and secret-key OR the credentials file") 255 | } 256 | 257 | if s3Opts.FileCredentials != "" { 258 | if _, err := os.Stat(s3Opts.FileCredentials); os.IsNotExist(err) { 259 | return fmt.Errorf("file %s does not exist", s3Opts.FileCredentials) 260 | } 261 | } 262 | 263 | logrus.WithFields(logrus.Fields{ 264 | "endpoint": endpoint, 265 | "use-ssl": useSSL, 266 | }).Info("using S3 endpoint") 267 | p.settings.S3Options.Endpoint = endpoint 268 | p.settings.S3Options.UseSSL = useSSL 269 | 270 | if isAWS && p.settings.Root == "" { 271 | return fmt.Errorf("no aws bucket specified in root or endpoint") 272 | } 273 | 274 | return nil 275 | } 276 | 277 | // Execute provides the implementation of the plugin. 278 | func (p *Plugin) Execute() error { 279 | at, err := util.FromFilename(p.settings.Filename) 280 | if err != nil { 281 | return err 282 | } 283 | 284 | st, err := s3.New(&p.settings.S3Options) 285 | if err != nil { 286 | return err 287 | } 288 | 289 | c := cache.New(st, at) 290 | 291 | if p.settings.Mode == rebuildMode { 292 | path := cleanPath(p.settings.Root, p.settings.Path, p.settings.Filename) 293 | logrus.WithFields(logrus.Fields{ 294 | "path": path, 295 | }).Info("rebuilding cache") 296 | err = c.Rebuild(p.settings.mount, path) 297 | 298 | if err == nil { 299 | logrus.Infof("cache rebuilt") 300 | } 301 | } else if p.settings.Mode == restoreMode { 302 | path := cleanPath(p.settings.Root, p.settings.Path, p.settings.Filename) 303 | fallbackPath := cleanPath(p.settings.Root, p.settings.FallbackPath, p.settings.Filename) 304 | 305 | logrus.WithFields(logrus.Fields{ 306 | "path": path, 307 | "fallback": fallbackPath, 308 | }).Info("restoring cache") 309 | err = c.Restore(path, fallbackPath) 310 | 311 | if err == nil { 312 | logrus.Info("cache restored") 313 | } 314 | } else /* p.settings.Mode == flushMode */ { 315 | flushPath := cleanPath(p.settings.Root, p.settings.FlushPath) 316 | 317 | logrus.WithFields(logrus.Fields{ 318 | "path": flushPath, 319 | "max-age": p.settings.FlushAge, 320 | }).Info("flushing cache") 321 | f := cache.NewFlusher(st, genIsExpired(p.settings.FlushAge)) 322 | err = f.Flush(flushPath) 323 | 324 | if err == nil { 325 | logrus.Info("Cache flushed") 326 | } 327 | } 328 | 329 | return err 330 | } 331 | 332 | func genIsExpired(age int) cache.DirtyFunc { 333 | return func(file storage.FileEntry) bool { 334 | // Check if older than "age" days 335 | return file.LastModified.Before(time.Now().AddDate(0, 0, age*-1)) 336 | } 337 | } 338 | 339 | func cleanPath(paths ...string) string { 340 | return pathutil.Clean(pathutil.Join(paths...)) 341 | } 342 | 343 | func multipleModesSpecified(bools ...bool) bool { 344 | var b bool 345 | for _, v := range bools { 346 | if b && b == v { 347 | return true 348 | } 349 | 350 | if v { 351 | b = true 352 | } 353 | } 354 | 355 | return false 356 | } 357 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------