• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

tehlers/gradle-gcs-build-cache: A Gradle build cache that uses Google Cloud Stor ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

tehlers/gradle-gcs-build-cache

开源软件地址(OpenSource Url):

https://github.com/tehlers/gradle-gcs-build-cache

开源编程语言(OpenSource Language):

Kotlin 100.0%

开源软件介绍(OpenSource Introduction):

Gradle - GCSBuildCache

This Gradle plugin provides a build cache implementation that uses Google Cloud Storage to store build artifacts.

Options

The build cache takes the following options:

Option Description

credentials

JSON key file of the service account to use, otherwise GCP Application Default Credentials are used. (optional)

bucket

Name of the Google Cloud Storage bucket (required)

refreshAfterSeconds

Amount of time to wait before the timestamp of a cached artifact that is still in use will be renewed (optional)

Usage

There are multiple ways to use the Google Cloud Storage based build cache inside your projects.

As plugin in settings.gradle

settings.gradle
buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'net.idlestate:gradle-gcs-build-cache:1.1.0'
    }
}

apply plugin: 'net.idlestate.gradle-gcs-build-cache'

buildCache {
    local {
        enabled = false
    }

    remote( GCSBuildCache.class ) {
        credentials = 'my-key.json' // (optional)
        bucket = 'my-bucket'
        refreshAfterSeconds = 86400 // 24h (optional)
        enabled = true
        push = true
    }
}

Manual registration in settings.gradle

settings.gradle
buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'net.idlestate:gradle-gcs-build-cache:1.1.0'
    }
}

import net.idlestate.gradle.caching.GCSBuildCache
import net.idlestate.gradle.caching.GCSBuildCacheServiceFactory

buildCache {
    local {
        enabled = false
    }

    registerBuildCacheService( GCSBuildCache.class, GCSBuildCacheServiceFactory.class )

    remote( GCSBuildCache.class ) {
        credentials = 'my-key.json' // (optional)
        bucket = 'my-bucket'
        refreshAfterSeconds = 86400 // 24h (optional)
        enabled = true
        push = true
    }
}

Using an init script

init-build-cache.gradle
initscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'net.idlestate:gradle-gcs-build-cache:1.1.0'
    }
}

import net.idlestate.gradle.caching.GCSBuildCache
import net.idlestate.gradle.caching.GCSBuildCacheServiceFactory

gradle.settingsEvaluated { settings ->
    settings.buildCache {
        local {
            enabled = false
        }

        registerBuildCacheService( GCSBuildCache.class, GCSBuildCacheServiceFactory.class )

        remote( GCSBuildCache.class ) {
            credentials = 'my-key.json' // (optional)
            bucket = 'my-bucket'
            refreshAfterSeconds = 86400 // 24h (optional)
            enabled = true
            push = true
        }
    }
}
% ./gradlew --build-cache --init-script init-build-cache.gradle <task>

Preparation in Google Cloud Storage

The following steps will create a Google Cloud Storage bucket named $BUCKET as part of the GCP project $PROJECT in your $REGION with private access. gsutil is available as part of the Google Cloud SDK.

% gsutil mb -p $PROJECT -c regional -l $REGION gs://$BUCKET
[...]
% gsutil acl set private gs://$BUCKET
[...]

To create a service account $ACCOUNT with access to the bucket the following commands have to be executed.

% gcloud iam service-accounts create $ACCOUNT --display-name "Service account to access the Gradle build cache in Google Cloud Storage"
[...]
% gsutil acl ch -u $ACCOUNT@$PROJECT.iam.gserviceaccount.com:WRITE gs://$BUCKET
[...]

A JSON key file $KEY_FILE that could be used by the Gradle plugin to access the bucket is created with the following statement.

% gcloud iam service-accounts keys create $KEY_FILE --iam-account $ACCOUNT@$PROJECT.iam.gserviceaccount.com
[...]

If cached artifacts should be deleted after two weeks lifecycle rules like the following should be applied to the bucket.

rules.json
{
  "rule":
  [
{
  "action": {"type": "Delete"},
  "condition": {"age": 14}
}
  ]
}
% gsutil lifecycle set rules.json gs://$BUCKET
[...]

License




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap