Code Monkey home page Code Monkey logo

meltwater / drone-cache Goto Github PK

View Code? Open in Web Editor NEW
335.0 99.0 81.0 1000 KB

A Drone plugin for caching current workspace files between builds to reduce your build times

Home Page: https://underthehood.meltwater.com/blog/2019/04/10/making-drone-builds-10-times-faster/

License: Apache License 2.0

Makefile 3.67% Go 95.12% Dockerfile 1.21%
drone golang droneio aws drone-plugin team-a-team lifecycle-active purpose-library usage-public automation-drone

drone-cache's Introduction

drone-cache

Latest Release Maintenance GitHub drone release snapshot

Go Doc Go Code reference CII Best Practices Go Report Card codebeat badge

meltwater/drone-cache on DockerHub DockerHub Pulls

A Drone plugin for caching current workspace files between builds to reduce your build times. drone-cache is a small CLI program, written in Go without any external OS dependencies (such as tar, etc).

With drone-cache, you can provide your own cache key templates, specify archive format (tar, tar.gz, etc) and you can use popular object storage as storage for your cached files, even better you can implement your custom storage backend to cover your use case.

For detailed usage information and a list of available options please take a look at usage and examples. If you want to learn more about custom cache keys, see cache key templates.

If you want to learn more about the story behind drone-cache, you can read our blogpost Making Drone Builds 10 Times Faster!!

Supported Storage Backends

How does it work

drone-cache stores mounted directories and files under a key at the specified backend (by default S3).

Use this plugin to cache data that makes your builds faster. In the case of a cache miss or an empty cache restore it will fail silently in won't break your running pipeline.

The best example would be to use this with your package managers such as Mix, Bundler or Maven. After your initial download, you can build a cache and then you can restore that cache in your next build.

With restored dependencies from a cache, commands like mix deps.get will only need to download new dependencies, rather than re-download every package on each build.

Example Usage of drone-cache

The following example configuration file (.drone.yml) shows the most common use of drone-cache.

Simple (with AWS S3 backend)

kind: pipeline
name: default

steps:
  - name: restore-cache
    image: meltwater/drone-cache
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: aws_access_key_id
      AWS_SECRET_ACCESS_KEY:
        from_secret: aws_secret_access_key
    pull: true
    settings:
      restore: true
      cache_key: '{{ .Commit.Branch }}-{{ checksum "go.mod" }}' # default if ommitted is {{ .Commit.Branch }}
      bucket: drone-cache-bucket
      region: eu-west-1
      mount:
        - 'vendor'

  - name: build
    image: golang:1.18.4
    pull: true
    commands:
      - make drone-cache

  - name: rebuild-cache
    image: meltwater/drone-cache
    pull: true
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: aws_access_key_id
      AWS_SECRET_ACCESS_KEY:
        from_secret: aws_secret_access_key
    settings:
      rebuild: true
      cache_key: '{{ .Commit.Branch }}-{{ checksum "go.mod" }}' # default if ommitted is {{ .Commit.Branch }}
      bucket: drone-cache-bucket
      region: eu-west-1
      mount:
        - 'vendor'

More Examples

Usage

Using executable (with CLI args)

NAME:
   Drone cache plugin - Drone cache plugin

USAGE:
   drone-cache [global options] command [command options] [arguments...]

VERSION:
   v1.4.0

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --access-key value                    AWS access key [$PLUGIN_ACCESS_KEY, $AWS_ACCESS_KEY_ID, $CACHE_AWS_ACCESS_KEY_ID]
   --acl value                           upload files with acl (private, public-read, ...) (default: "private") [$PLUGIN_ACL, $AWS_ACL]
   --alibaba.access-key value            AlibabaOSS access key [$PLUGIN_ALIBABA_ACCESS_KEY, $ALIBABA_ACCESS_KEY_ID, $CACHE_ALIBABA_ACCESS_KEY_ID]
   --alibaba.secret-key value            AlibabaOSS access secret [$PLUGIN_ALIBABA_ACCESS_SECRET, $ALIBABA_ACCESS_SECRET, $CACHE_ALIBABA_ACCESS_SECRET]
   --archive-format value                archive format to use to store the cache directories (tar, gzip, zstd) (default: "tar") [$PLUGIN_ARCHIVE_FORMAT]
   --azure.account-key value             Azure Blob Storage Account Key [$PLUGIN_ACCOUNT_KEY, $AZURE_ACCOUNT_KEY]
   --azure.account-name value            Azure Blob Storage Account Name [$PLUGIN_ACCOUNT_NAME, $AZURE_ACCOUNT_NAME]
   --azure.blob-container-name value     Azure Blob Storage container name [$PLUGIN_CONTAINER, $AZURE_CONTAINER_NAME]
   --azure.blob-max-retry-requets value  Azure Blob Storage Max Retry Requests (default: 4) [$AZURE_BLOB_MAX_RETRY_REQUESTS]
   --azure.blob-storage-url value        Azure Blob Storage URL (default: "blob.core.windows.net") [$AZURE_BLOB_STORAGE_URL]
   --backend value                       cache backend to use in plugin (s3, filesystem, sftp, azure, gcs) (default: "s3") [$PLUGIN_BACKEND]
   --backend.operation-timeout value     timeout value to use for each storage operations (default: 3m0s) [$PLUGIN_BACKEND_OPERATION_TIMEOUT, $BACKEND_OPERATION_TIMEOUT]
   --bucket value                        AWS bucket name [$PLUGIN_BUCKET, $S3_BUCKET, $GCS_BUCKET]
   --build.created value                 build created (default: 0) [$DRONE_BUILD_CREATED]
   --build.deploy value                  build deployment target [$DRONE_DEPLOY_TO]
   --build.event value                   build event (default: "push") [$DRONE_BUILD_EVENT]
   --build.finished value                build finished (default: 0) [$DRONE_BUILD_FINISHED]
   --build.link value                    build link [$DRONE_BUILD_LINK]
   --build.number value                  build number (default: 0) [$DRONE_BUILD_NUMBER]
   --build.started value                 build started (default: 0) [$DRONE_BUILD_STARTED]
   --build.status value                  build status (default: "success") [$DRONE_BUILD_STATUS]
   --cache-key value                     cache key to use for the cache directories [$PLUGIN_CACHE_KEY]
   --commit.author.avatar value          git author avatar [$DRONE_COMMIT_AUTHOR_AVATAR]
   --commit.author.email value           git author email [$DRONE_COMMIT_AUTHOR_EMAIL]
   --commit.author.name value            git author name [$DRONE_COMMIT_AUTHOR]
   --commit.branch value                 git commit branch (default: "master") [$DRONE_COMMIT_BRANCH]
   --commit.link value                   git commit link [$DRONE_COMMIT_LINK]
   --commit.message value                git commit message [$DRONE_COMMIT_MESSAGE]
   --commit.ref value                    git commit ref (default: "refs/heads/master") [$DRONE_COMMIT_REF]
   --commit.sha value                    git commit sha [$DRONE_COMMIT_SHA]
   --compression-level value             compression level to use for gzip/zstd compression when archive-format specified as gzip/zstd
                                             (check https://godoc.org/compress/flate#pkg-constants for available options for gzip
                                             and https://pkg.go.dev/github.com/klauspost/compress/zstd#EncoderLevelFromZstd for zstd) (default: -1) [$PLUGIN_COMPRESSION_LEVEL]
   --debug                               debug (default: false) [$PLUGIN_DEBUG, $DEBUG]
   --encryption value                    server-side encryption algorithm, defaults to none. (AES256, aws:kms) [$PLUGIN_ENCRYPTION, $AWS_ENCRYPTION]
   --endpoint value                      endpoint for the s3/cloud storage connection [$PLUGIN_ENDPOINT, $S3_ENDPOINT, $GCS_ENDPOINT]
   --filesystem.cache-root value         local filesystem root directory for the filesystem cache (default: "/tmp/cache") [$PLUGIN_FILESYSTEM_CACHE_ROOT, $FILESYSTEM_CACHE_ROOT]
   --gcs.acl value                       upload files with acl (private, public-read, ...) (default: "private") [$PLUGIN_GCS_ACL, $GCS_ACL]
   --gcs.api-key value                   Google service account API key [$PLUGIN_API_KEY, $GCP_API_KEY]
   --gcs.encryption-key value            server-side encryption key, must be a 32-byte AES-256 key, defaults to none
                                             (See https://cloud.google.com/storage/docs/encryption for details.) [$PLUGIN_GCS_ENCRYPTION_KEY, $GCS_ENCRYPTION_KEY]
   --gcs.json-key value                  Google service account JSON key [$PLUGIN_JSON_KEY, $GCS_CACHE_JSON_KEY]
   --help, -h                            show help (default: false)
   --local-root value                    local root directory to base given mount paths (default pwd [present working directory]) [$PLUGIN_LOCAL_ROOT]
   --log.format value                    log format to use. ('logfmt', 'json') (default: "logfmt") [$PLUGIN_LOG_FORMAT, $LOG_FORMAT]
   --log.level value                     log filtering level. ('error', 'warn', 'info', 'debug') (default: "info") [$PLUGIN_LOG_LEVEL, $LOG_LEVEL]
   --mount value                         cache directories, an array of folders to cache  (accepts multiple inputs) [$PLUGIN_MOUNT]
   --override                            override even if cache key already exists in backend (default: true) [$PLUGIN_OVERRIDE]
   --path-style                          AWS path style to use for bucket paths. (true for minio, false for aws) (default: false) [$PLUGIN_PATH_STYLE, $AWS_PLUGIN_PATH_STYLE]
   --prev.build.number value             previous build number (default: 0) [$DRONE_PREV_BUILD_NUMBER]
   --prev.build.status value             previous build status [$DRONE_PREV_BUILD_STATUS]
   --prev.commit.sha value               previous build sha [$DRONE_PREV_COMMIT_SHA]
   --rebuild                             rebuild the cache directories (default: false) [$PLUGIN_REBUILD]
   --region value                        AWS bucket region. (us-east-1, eu-west-1, ...) [$PLUGIN_REGION, $S3_REGION]
   --remote-root value                   remote root directory to contain all the cache files created (default repo.name) [$PLUGIN_REMOTE_ROOT]
   --remote.url value                    git remote url [$DRONE_REMOTE_URL]
   --repo.avatar value                   repository avatar [$DRONE_REPO_AVATAR]
   --repo.branch value                   repository default branch [$DRONE_REPO_BRANCH]
   --repo.fullname value                 repository full name [$DRONE_REPO]
   --repo.link value                     repository link [$DRONE_REPO_LINK]
   --repo.name value                     repository name [$DRONE_REPO_NAME]
   --repo.namespace value                repository namespace [$DRONE_REPO_NAMESPACE]
   --repo.owner value                    repository owner (for Drone version < 1.0) [$DRONE_REPO_OWNER]
   --repo.private                        repository is private (default: false) [$DRONE_REPO_PRIVATE]
   --repo.trusted                        repository is trusted (default: false) [$DRONE_REPO_TRUSTED]
   --restore                             restore the cache directories (default: false) [$PLUGIN_RESTORE]
   --role-arn value                      AWS IAM role ARN to assume [$PLUGIN_ASSUME_ROLE_ARN, $AWS_ASSUME_ROLE_ARN]
   --s3-bucket-public value              Set to use anonymous credentials with public S3 bucket [$PLUGIN_S3_BUCKET_PUBLIC, $S3_BUCKET_PUBLIC]
   --secret-key value                    AWS secret key [$PLUGIN_SECRET_KEY, $AWS_SECRET_ACCESS_KEY, $CACHE_AWS_SECRET_ACCESS_KEY]
   --sftp.auth-method value              sftp auth method, defaults to none. (PASSWORD, PUBLIC_KEY_FILE) [$SFTP_AUTH_METHOD]
   --sftp.cache-root value               sftp root directory [$SFTP_CACHE_ROOT]
   --sftp.host value                     sftp host [$SFTP_HOST]
   --sftp.password value                 sftp password [$PLUGIN_PASSWORD, $SFTP_PASSWORD]
   --sftp.port value                     sftp port [$SFTP_PORT]
   --sftp.public-key-file value          sftp public key file path [$PLUGIN_PUBLIC_KEY_FILE, $SFTP_PUBLIC_KEY_FILE]
   --sftp.username value                 sftp username [$PLUGIN_USERNAME, $SFTP_USERNAME]
   --skip-symlinks                       skip symbolic links in archive (default: false) [$PLUGIN_SKIP_SYMLINKS, $SKIP_SYMLINKS]
   --sts-endpoint value                  Custom STS endpoint for IAM role assumption [$PLUGIN_STS_ENDPOINT, $AWS_STS_ENDPOINT]
   --version, -v                         print the version (default: false)
   --yaml.signed                         build yaml is signed (default: false) [$DRONE_YAML_SIGNED]
   --yaml.verified                       build yaml is verified (default: false) [$DRONE_YAML_VERIFIED]

Using Docker (with Environment variables)

$ docker run --rm \
      -v "$(pwd)":/app \
      -e DRONE_REPO=octocat/hello-world \
      -e DRONE_REPO_BRANCH=master \
      -e DRONE_COMMIT_BRANCH=master \
      -e PLUGIN_MOUNT=/app/node_modules \
      -e PLUGIN_RESTORE=false \
      -e PLUGIN_REBUILD=true \
      -e PLUGIN_BUCKET=<bucket> \
      -e AWS_ACCESS_KEY_ID=<token> \
      -e AWS_SECRET_ACCESS_KEY=<secret> \
      meltwater/drone-cache

Development

Usage:
  make <target>

Targets:
  setup          	  Setups dev environment
  drone-cache    	  Runs drone-cache target
  clean          	  Cleans build resourcess
  docs           	  Generates docs
  generate       	  Generate documentation, website and yaml files,
  vendor         	  Updates vendored copy of dependencies
  compress       	  Creates compressed binary
  container      	  Builds drone-cache docker image with latest tag
  container-push 	  Pushes latest $(CONTAINER_REPO) image to repository
  test           	  Runs tests
  test-integration	  Runs integration tests
  test-unit      	  Runs unit tests
  lint           	  Runs golangci-lint analysis
  fix            	  Runs golangci-lint fix
  format         	  Runs gofmt
  help           	  Shows this help message

Releases

Release management handled by the CI pipeline. When you create a tag on master branch, CI handles the rest.

You can find released artifacts (binaries, code, archives) under releases.

You can find released images at DockerHub.

PLEASE DO NOT INTRODUCE BREAKING CHANGES

Keep in mind that users usually use the image tagged with latest in their pipeline, please make sure you do not interfere with their working workflow. Latest stable releases will be tagged with the latest.

Versioning

drone-cache uses SemVer for versioning. For the versions available, see the tags on this repository.

As the versioning scheme dictates, drone-cache respects backward compatibility within the major versions. However, the project only offers guarantees regarding the command-line interface (flags and environment variables). Any exported public package can change its API.

Authors and Acknowledgement

See the list of all contributors.

  • @kakkoyun - Thank you Kemal for bringing drone-cache to life, and building most of the initial version.
  • @AdamGlazerMW - Special thanks to Adam for the amazing artwork!
  • @dim - Thanks for the original work that inspired drone-cache!

Inspiration

Contributing

Please read CONTRIBUTING.md to understand how to submit pull requests to us, and also see our code of conduct.

Future work

All ideas for new features and bug reports will be kept in github.com/meltwater/drone-cache/issues.

One bigger area of future investment is to add a couple of new storage backends for caching the workspace files.

License and Copyright

This project is licensed under the Apache License 2.0.

drone-cache's People

Contributors

apoorva-marisomaradhya avatar atombender avatar bdebyl avatar cmckeen avatar cthulhuden avatar cydowens avatar dependabot[bot] avatar dim avatar foymikek avatar hacktron95 avatar hhamalai avatar hikerspath avatar hulloitskai avatar imranismail avatar jcalonso avatar kadetutu avatar kakkoyun avatar lafriks avatar mavimo avatar meltwater-ateam avatar mmaaxx500 avatar mr-cn avatar pastushenkoy avatar remen avatar salimane avatar seandtaber avatar soundmonster avatar spacentropy avatar spier avatar ste93cry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drone-cache's Issues

Add timeout option to cancel outgoing request after the given time

Is your feature request related to a problem? Please describe.
In order to prevent hanging outgoing calls to remote storages introduce a timeout logic.

Describe the solution you'd like
Add timeout CLI option to cancel outgoing request after the given time.
Use context to cancel outgoing requests.

Rename drone-cache to something more generic

drone-cache cache is not actually limited to caching workspace artifacts just for drone.

So other docker-based CI solutions can use this out of the box.

As drone-cache is just a static binary, you could even use this with other CI solutions (although we have not tried this yet).

To make it easier for users to find this tool, we would have to do some work though. e.g.

  • renaming drone-cache to something more generic
  • distributing drone-cache to other package management solutions, so that users out side of the container ecosystem would also find out about this

Symlinks are not restored or restored incorectly in latest version

When using :latest tag restored node_modules and after npm install, npm scripts using npm run xxx does work correctly.
After switching to docker tag :master-ef42beb it does fail to either restore node_modules/.bin/... folder or symlinks correctly.
I also checked the created tar file content on S3 storage and it does contain .bin folder with symlink files so I'm not really sure where it goes wrong.

NB On so not too important note, also cached tar file content seems to have changed structure between :latest and :master-ef42beb and cached tar files fails to restore with error if tar file was created with :latest but extracting is done using :master-ef42beb version (should I report that separately?). I just deleted all cached objects so that was not so big deal :)

Customize cache key with path

The final cache path is generated by joining repo name and cache key (here & here). This prevents end users to fully control the cache destination (basically the structure is somewhat fixed: /<repo_name>/).

Wonder if the user could control it freely.

Regards.

Add Alibaba OSS Storage Backend

Is your feature request related to a problem? Please describe.

As a user of the Alibaba Cloud, I want to use Alibaba OSS Storage to persist my cache, so that I can reuse the storage system that I already know.

Describe the solution you'd like
Alibaba OSS Storage Backend

Describe alternatives you've considered
using a separate storage backend that already exists in drone-cache

Additional context
none

Add ability to use checksum of a file in cache key

Let me start by congratulating on the addition of ability to create custom cache keys - #4. Very useful feature.

Something that we find very useful about the feature in CircleCI is ability to use the checksum of a file in the cache key. For ex:

{{ checksum "pom.xml" }}

For maven projects like ours, the dependency JARs are the ones that change infrequently and would be useful to cache. And these are mentioned in the pom.xml file.
Having the ability to use the checksum of this file means we don't have to update the cache on every build, but only if the checksum changes.

Add cache clear

Expected Behavior

When I add [CLEAR CACHE] to a commit, the cache is not restored. Instead it is removed so the rebuild step can generate a new one.

Actual Behavior

Directive is ignored

Steps to Reproduce the Problem

  1. Create cache
  2. Push commit with [CLEAR CACHE] directive
  3. Cache is restored normally

Specifications

  • Version: dev
  • Platform: Ubuntu 18
  • Subsystem:

According to http://plugins.drone.io/drillster/drone-volume-cache/ this is the default cache's behavior. This same API should be used and documented. I did not find information in this package about how to clear the cache.

Self-explanatory Makefile

Make Makefile self-explanatory with comment and help action to ease the use for newcomers for development.

Can't cache `bundle install`

Expected Behavior

Successfully cache the /usr/local/lib/ruby directory

Actual Behavior

[rebuild-cache-with-filesystem:1] 2019/08/20 22:40:17 [WARNING] could not build cache, process rebuild failed, could not mount </usr/local/lib/ruby>, make sure file or directory exists and readable: stat /usr/local/lib/ruby: no such file or directory

Steps to Reproduce the Problem

  1. Add The following .drone.yml and Gemfile
# .drone.yml
---
kind: pipeline
name: default

steps:
- name: restore-cache-with-filesystem
  image: meltwater/drone-cache:dev
  pull: true
  settings:
    backend: "filesystem"
    restore: true
    cache_key: "${DRONE_REPO_NAME}"
    archive_format: "gzip"
    mount:
    - '/usr/local/lib/ruby'
  volumes:
  - name: cache
    path: /tmp/cache

- name: step1
  image: ruby:2.3.1
  commands:
  - bundle install
  - cd /usr/local/lib/ruby
  - ls -al

- name: rebuild-cache-with-filesystem
  image: meltwater/drone-cache:dev
  pull: true
  settings:
    backend: "filesystem"
    rebuild: true
    cache_key: "${DRONE_REPO_NAME}"
    archive_format: "gzip"
    mount:
    - '/usr/local/lib/ruby'
  volumes:
  - name: cache
    path: /tmp/cache

volumes:
  - name: cache
    host:
      path: /tmp/cache/

# Gemfile
source 'https://rubygems.org'
ruby "2.3.1"
gem 'byebug'
gem 'colorize'
gem 'faker'
gem 'json_pure'
gem 'mysql2', '~> 0.5'
gem 'rake'
gem 'rest-client', '~> 2.0.2'
gem 'rspec', '~> 3.5.0'
gem 'rubocop'
gem 'aws-sdk-sqs', '~> 1.16.0'
gem 'sinatra', '~> 2.0.5'
  1. Run $ drone exec --trusted

Specifications

OS - Mac OS Mojave

$ drone -v
drone version 1.1.1

Thank you for the awesome plugin and help in advance πŸ˜„

Broken link in docs

Describe the bug
Broken link in docs/examples/drone-1.0.md#106 and docs/examples/drone-0.8.md#92

I will open a PR later.

The links in the README section "Supported Storage Backends" don't work

Describe the bug
The links in the README section about Supported Storage Backends are not working.
See https://github.com/meltwater/drone-cache#supported-storage-backends

To Reproduce
Steps to reproduce the behavior:

  1. Open https://github.com/meltwater/drone-cache#supported-storage-backends in your browser
  2. Click any of the links
  3. I am redirected to https://github.com/meltwater/drone-cache#

Expected behavior
The respective links open.

I don't know if these links are meant to point to internal drone-cache documentation, or docs about the respective storage engines on other websites?

Cannot upload files larger than 5GB to AWS S3 in a single PUT operation

Expected Behavior

Successfully upload files larger than 5GB (using Multipart Upload API).

Actual Behavior

[WARNING] could not build cache, process rebuild failed, could not upload: could not upload file: couldn't put the object: EntityTooLarge: Your proposed upload exceeds the maximum allowed size

Steps to Reproduce the Problem

  1. Build cache for a directory larger than 5GB

Specifications

  • Image: meltwater/drone-cache:latest
  • Drone Version: 1.3.1

Cache cannot rebuid properly when nested paths specified in mount

Describe the bug
I try cache yarn.lock file, but when it's extracted from tar it md5 checksum different. This leads to reinstall node_modules dependencies.

To Reproduce
Steps to reproduce the behavior:

  1. Check md5sum before cache and after extract.

Expected behavior
md5sum file before and after must match

Maintainer's note:

Rebuild step fails to find files when nested path given:
packages/test/node_modules

Feature request: log gzip compression ratio

Is your feature request related to a problem? Please describe.
Currently I'm investigating a slowdown in the caching steps for a build. I'm aware the data being cached has grown significantly, so I wondered how "just tar" vs tar with gzip would perform.

Turns out, tar without gzip performed worse because I was getting a whopping 80% size reduction.

Describe the solution you'd like
In the archiving (and extraction?) steps, I would like to see an additional line that prints out the gzip compression ratio achieved.

Describe alternatives you've considered
Duplicate the caching steps, modify the copy to use tar at a different cache key, compare filesizes at the backend (in my case minio's GUI).

Additional context
Example build with and without gzip.
https://drone.teamopen.dev/teamopen-dev/sourcecred-stack-lookup/79

Results in the layers:

# With gzip
.scores 72.84 MB
.sourcecred 768.31 MB

# Without gzip
.scores 535.22 MB
.sourcecred 3.61 GB

Checksum does not appear to read file contents

I have an entry similar to this in the settings for the cache-key template

cache-key:  bundle-dependencies--{{ checksum "Gemfile.lock" }}

However, no matter the contents of that file, the cache key is always:

196ca0330c1f62e2a1a047a2.....

Archive file backward compatibility

When restoring archive files created with :latest tag with :master-ef42beb version there is error when extracting archive file:

level=info name=drone-cache ts=2020-04-08T09:36:06.836811454Z caller=restorer.go:95 component=plugin component=restorer msg="extracting archived directory" remote=xxx_7f8f9564d852af06d95e5156aa50a2ed_f024307c4da35ea0c40eb17b8730c470/src/xxx/web/node_modules local=src/xxx/web/node_modules
level=error name=drone-cache ts=2020-04-08T09:36:07.372433303Z caller=main.go:581 err="[IMPORTANT] restore cache, restore failed, download from <xxx_7f8f9564d852af06d95e5156aa50a2ed_f024307c4da35ea0c40eb17b8730c470/src/xxx/web/node_modules> to <src/xxx/web/node_modules>, extract files from downloaded archive, pipe reader failed, relative name, relative path <>, base <node_modules>, Rel: can't make /go/src/src/xxx/web relative to src/xxx/web/node_modules\n"

To me it looks like previously files in archive was stored with full path?

WORKAROUND: override with rebuild or delete cached files

Not saving .bin when caching node_modules on filesystem

Expected Behavior

.bin is kept, so symlinks are not lost

Actual Behavior

.bin folder is nowhere to be found

Steps to Reproduce the Problem

  1. Create node_modules and install packages that symlink binaries into node_modules/.bin (i.e. jest)
  2. Rebuild cache
  3. Restore cache in another build
  4. Try to execute symlinked commands from restored cache

Specifications

  • Version: dev
  • Platform: Ubuntu 18
  • Subsystem:

I am not sure if this is something that can be done at the cache level, but I am putting it in here in case that someone else has the same situation as me.
After restoring cache, I am unable to run anything that npm install added on the first run. The .bin folder where all the symlinks for node_modules are stored is missing after the restore.

My guesses (wild guesses, as I haven't checked any implementation) are:

  1. Hidden folders are not being added to the archive
  2. Symlinks are not being added to the archive

My workaround was to add the final file directly. In my case I was using jest:

  • ./node_modules/jest/bin/jest.js

Cache is always rebuilding

The cache is currently always being rebuilt for meβ€”I think we should compute the cache_key in the rebuild process, and if it has changed then we rebuild.

cache_key: {{ checksum "yarn.lock" }}

That's my cache_keyβ€”if the lock file hasn't changed (hence the key is the same), there's no need to re-upload node_modules entirely.

If implemented, should also check if the cache for the given key exists. Otherwise, it's the first time we're generating it.

Thoughts?

Filesystem example is misleading

The filesystem example has the following:

volumes:
  - name: cache
    temp: {}

However, according to drone docs a temp folder is for sharing information between steps, not builds.

To circumvent this, I had to use:

volumes:
  - name: cache
    host:
      path: /var/lib/cache 

This, however, has the restriction of requiring the repository to be trusted. After doing that, everything worked as expected.

There is nothing wrong with the project functionality per se, but the examples and documentation can be improved to better explain the alternatives, and to avoid contradictions.
Other than this, everything worked smoothly. Nice plugin!

Kubernetes PVC as a Cache Volume

Hello all,

 Is there a way to mount a pvc on drone to cache files?

 I found how to set a local volume (file system) as a cache but i would like to use a kubernetes pvc to storage cache files.

Thanks!

sFTP tests in CI are flaky

Describe the bug
sFTP tests in CI are flaky. They fail time to time even though everything works fine locally. Even with drone exec.

To Reproduce

  1. Do some changes
  2. Open a PR
  3. Check if CI fails

Expected behavior
CI should be consistent.

Allow to configure skipping symbolic links

When caching node_moodules directory for node projects there are many useful links in node_modules/.bin directory.

However, I could not find a way to configure tar or gzip archiver to include symbolic links into the archive file produces by the plugin.

Missing links force you to reinstall packages which kill the idea of the cache.

CI pushes latest tagged images when ever something merged to master

Describe the bug
CI pushes latest tagged images whenever something merged to master. This wasn't the intended behaviour. It should only push latest images whenever a git tag created.

To Reproduce
Steps to reproduce the behavior:

  1. Merge or push a commit to master.
  2. Check Docker Hub to see newly created image.

Expected behavior
It should only push latest images whenever a git tag created.

Do you plan to support not only tar, but also rsync based copy

Is your feature request related to a problem? Please describe.
if cache dir contains only some big files best to use rsync to it and not use tar

Describe the solution you'd like
ability to rsync files between cache and build volume

Describe alternatives you've considered
none

Additional context
none

Support IAM Roles for Kubernetes Service Accounts (IRSA)

Is your feature request related to a problem? Please describe.
I feel it's very tedious to issue, rotate, and smuggle AWS IAM keys around different config files or into the drone-secrets service. While drone-cache currently supports using instance profile credentials when running on EC2, it doesn't support leveraging IAM Roles for Service Accounts (IRSA) credentials when running on Kubernetes, specifically on EKS.

Describe the solution you'd like
Support for IRSA should only require using a minimum version of the Go AWS SDK. Specifically, their docs mention version 1.23.13 as the minimum recommended version. Upgrading to this version, with no other code changes, should enable support for IRSA.

Describe alternatives you've considered
As far as I know, support for using credentials via sts.AssumeRoleWithWebIdentity is best accomplished by the AWS SDK's default credential management system. I haven't considered alternatives, but I do believe relying on the upstream SDK is the best solution.

Additional context
Technically, this isn't just adding support for IRSA, but for web identity IAM credentials, in general.

Here's the relevant upstream PR: aws/aws-sdk-go#2667

Add TTL to cache archives

Is your feature request related to a problem? Please describe.
As a user, I would like to set a time-to-live to archives when they are cached.

Describe the solution you'd like
Whenever an archive's TTL expires, the archive should automatically expire.

More complex rule to cache mounted files

Is your feature request related to a problem? Please describe.
I manage my C++ project 3rd-party dependencies by CMake, and it stores the 3rd-party source files in a structure like this (and seems hard to change):

.
β”œβ”€β”€ ... (my source code)
β”œβ”€β”€ cmake-build-debug
β”‚Β Β  β”œβ”€β”€ _deps
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib1-build
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib1-src
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib1-subbuild
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib2-build
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lib2-src
β”‚Β Β  β”‚Β Β  └── lib2-subbuild (or more libs)
β”‚   β”œβ”€β”€ .... (other files which we don't need to cache)

The libxxx-src is what need to cache, and libxxx-build and libxxx-subbuild is what don't need (and can't cache).

But it seems I can only cache the entire _deps directory. (If there is any way, please tell me)

Describe the solution you'd like
Maybe we can support wildcards (like *-src) to select them?

[docs] move "Future Work" section to GH issues instead

When looking at the Future Work section in the README I was wondering if we should move this to github issues instead?

When doing a quick grouping, I think that for the following feature ideas we already have issues (or could easily create new ones):

Add Azure Storage Backend
Add Google Cloud Storage Backend
Add s/FTP Backend
Add Alibaba OSS Backend
Add Microsoft Azure Storage Backend

The following look like chores/fixes/smaller features that we don't have issues for yet:

Fix goreleaser/drone/docker conflicts or remove redundancy with Drone jsonnet
Add cache key fallback list
Flush or TTL/Retention policy
Add unit tests

@kakkoyun if you hare happy for me to do so, I can create new issues for the missing ones, and then just point from the future work section to the https://github.com/meltwater/drone-cache/issues

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.