Skip to content

kohii/s3-gradle-build-cache-plugin

Repository files navigation

s3-gradle-build-cache-plugin

Apache License 2.0 Build Status

A Gradle build cache that uses AWS S3 to store build artifacts.

Compatibility

Plugin made with gradle 5.2.1 so should work for Gradle 5.x. Might work with gradle version 4.x but haven't tested.

Usage

Please note that this plugin is not yet ready for production.

Apply plugin

settings.gradle

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.github.kohii.s3-gradle-build-cache-plugin:0.1.0"
  }
}

apply plugin: 'com.github.kohii.s3-gradle-build-cache-plugin'

ext.isCiServer = System.getenv().containsKey("CI")
 
buildCache {
  local {
    enabled = !isCiServer
  }
  remote(com.github.kohii.gradle.build_cache.s3.S3BuildCache) {
    region = '<your region>'
    bucket = '<your bucket name>'
    push = isCiServer
  }
}

Configuration

Configuration Key Type Description Mandatory Default Value
awsAccessKeyId String The AWS access key id Using the Default Credential Provider Chain
awsSecretKey String The AWS secret access key Using the Default Credential Provider Chain
sessionToken String The AWS sessionToken Using the Default Credential Provider Chain
region String The AWS region yes
bucket String The name of the AWS S3 bucket where cache objects should be stored. yes
prefix String The prefix of the AWS S3 object key in the bucket
endpoint String The S3 endpoint
reducedRedundancyStorage boolean Whether to use Reduced Redundancy Storage or not true

AWS credentials

By default, this plugin uses Default Credential Provider Chain to lookup the AWS credentials.
See Using the Default Credential Provider Chain - AWS SDK for Java for more details.

If you want to set access key id and secret access key manually, configure awsAccessKeyId and awsSecretKey (and sessionToken optionally).

S3 Bucket Policy

The AWS credential must have at least the following permissions to the bucket:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
          "s3:PutObject",
          "s3:GetObject",
          "s3:ListBucket"
      ],
      "Resource": [
          "arn:aws:s3:::your-bucket/*",
          "arn:aws:s3:::your-bucket"
      ]
    }
  ]
}

Run build with build cache

The Gradle build cache is an incubating feature and needs to be enabled per build (--build-cache) or in the Gradle properties (org.gradle.caching=true). See the official doc for details.

License

LICENSE

About

A Gradle build cache that uses AWS S3 to store build artifacts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages