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

skhatri/gradle-s3-plugin: S3 File Upload and Download plugin

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

开源软件名称(OpenSource Name):

skhatri/gradle-s3-plugin

开源软件地址(OpenSource Url):

https://github.com/skhatri/gradle-s3-plugin

开源编程语言(OpenSource Language):

Groovy 71.2%

开源软件介绍(OpenSource Introduction):

Gradle S3 Plugin

This plugin can be used to download files from S3 buckets. You can upload artifacts to S3 as well. The link configuration attribute can be used to create amz-website-redirect-location based redirects. Technically this is not a symbolic link, but it can behave like one when trying to reference same file from multiple locations.

The plugin creates two tasks:

s3Upload

As the name suggests, the s3Upload task can be used to upload a local file to a bucket with a given key name.

s3Download

Similarly, the s3Download task can be used to download a given file from a chosen bucket to a local directory.

The plugin uses a ProfileCredentialsProvider strategy to figure out AWS access and secret key. The name of the credentials profile to use when connecting to AWS can be specified by the awsProfile propterty.

See com.github.skhatri.s3aws.client.S3Client for implementation.

Pull requests are welcome if you want to modify to your needs.

Plugin Configuration in your build.gradle

buildscript {
    dependencies {
        classpath 'com.github.skhatri:gradle-s3-plugin:1.0.6'
    }
    repositories {
        mavenCentral()
    }
}
apply plugin: 's3'

s3 {
    bucket = 'skhatri-bucket'
    awsProfile = 'default'
    upload {
        //"key" is the name of the target file in S3 (in this example we create a versioned file)
        key =  java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd")) +'/gradle-s3-plugin-1.0.6.jar'
        
        // "file" is the name of the local source file
        file = '../build/libs/gradle-s3-plugin-1.0.6.jar'
        
        //"link" will create http redirect to the latest uploaded version of the file
        // This will redirect is only available via the "s3 static webpage" option. 
        // walkthorugh link from AWS on how to set it up
        // https://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html
        link = 'latest/gradle-plugin.jar'
    }
    download {
        key = 'latest/gradle-plugin.jar'
        saveTo = 'gradle-pugin.jar'
    }
}


Using Upload Task to upload more artifacts

task uploadAppJar(type: com.github.skhatri.s3aws.plugin.S3UploadTask) {
    key = 'gradle-s3-plugin-1.0.0-something.jar'
    file = '../build/libs/gradle-s3-plugin-master-1.0.1-SNAPSHOT.jar'
    link = 'latest/gradle-plugin.jar'
}

Then I can call "gradle uploadAppJar" to upload yet another artifact to S3.

This can be useful, if uploading hash checksums of the artifacts. For instance, I can upload sha1 value of the artifact so my automated artifact deployment task could download checksum file first to decide whether downloading the big artifact is worth it.

task writeHash() {
    String hashValue = computeHash('../build/libs/gradle-s3-plugin-master-1.0.1-SNAPSHOT.jar')
    file('../build/libs/gradle-s3-plugin-master-1.0.1-SNAPSHOT.sha1').write(hashValue)
}

task uploadHash(type: com.github.skhatri.s3aws.plugin.S3UploadTask) {
    key = 'gradle-s3-plugin-1.0.0-something.sha1'
    file = '../build/libs/gradle-s3-plugin-master-1.0.1-SNAPSHOT.sha1'
    link = 'latest/gradle-plugin.sha1'
}

task awsUpload(dependsOn:['uploadAppJar', 'writeHash', 'uploadHash']) {
}

Now, calling awsUpload will upload jar and the hash file.

Downloading more than one artifact

Similarly, I can download more artifacts by simply creating ad-hoc Download task. I am downloading the previously uploaded sha1 file of the artifact using the task below.

task awsDownload(type: com.github.skhatri.s3aws.plugin.S3DownloadTask) {
    key = 'latest/gradle-plugin.sha1'
    saveTo = 'gradle-plugin.txt'
}



鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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