├── .dockerignore ├── .drone.yml ├── .github ├── issue_template.md ├── pull_request_template.md └── settings.yml ├── .gitignore ├── .harness ├── eventPR.yaml ├── eventPush.yaml ├── eventTag.yaml └── harness.yaml ├── LICENSE ├── README.md ├── archive └── tar.go ├── docker ├── Dockerfile.linux.amd64 ├── Dockerfile.linux.arm64 ├── Dockerfile.windows.1809 ├── Dockerfile.windows.ltsc2022 └── manifest.tmpl ├── go.mod ├── go.sum ├── local.go ├── main.go ├── plugin.go └── renovate.json /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !release/ 3 | -------------------------------------------------------------------------------- /.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.20 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.20 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.20 50 | pull: always 51 | environment: 52 | CGO_ENABLED: "0" 53 | commands: 54 | - go version 55 | - go env 56 | - name: build 57 | image: golang:1.20 58 | environment: 59 | CGO_ENABLED: "0" 60 | commands: 61 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-volume-cache . 62 | - name: docker 63 | image: plugins/docker 64 | settings: 65 | dockerfile: docker/Dockerfile.linux.amd64 66 | repo: plugins/volume-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.20 94 | pull: always 95 | environment: 96 | CGO_ENABLED: "0" 97 | commands: 98 | - go version 99 | - go env 100 | - name: build 101 | image: golang:1.20 102 | environment: 103 | CGO_ENABLED: "0" 104 | commands: 105 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-volume-cache . 106 | - name: docker 107 | image: plugins/docker 108 | settings: 109 | dockerfile: docker/Dockerfile.linux.arm64 110 | repo: plugins/volume-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.20 138 | pull: always 139 | environment: 140 | CGO_ENABLED: "0" 141 | commands: 142 | - go version 143 | - go env 144 | - name: build 145 | image: golang:1.20 146 | environment: 147 | CGO_ENABLED: "0" 148 | commands: 149 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-volume-cache.exe . 150 | - name: docker 151 | image: plugins/docker 152 | settings: 153 | dockerfile: docker/Dockerfile.windows.1809 154 | repo: plugins/volume-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.20 188 | pull: always 189 | environment: 190 | CGO_ENABLED: "0" 191 | commands: 192 | - go version 193 | - go env 194 | - name: build 195 | image: golang:1.20 196 | environment: 197 | CGO_ENABLED: "0" 198 | commands: 199 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-volume-cache.exe . 200 | - name: docker 201 | image: plugins/docker 202 | settings: 203 | dockerfile: docker/Dockerfile.windows.ltsc2022 204 | repo: plugins/volume-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 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-volume-cache/3db09f3f2b792c7da7cc71bfd952873924748e6a/.github/pull_request_template.md -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | repository: 2 | name: drone-volume-cache 3 | description: Drone plugin to cache directories within the build workspace 4 | homepage: http://plugins.drone.io/drone-plugins/drone-volume-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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | release/ 27 | vendor/ 28 | 29 | coverage.out 30 | drone-volume-cache 31 | -------------------------------------------------------------------------------- /.harness/eventPR.yaml: -------------------------------------------------------------------------------- 1 | inputSet: 2 | name: event-PR 3 | identifier: eventPR 4 | orgIdentifier: default 5 | projectIdentifier: Drone_Plugins 6 | pipeline: 7 | identifier: dronevolumecacheharness 8 | properties: 9 | ci: 10 | codebase: 11 | build: 12 | type: PR 13 | spec: 14 | number: <+trigger.prNumber> 15 | -------------------------------------------------------------------------------- /.harness/eventPush.yaml: -------------------------------------------------------------------------------- 1 | inputSet: 2 | name: event-Push 3 | identifier: eventPush 4 | orgIdentifier: default 5 | projectIdentifier: Drone_Plugins 6 | pipeline: 7 | identifier: dronevolumecacheharness 8 | properties: 9 | ci: 10 | codebase: 11 | build: 12 | type: branch 13 | spec: 14 | branch: <+trigger.branch> 15 | -------------------------------------------------------------------------------- /.harness/eventTag.yaml: -------------------------------------------------------------------------------- 1 | inputSet: 2 | name: event-Tag 3 | identifier: eventTag 4 | orgIdentifier: default 5 | projectIdentifier: Drone_Plugins 6 | pipeline: 7 | identifier: dronevolumecacheharness 8 | properties: 9 | ci: 10 | codebase: 11 | build: 12 | type: tag 13 | spec: 14 | tag: <+trigger.tag> 15 | -------------------------------------------------------------------------------- /.harness/harness.yaml: -------------------------------------------------------------------------------- 1 | pipeline: 2 | name: drone-volume-cache-harness 3 | identifier: dronevolumecacheharness 4 | projectIdentifier: Drone_Plugins 5 | orgIdentifier: default 6 | tags: {} 7 | properties: 8 | ci: 9 | codebase: 10 | connectorRef: GitHub_Drone_Plugins_Org 11 | repoName: drone-volume-cache 12 | build: <+input> 13 | sparseCheckout: [] 14 | stages: 15 | - stage: 16 | name: Testing Stage 17 | identifier: Testing_Stage 18 | type: CI 19 | spec: 20 | cloneCodebase: true 21 | caching: 22 | enabled: false 23 | paths: [] 24 | platform: 25 | os: Linux 26 | arch: Amd64 27 | runtime: 28 | type: Cloud 29 | spec: {} 30 | execution: 31 | steps: 32 | - step: 33 | type: Run 34 | name: Lint 35 | identifier: Lint 36 | spec: 37 | connectorRef: Plugins_Docker_Hub_Connector 38 | image: golang:1.20 39 | shell: Sh 40 | command: |- 41 | go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 42 | golangci-lint version 43 | golangci-lint run 44 | - step: 45 | type: Run 46 | name: Test 47 | identifier: Run_1 48 | spec: 49 | connectorRef: Plugins_Docker_Hub_Connector 50 | image: golang:1.20 51 | shell: Sh 52 | command: go test -cover ./... 53 | description: "" 54 | - parallel: 55 | - stage: 56 | name: linux-amd64 57 | identifier: linuxamd64 58 | type: CI 59 | spec: 60 | cloneCodebase: true 61 | caching: 62 | enabled: false 63 | paths: [] 64 | platform: 65 | os: Linux 66 | arch: Amd64 67 | runtime: 68 | type: Cloud 69 | spec: {} 70 | execution: 71 | steps: 72 | - step: 73 | name: Build binaries 74 | identifier: Build_binaries 75 | type: Run 76 | spec: 77 | connectorRef: Plugins_Docker_Hub_Connector 78 | image: golang:1.20 79 | shell: Sh 80 | command: |- 81 | # force go modules 82 | export GOPATH="" 83 | 84 | # disable cgo 85 | export CGO_ENABLED=0 86 | 87 | set -e 88 | set -x 89 | 90 | # linux 91 | export GOOS=linux GOARCH=amd64 92 | go build -v -a -tags netgo -o release/linux/amd64/drone-volume-cache . 93 | when: 94 | stageStatus: Success 95 | - step: 96 | type: Plugin 97 | name: BuildAndPushDockerPlugin 98 | identifier: BuildAndPushDockerPlugin 99 | spec: 100 | connectorRef: Plugins_Docker_Hub_Connector 101 | image: plugins/docker 102 | settings: 103 | username: drone 104 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 105 | repo: plugins/volume-cache 106 | dockerfile: docker/Dockerfile.linux.amd64 107 | auto_tag: "true" 108 | auto_tag_suffix: linux-amd64 109 | when: 110 | stageStatus: Success 111 | condition: <+codebase.build.type> == "tag" 112 | - step: 113 | type: BuildAndPushDockerRegistry 114 | name: BuildAndPushDockerRegistry 115 | identifier: BuildAndPushDockerRegistry 116 | spec: 117 | connectorRef: Plugins_Docker_Hub_Connector 118 | repo: plugins/volume-cache 119 | tags: 120 | - linux-amd64 121 | caching: false 122 | dockerfile: docker/Dockerfile.linux.amd64 123 | when: 124 | stageStatus: Success 125 | condition: | 126 | <+codebase.build.type> == "branch" 127 | description: "" 128 | - stage: 129 | name: linux-arm64 130 | identifier: linuxarm64 131 | type: CI 132 | spec: 133 | cloneCodebase: true 134 | caching: 135 | enabled: false 136 | paths: [] 137 | platform: 138 | os: Linux 139 | arch: Arm64 140 | runtime: 141 | type: Cloud 142 | spec: {} 143 | execution: 144 | steps: 145 | - step: 146 | name: Build binaries 147 | identifier: Build_binaries 148 | type: Run 149 | spec: 150 | connectorRef: Plugins_Docker_Hub_Connector 151 | image: golang:1.20 152 | shell: Sh 153 | command: |- 154 | # force go modules 155 | export GOPATH="" 156 | 157 | # disable cgo 158 | export CGO_ENABLED=0 159 | 160 | set -e 161 | set -x 162 | 163 | # linux 164 | export GOOS=linux GOARCH=arm64 165 | go build -v -a -tags netgo -o release/linux/arm64/drone-volume-cache . 166 | when: 167 | stageStatus: Success 168 | - step: 169 | type: Plugin 170 | name: BuildAndPushDockerPlugin 171 | identifier: BuildAndPushDockerPlugin 172 | spec: 173 | connectorRef: Plugins_Docker_Hub_Connector 174 | image: plugins/docker 175 | settings: 176 | username: drone 177 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 178 | repo: plugins/volume-cache 179 | dockerfile: docker/Dockerfile.linux.arm64 180 | auto_tag: "true" 181 | auto_tag_suffix: linux-arm64 182 | when: 183 | stageStatus: Success 184 | condition: <+codebase.build.type> == "tag" 185 | - step: 186 | type: BuildAndPushDockerRegistry 187 | name: BuildAndPushDockerRegistry 188 | identifier: BuildAndPushDockerRegistry 189 | spec: 190 | connectorRef: Plugins_Docker_Hub_Connector 191 | repo: plugins/volume-cache 192 | tags: 193 | - linux-arm64 194 | caching: false 195 | dockerfile: docker/Dockerfile.linux.arm64 196 | when: 197 | stageStatus: Success 198 | condition: | 199 | <+codebase.build.type> == "branch" 200 | description: "" 201 | - stage: 202 | name: windows-1809-amd64 203 | identifier: windows1809amd64 204 | type: CI 205 | spec: 206 | cloneCodebase: true 207 | caching: 208 | enabled: false 209 | paths: [] 210 | execution: 211 | steps: 212 | - step: 213 | name: Build binaries 214 | identifier: Build_binaries 215 | type: Run 216 | spec: 217 | connectorRef: Plugins_Docker_Hub_Connector 218 | image: golang:1.20 219 | shell: Sh 220 | command: |- 221 | # force go modules 222 | export GOPATH="" 223 | 224 | # disable cgo 225 | export CGO_ENABLED=0 226 | 227 | set -e 228 | set -x 229 | 230 | # Windows 231 | GOOS=windows 232 | go build -v -a -tags netgo -o release/windows/amd64/drone-volume-cache.exe . 233 | when: 234 | stageStatus: Success 235 | - step: 236 | type: Plugin 237 | name: BuildAndPushDockerPlugin 238 | identifier: BuildAndPushDockerPlugin 239 | spec: 240 | connectorRef: Plugins_Docker_Hub_Connector 241 | image: plugins/docker 242 | settings: 243 | username: drone 244 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 245 | repo: plugins/volume-cache 246 | dockerfile: docker/Dockerfile.windows.1809 247 | auto_tag: "true" 248 | auto_tag_suffix: windows-1809-amd64 249 | when: 250 | stageStatus: Success 251 | condition: <+codebase.build.type> == "tag" 252 | - step: 253 | type: BuildAndPushDockerRegistry 254 | name: BuildAndPushDockerRegistry 255 | identifier: BuildAndPushDockerRegistry 256 | spec: 257 | connectorRef: Plugins_Docker_Hub_Connector 258 | repo: plugins/volume-cache 259 | tags: 260 | - windows-1809-amd64 261 | caching: false 262 | dockerfile: docker/Dockerfile.windows.1809 263 | when: 264 | stageStatus: Success 265 | condition: | 266 | <+codebase.build.type> == "branch" 267 | infrastructure: 268 | type: VM 269 | spec: 270 | type: Pool 271 | spec: 272 | poolName: windows-2019 273 | os: Windows 274 | description: "" 275 | delegateSelectors: 276 | - windows-vm 277 | - stage: 278 | name: windows-ltsc2022-amd64 279 | identifier: windowsltsc2022amd64 280 | type: CI 281 | spec: 282 | cloneCodebase: true 283 | caching: 284 | enabled: false 285 | paths: [] 286 | platform: 287 | os: Windows 288 | arch: Amd64 289 | runtime: 290 | type: Cloud 291 | spec: {} 292 | execution: 293 | steps: 294 | - step: 295 | name: Build binaries 296 | identifier: Build_binaries 297 | type: Run 298 | spec: 299 | connectorRef: Plugins_Docker_Hub_Connector 300 | image: golang:1.20 301 | shell: Sh 302 | command: |- 303 | # force go modules 304 | export GOPATH="" 305 | 306 | # disable cgo 307 | export CGO_ENABLED=0 308 | 309 | set -e 310 | set -x 311 | 312 | # Windows 313 | GOOS=windows 314 | go build -v -a -tags netgo -o release/windows/amd64/drone-volume-cache.exe . 315 | - step: 316 | type: Plugin 317 | name: BuildAndPushDockerPlugin 318 | identifier: BuildAndPushDockerPlugin 319 | spec: 320 | connectorRef: Plugins_Docker_Hub_Connector 321 | image: plugins/docker 322 | settings: 323 | username: drone 324 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 325 | repo: plugins/volume-cache 326 | dockerfile: docker/Dockerfile.windows.ltsc2022 327 | auto_tag: "true" 328 | auto_tag_suffix: windows-ltsc2022-amd64 329 | when: 330 | stageStatus: Success 331 | condition: <+codebase.build.type> == "tag" 332 | - step: 333 | type: BuildAndPushDockerRegistry 334 | name: BuildAndPushDockerRegistry 335 | identifier: BuildAndPushDockerRegistry 336 | spec: 337 | connectorRef: Plugins_Docker_Hub_Connector 338 | repo: plugins/volume-cache 339 | tags: 340 | - windows-ltsc2022-amd64 341 | caching: false 342 | dockerfile: docker/Dockerfile.windows.ltsc2022 343 | when: 344 | stageStatus: Success 345 | condition: | 346 | <+codebase.build.type> == "branch" 347 | description: "" 348 | - stage: 349 | name: Manifest 350 | identifier: Manifest 351 | type: CI 352 | spec: 353 | cloneCodebase: true 354 | caching: 355 | enabled: false 356 | paths: [] 357 | platform: 358 | os: Linux 359 | arch: Amd64 360 | runtime: 361 | type: Cloud 362 | spec: {} 363 | execution: 364 | steps: 365 | - step: 366 | type: Plugin 367 | name: Manifest 368 | identifier: Manifest 369 | spec: 370 | connectorRef: Plugins_Docker_Hub_Connector 371 | image: plugins/manifest 372 | settings: 373 | username: drone 374 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 375 | auto_tag: "true" 376 | ignore_missing: "true" 377 | spec: docker/manifest.tmpl 378 | when: 379 | stageStatus: Success 380 | condition: | 381 | <+codebase.build.type> == "tag" || <+codebase.build.type> == "branch" 382 | description: "" 383 | allowStageExecutions: true 384 | -------------------------------------------------------------------------------- /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 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # drone-volume-cache 2 | 3 | [![Build Status](http://cloud.drone.io/api/badges/drone-plugins/drone-volume-cache/status.svg)](http://cloud.drone.io/drone-plugins/drone-volume-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/volume-cache.svg)](https://microbadger.com/images/plugins/volume-cache "Get your own image badge on microbadger.com") 8 | [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-volume-cache?status.svg)](http://godoc.org/github.com/drone-plugins/drone-volume-cache) 9 | [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-volume-cache)](https://goreportcard.com/report/github.com/drone-plugins/drone-volume-cache) 10 | 11 | Drone plugin that allows you to cache directories within the build workspace, this plugin is backed by Docker volumes. 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-volume-cache/). 12 | 13 | ## Build 14 | 15 | Build the binary with the following commands: 16 | 17 | ``` 18 | go build 19 | ``` 20 | 21 | ## Docker 22 | 23 | Build the Docker image with the following commands: 24 | 25 | ``` 26 | GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-volume-cache 27 | docker build --rm -t plugins/volume-cache . 28 | ``` 29 | 30 | ## Usage 31 | 32 | Execute from the working directory: 33 | 34 | ``` 35 | docker run --rm \ 36 | -e PLUGIN_FLUSH=true \ 37 | -e PLUGIN_TTL=1 \ 38 | -v $(pwd):$(pwd) \ 39 | -v /tmp/cache:/cache \ 40 | -w $(pwd) \ 41 | plugins/volume-cache 42 | 43 | docker run --rm \ 44 | -e PLUGIN_RESTORE=true \ 45 | -e PLUGIN_FILE="backup.tar" \ 46 | -e DRONE_REPO_OWNER="foo" \ 47 | -e DRONE_REPO_NAME="bar" \ 48 | -e DRONE_COMMIT_BRANCH="test"\ 49 | -v $(pwd):$(pwd) \ 50 | -v /tmp/cache:/cache \ 51 | -w $(pwd) \ 52 | plugins/volume-cache 53 | 54 | docker run -it --rm \ 55 | -v $(pwd):$(pwd) \ 56 | -v /tmp/cache:/cache \ 57 | -w $(pwd) \ 58 | alpine:latest sh -c "mkdir -p cache && echo 'testing cache' >> cache/test && cat cache/test" 59 | 60 | docker run --rm \ 61 | -e PLUGIN_REBUILD=true \ 62 | -e PLUGIN_MOUNT="./cache" \ 63 | -e PLUGIN_FILE="backup.tar" \ 64 | -e DRONE_REPO_OWNER="foo" \ 65 | -e DRONE_REPO_NAME="bar" \ 66 | -e DRONE_COMMIT_BRANCH="test"\ 67 | -v $(pwd):$(pwd) \ 68 | -v /tmp/cache:/cache \ 69 | -w $(pwd) \ 70 | plugins/volume-cache 71 | ``` 72 | -------------------------------------------------------------------------------- /archive/tar.go: -------------------------------------------------------------------------------- 1 | package archive 2 | 3 | import ( 4 | "io" 5 | 6 | "github.com/sirupsen/logrus" 7 | "github.com/drone/drone-cache-lib/archive" 8 | "github.com/replicon/fast-archiver/falib" 9 | ) 10 | 11 | type fastArchiver struct{} 12 | 13 | // New returns a new archiver based on fast-archiver. 14 | func New() archive.Archive { 15 | return new(fastArchiver) 16 | } 17 | 18 | func (fa *fastArchiver) Pack(dirs []string, w io.Writer) error { 19 | a := falib.NewArchiver(w) 20 | a.BlockSize = 4096 21 | a.DirScanQueueSize = 128 22 | a.FileReadQueueSize = 128 23 | a.BlockQueueSize = 128 24 | a.DirReaderCount = 16 25 | a.FileReaderCount = 16 26 | 27 | a.Logger = &logger{} 28 | for _, dir := range dirs { 29 | a.AddDir(dir) 30 | } 31 | return a.Run() 32 | } 33 | 34 | func (fa *fastArchiver) Unpack(dst string, r io.Reader) error { 35 | a := falib.NewUnarchiver(r) 36 | a.Logger = &logger{} 37 | return a.Run() 38 | } 39 | 40 | type logger struct{} 41 | 42 | func (l *logger) Verbose(v ...interface{}) { 43 | logrus.Debug(v...) 44 | } 45 | 46 | func (l *logger) Warning(v ...interface{}) { 47 | logrus.Warn(v...) 48 | } 49 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.amd64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone Volume Cache" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/amd64/drone-volume-cache /bin/ 9 | ENTRYPOINT ["/bin/drone-volume-cache"] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.arm64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone Volume Cache" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/arm64/drone-volume-cache /bin/ 9 | ENTRYPOINT ["/bin/drone-volume-cache"] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.1809: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-1809-amd64@sha256:a5493cfd5ef8326296121233e392437ca535dcf8097f15edafd727fcf2d43ed6 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone Volume Cache" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-volume-cache.exe c:/drone-volume-cache.exe 10 | ENTRYPOINT [ "c:\\drone-volume-cache.exe" ] 11 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.ltsc2022: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-1809-amd64@sha256:a5493cfd5ef8326296121233e392437ca535dcf8097f15edafd727fcf2d43ed6 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone Volume Cache" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-volume-cache.exe c:/drone-volume-cache.exe 10 | ENTRYPOINT [ "c:\\drone-volume-cache.exe" ] 11 | -------------------------------------------------------------------------------- /docker/manifest.tmpl: -------------------------------------------------------------------------------- 1 | image: plugins/volume-cache:{{#if build.tag}}{{trimPrefix build.tag "v"}}{{else}}latest{{/if}} 2 | {{#if build.tags}} 3 | tags: 4 | {{#each build.tags}} 5 | - {{this}} 6 | {{/each}} 7 | {{/if}} 8 | manifests: 9 | - 10 | image: plugins/volume-cache:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-amd64 11 | platform: 12 | architecture: amd64 13 | os: linux 14 | - 15 | image: plugins/volume-cache:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}linux-arm64 16 | platform: 17 | architecture: arm64 18 | os: linux 19 | variant: v8 20 | - 21 | image: plugins/volume-cache:{{#if build.tag}}{{trimPrefix build.tag "v"}}-{{/if}}windows-1809-amd64 22 | platform: 23 | architecture: amd64 24 | os: windows 25 | version: 1809 26 | - image: plugins/volume-cache:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 27 | platform: 28 | architecture: amd64 29 | os: windows 30 | version: ltsc2022 31 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/drone-plugins/drone-volume-cache 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/drone/drone-cache-lib v0.0.0-20200806063744-981868645a25 7 | github.com/replicon/fast-archiver v0.0.0-20121220195659-060bf9adec25 8 | github.com/sirupsen/logrus v1.9.3 9 | github.com/urfave/cli v1.22.14 10 | ) 11 | 12 | require ( 13 | github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect 14 | github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf // indirect 15 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 16 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 17 | github.com/stretchr/testify v1.8.4 // indirect 18 | golang.org/x/sys v0.3.0 // indirect 19 | ) 20 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 3 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= 4 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 5 | github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= 6 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 9 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/franela/goblin v0.0.0-20181003173013-ead4ad1d2727/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= 13 | github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf h1:NrF81UtW8gG2LBGkXFQFqlfNnvMt9WdB46sfdJY4oqc= 14 | github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf/go.mod h1:VzmDKDJVZI3aJmnRI9VjAn9nJ8qPPsN1fqzr9dqInIo= 15 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 16 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 17 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 18 | github.com/replicon/fast-archiver v0.0.0-20121220195659-060bf9adec25 h1:aq3XSz9htmdvrxpK6eBIbjs3SaN8G1D9RuKkDo4PRnw= 19 | github.com/replicon/fast-archiver v0.0.0-20121220195659-060bf9adec25/go.mod h1:R9DTtFe2IYmHTz+jzYtQmqqltTKfdZCqx4NgPIEg6oY= 20 | github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= 21 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 22 | github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 23 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 24 | github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= 25 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 26 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 27 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 28 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 29 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 30 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 31 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 32 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 33 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 34 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 35 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 36 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 37 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 38 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 39 | github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= 40 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 41 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 42 | github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk= 43 | github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 44 | github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= 45 | github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= 46 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 47 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 48 | golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= 49 | golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 50 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 51 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 52 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 53 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 54 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 55 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 56 | -------------------------------------------------------------------------------- /local.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "io" 5 | "os" 6 | "path/filepath" 7 | 8 | "github.com/drone/drone-cache-lib/storage" 9 | ) 10 | 11 | type localCache struct { 12 | } 13 | 14 | func (s *localCache) Get(path string, dst io.Writer) error { 15 | src, err := os.Open(path) 16 | if err != nil { 17 | return err 18 | } 19 | defer src.Close() 20 | _, err = io.Copy(dst, src) 21 | return err 22 | } 23 | 24 | func (s *localCache) Put(path string, src io.Reader) error { 25 | dst, err := os.Create(path) 26 | if err != nil { 27 | return err 28 | } 29 | defer dst.Close() 30 | _, err = io.Copy(dst, src) 31 | return err 32 | } 33 | 34 | func (s *localCache) List(path string) ([]storage.FileEntry, error) { 35 | var files []storage.FileEntry 36 | walker := func(path string, info os.FileInfo, err error) error { 37 | if !info.IsDir() { 38 | files = append(files, storage.FileEntry{ 39 | Path: path, 40 | Size: info.Size(), 41 | LastModified: info.ModTime(), 42 | }) 43 | } 44 | return nil 45 | } 46 | _ = filepath.Walk(path, walker) 47 | return files, nil 48 | } 49 | 50 | func (s *localCache) Delete(path string) error { 51 | return os.Remove(path) 52 | } 53 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | "time" 8 | 9 | "github.com/sirupsen/logrus" 10 | "github.com/urfave/cli" 11 | ) 12 | 13 | var ( 14 | version = "0.0.0" 15 | build = "0" 16 | ) 17 | 18 | func main() { 19 | app := cli.NewApp() 20 | app.Name = "volume cache plugin" 21 | app.Usage = "volume cache plugin" 22 | app.Action = run 23 | app.Version = fmt.Sprintf("%s+%s", version, build) 24 | app.Flags = []cli.Flag{ 25 | cli.StringFlag{ 26 | Name: "path", 27 | Usage: "path", 28 | Value: "/cache", 29 | EnvVar: "PLUGIN_PATH", 30 | }, 31 | cli.StringFlag{ 32 | Name: "file", 33 | Usage: "file", 34 | EnvVar: "PLUGIN_FILE", 35 | }, 36 | cli.StringFlag{ 37 | Name: "fallback-to", 38 | Usage: "fallback-to", 39 | EnvVar: "PLUGIN_FALLBACK_TO", 40 | }, 41 | cli.StringSliceFlag{ 42 | Name: "mount", 43 | Usage: "cache directories", 44 | EnvVar: "PLUGIN_MOUNT", 45 | }, 46 | cli.BoolFlag{ 47 | Name: "rebuild", 48 | Usage: "rebuild the cache directories", 49 | EnvVar: "PLUGIN_REBUILD", 50 | }, 51 | cli.BoolFlag{ 52 | Name: "restore", 53 | Usage: "restore the cache directories", 54 | EnvVar: "PLUGIN_RESTORE", 55 | }, 56 | cli.BoolFlag{ 57 | Name: "flush", 58 | Usage: "flush the cache directories", 59 | EnvVar: "PLUGIN_FLUSH", 60 | }, 61 | cli.IntFlag{ 62 | Name: "ttl", 63 | Usage: "cache ttl in days", 64 | Value: 30, 65 | EnvVar: "PLUGIN_TTL", 66 | }, 67 | cli.BoolFlag{ 68 | Name: "debug", 69 | Usage: "debug plugin output", 70 | EnvVar: "PLUGIN_DEBUG", 71 | }, 72 | cli.StringFlag{ 73 | Name: "repo-owner", 74 | Usage: "repository owner", 75 | EnvVar: "DRONE_REPO_OWNER", 76 | }, 77 | cli.StringFlag{ 78 | Name: "repo-name", 79 | Usage: "repository name", 80 | EnvVar: "DRONE_REPO_NAME", 81 | }, 82 | cli.StringFlag{ 83 | Name: "commit-branch", 84 | Value: "master", 85 | Usage: "git commit branch", 86 | EnvVar: "DRONE_COMMIT_BRANCH", 87 | }, 88 | } 89 | 90 | if err := app.Run(os.Args); err != nil { 91 | logrus.Fatal(err) 92 | } 93 | } 94 | 95 | func run(c *cli.Context) error { 96 | if c.Bool("debug") { 97 | logrus.SetLevel(logrus.DebugLevel) 98 | } 99 | 100 | p := &plugin{ 101 | mount: c.StringSlice("mount"), 102 | path: c.String("path"), 103 | file: c.String("file"), 104 | fallback: c.String("fallback-to"), 105 | rebuild: c.Bool("rebuild"), 106 | restore: c.Bool("restore"), 107 | flush: c.Bool("flush"), 108 | ttl: time.Duration(c.Int("ttl")) * 24 * time.Hour, 109 | storage: &localCache{}, 110 | } 111 | 112 | if p.file == "" { 113 | p.file = path.Join( 114 | c.String("repo-owner"), 115 | c.String("repo-name"), 116 | c.String("commit-branch")+".tar", 117 | ) 118 | } 119 | 120 | if p.fallback == "" { 121 | p.fallback = path.Join( 122 | c.String("repo-owner"), 123 | c.String("repo-name"), 124 | c.String("commit-branch")+".tar", 125 | ) 126 | } 127 | 128 | if !path.IsAbs(p.file) { 129 | p.file = path.Join(p.path, p.file) 130 | } 131 | 132 | if !path.IsAbs(p.fallback) { 133 | p.fallback = path.Join(p.path, p.fallback) 134 | } 135 | 136 | return p.Exec() 137 | } 138 | -------------------------------------------------------------------------------- /plugin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "time" 7 | 8 | "github.com/drone/drone-cache-lib/archive/tar" 9 | "github.com/drone/drone-cache-lib/cache" 10 | "github.com/drone/drone-cache-lib/storage" 11 | "github.com/sirupsen/logrus" 12 | ) 13 | 14 | type plugin struct { 15 | mount []string 16 | path string 17 | file string 18 | fallback string 19 | rebuild bool 20 | restore bool 21 | flush bool 22 | ttl time.Duration 23 | 24 | storage storage.Storage 25 | } 26 | 27 | // Exec runs the plugin 28 | func (p *plugin) Exec() error { 29 | encoder := tar.New() 30 | cacher := cache.New(p.storage, encoder) 31 | 32 | if p.rebuild { 33 | dir, _ := filepath.Split(p.file) 34 | _ = os.MkdirAll(dir, 0700) 35 | 36 | logrus.Infof("Rebuilding cache at %s", p.file) 37 | if err := cacher.Rebuild(p.mount, p.file); err == nil { 38 | logrus.Infof("Cache rebuilt") 39 | } else { 40 | logrus.Warnf("Error rebuilding cache. %s", err) 41 | } 42 | } 43 | 44 | if p.restore { 45 | logrus.Infof("Restoring cache from %s", p.file) 46 | if err := cacher.Restore(p.file, p.fallback); err == nil { 47 | logrus.Info("Cache restored") 48 | } else { 49 | logrus.Warningf("Error restoring cache %v", err) 50 | _ = p.storage.Delete(p.file) 51 | _ = p.storage.Delete(p.fallback) 52 | } 53 | } 54 | 55 | if p.flush && p.ttl > 0 { 56 | logrus.Infof("Purging cached items older then %v", p.ttl) 57 | flusher := cache.NewFlusher(p.storage, testExpired(p.ttl)) 58 | if ferr := flusher.Flush(p.path); ferr != nil { 59 | logrus.Warnf("Error purging cache. %s", ferr) 60 | } 61 | } 62 | 63 | return nil 64 | } 65 | 66 | // Check if older then x days (default 30 days) 67 | func testExpired(ttl time.Duration) cache.DirtyFunc { 68 | return func(file storage.FileEntry) bool { 69 | return file.LastModified.Before(time.Now().Add(-ttl)) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "docker": { 6 | "fileMatch": [ 7 | "/docker/Dockerfile" 8 | ] 9 | }, 10 | "labels": [ 11 | "renovate" 12 | ] 13 | } 14 | --------------------------------------------------------------------------------