forked from classmethod/gradle-aws-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
executable file
·130 lines (109 loc) · 3.53 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// -*- coding: utf-8; mode: groovy -*-
buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE"
classpath "jp.classmethod.aws:gradle-aws-plugin:0.+"
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: "jp.classmethod.aws.s3"
apply plugin: "jp.classmethod.aws.cloudformation"
// ==== Project settings
group = 'jp.classmethod.aws.gradle.sample'
version = '0.1-SNAPSHOT'
ext.artifactId = '06-cloudformation'
ext.timestamp = new Date().format("yyyyMMdd'_'HHmmss", TimeZone.default)
ext.versionDesc = "${version}-${timestamp}"
ext.defaultEncoding = 'UTF-8'
sourceCompatibility = targetCompatibility = 1.8
tasks.withType(AbstractCompile) each {
it.options.encoding = ext.defaultEncoding
}
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/release' }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.apache.tomcat.embed:tomcat-embed-jasper"
compile "javax.servlet:jstl"
}
// ==== AWS settings
aws {
profileName = "default"
region = "ap-northeast-1"
}
cloudFormation {
final String STACK_PARAMS_PREFIX = 'barista.aws.cfn.stackParams.'
templateFile project.file('src/main/cloudformation/06-cloudformation.template')
templateBucket "cf-templates-1r72h3gknbax2-${aws.region}"
templateKeyPrefix "06-cloudformation"
stackName "gradlecfn"
conventionMapping.stackParams = {
def stackParams
def stack = cloudFormation.getStack()
if (stack.isPresent()) {
// existing parameter values
stackParams = cloudFormation.toMap(stack.get().parameters)
} else {
assert project.uploadBundle.didWork
// default values
stackParams = [
KeyName: "sample-key",
EnvironmentType: "development"
]
}
if (project.uploadBundle.didWork) {
stackParams["AppVersionLabel"] = project.uploadBundle.versionDesc
}
return stackParams
}
capabilityIam true
}
//==== Other tasks
task createDockerfile(type: Copy, dependsOn: jar) {
from "src/main/bundle/Dockerfile"
into "build/bundle"
expand(jarFilename: jar.archiveName, artifactId: project.artifactId)
}
task createBundleResources(type: Copy) {
from "src/main/bundle"
into "build/bundle"
exclude "src/main/bundle/Dockerfile"
}
task createBundle(type: Zip, dependsOn: [createDockerfile, createBundleResources, bootRepackage]) {
archiveName = jar.archiveName.substring(0, jar.archiveName.length() - 4) + ".zip"
from "build/bundle"
from jar.archivePath
}
task uploadBundle(type: jp.classmethod.aws.gradle.s3.AmazonS3FileUploadTask, dependsOn: createBundle) {
group "AWS"
description "Upload ${artifactId} application bundle file to S3."
ext.versionDesc = "${version}-${timestamp}"
bucketName "elasticbeanstalk-${aws.region}-${aws.accountId}"
key "eb-apps/${artifactId}/${artifactId}-${versionDesc}.zip"
file project.createBundle.archivePath
overwrite project.version.endsWith("-SNAPSHOT")
}
task awsFullDeploy(dependsOn: [
uploadBundle,
awsCfnUploadTemplate,
awsCfnMigrateStackAndWaitCompleted
]) {
group 'AWS'
description 'Deploys full-stack ${artifactId} environment to AWS'
}
task awsFullUndeploy(dependsOn: awsCfnDeleteStackAndWaitCompleted) {
group 'AWS'
description 'Undeploys full-stack ${artifactId} environment on AWS'
}
awsCfnMigrateStack.mustRunAfter uploadBundle
awsCfnMigrateStack.dependsOn awsCfnUploadTemplate
awsCfnWaitStackComplete.loopTimeout = 10800 // = 3hr
awsCfnWaitStackDeleted.loopTimeout = 10800 // = 3hr