-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathbuild.gradle
70 lines (59 loc) · 1.99 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// -*- coding: utf-8; mode: groovy -*-
import com.amazonaws.auth.policy.Policy
import com.amazonaws.auth.policy.Principal
import com.amazonaws.auth.policy.Statement
import com.amazonaws.auth.policy.actions.S3Actions
import com.amazonaws.auth.policy.resources.S3BucketResource
import com.amazonaws.auth.policy.resources.S3ObjectResource
import com.amazonaws.services.s3.model.ObjectMetadata
import jp.classmethod.aws.gradle.s3.AmazonS3FileUploadTask
import jp.classmethod.aws.gradle.s3.BucketPolicyTask
import jp.classmethod.aws.gradle.s3.CreateBucketTask
import jp.classmethod.aws.gradle.s3.DeleteBucketTask
buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "jp.classmethod.aws:gradle-aws-plugin:0.+"
}
}
apply plugin: "jp.classmethod.aws.s3"
aws {
profileName = "default"
region = "ap-northeast-1"
}
def myBucketName = 'gradle-aws-plugin-sample'
task createBucket(type: CreateBucketTask) {
bucketName myBucketName
// one of http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region values, us-east-1 by default
region regionName
ifNotExists true
}
task deleteBucket(type: DeleteBucketTask) {
bucketName myBucketName
ifExists true
deleteObjects true
}
task uploadContent(type: AmazonS3FileUploadTask, dependsOn: createBucket) {
file file("target-file.txt") // must be a file
bucketName myBucketName
key "01-s3-upload-simple.txt"
def m = new ObjectMetadata()
m.setCacheControl("no-cache, no-store")
objectMetadata = m
}
task setBucketPolicy(type: BucketPolicyTask, dependsOn: createBucket) {
bucketName myBucketName
policy new Policy().withStatements(
new Statement(Statement.Effect.Allow)
.withPrincipals(Principal.AllUsers)
.withActions(S3Actions.GetObject)
.withResources(new S3ObjectResource(myBucketName, "*")),
new Statement(Statement.Effect.Allow)
.withPrincipals(Principal.AllUsers)
.withActions(S3Actions.ListObjects)
.withResources(new S3BucketResource(myBucketName))
)
}