Repository navigation
Expand file tree
/
Copy pathdeploy.gradle
More file actions
225 lines (198 loc) · 5.79 KB
/
Copy pathdeploy.gradle
File metadata and controls
225 lines (198 loc) · 5.79 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
apply from: "commons.gradle"
apply from: "environments.gradle"
ext.commonDeployArtifacts = [
[
module: 'deployer',
from : "${projectDir}/deployer/build/libs/crafter-deployer.jar",
into : "/bin/crafter-deployer/"
],
[
module: 'engine',
from : "${projectDir}/engine/build/libs/crafter-engine.war",
into : "/bin/apache-tomcat/webapps/ROOT.war",
copyFile: true
],
[
module: 'cli',
from : "${projectDir}/cli/build/cli",
into : "/bin/"
]
]
ext.authoringDeployArtifacts = [
[
module: 'studio',
from : "${projectDir}/studio/build/libs/crafter-studio.war",
into : "/bin/apache-tomcat/webapps/studio.war",
copyFile: true,
]
]
ext.deliveryDeployArtifacts = [
]
ext.commonDeployPermissions = [
[
// Only applied when the cli module is part of the deployment, otherwise the file is not there yet
module : 'cli',
items : [
"/cli/bin/crafter-cli"
],
permissions: [
"+x"
]
]
]
ext.authoringDeployPermissions = [
]
ext.deliveryDeployPermissions = [
]
ext.deployBaseEnvironment = { envFolder, modules, overwriteChangedFiles ->
def syncedModules = [] as Set
// Deploy Crafter binaries into env
commonDeployArtifacts.each { item ->
def name = item.module
def from = item.from
def into = item.into
def exclude = ""
def performSync = true
if (modules.find { it == name } == null) {
performSync = false
}
if (performSync) {
if (item.copyFile) {
copyFile("${projectDir}", from, envFolder + into)
} else {
syncFolder("${projectDir}", from, envFolder + into, exclude, overwriteChangedFiles, true)
}
syncedModules << name
}
}
commonDeployPermissions.each { group ->
if (group['module'] != null && !syncedModules.contains(group['module'])) {
return
}
def command = ["chmod"]
group['permissions'].each { permission ->
command << permission
}
group['items'].each { item ->
command << "bin" + item
}
execCommand(command, envFolder)
}
// Create the CLI symlink only after its target has been synced, module deploy tasks run in
// parallel against the same env folder and would otherwise leave a dangling link behind
if (syncedModules.contains('cli')) {
execCommand(["ln", "-sf", "cli/bin/crafter-cli", "bin/crafter-cli"], envFolder)
}
}
ext.deployAuthoringEnvironment = { modules, overwriteChangedFiles ->
deployBaseEnvironment("${authoringEnvDir}", modules, overwriteChangedFiles)
// Deploy Crafter binaries into env
authoringDeployArtifacts.each { item ->
def name = item.module
def from = item.from
def into = item.into
def exclude = ""
def performSync = true
if (modules.find { it == name } == null) {
performSync = false
}
if (performSync) {
if(item.copyFile) {
copyFile("${projectDir}", from, "${authoringEnvDir}" + into)
} else {
syncFolder("${projectDir}", from, "${authoringEnvDir}" + into, exclude, overwriteChangedFiles, true)
}
}
}
authoringDeployPermissions.each { group ->
def command = ["chmod"]
group['permissions'].each { permission ->
command << permission
}
group['items'].each { item ->
command << "bin" + item
}
execCommand(command, "${authoringEnvDir}")
}
}
ext.deployDeliveryEnvironment = { modules, overwriteChangedFiles ->
deployBaseEnvironment("${deliveryEnvDir}", modules, overwriteChangedFiles)
// Deploy Crafter binaries into env
deliveryDeployArtifacts.each { item ->
def name = item.module
def from = item.from
def into = item.into
def exclude = ""
def performSync = true
if (modules.find { it == name } == null) {
performSync = false
}
if (performSync) {
if (item.copyFile) {
copyFile("${projectDir}", from, "${deliveryEnvDir}" + into)
} else {
syncFolder("${projectDir}", from, "${deliveryEnvDir}" + into, exclude, overwriteChangedFiles, true)
}
}
}
deliveryUpdatePermissions.each { group ->
def command = ["chmod"]
group['permissions'].each { permission ->
command << permission
}
group['items'].each { item ->
command << "bin" + item
}
execCommand(command, "${deliveryEnvDir}")
}
}
ext.deployEnvironment = { environment, modules, overwriteChangedFiles ->
if (environment == "authoring") {
deployAuthoringEnvironment(modules, overwriteChangedFiles)
} else if (environment == "delivery") {
deployDeliveryEnvironment(modules, overwriteChangedFiles)
} else {
logger.error("Unknown environment \"" + environment + "\"")
throw new GradleException("Unknown environment \"" + environment + "\"")
}
}
// Gradle project path -> deploy artifact module name (as used in *DeployArtifacts)
ext.deployModuleProjects = [
'deployer' : 'deployer',
'engine' : 'engine',
'cli' : 'cli',
'studio' : 'studio'
]
gradle.projectsEvaluated {
deployModuleProjects.each { projectPath, moduleName ->
def proj = rootProject.findProject(":${projectPath}")
if (proj == null) {
return
}
// Register a deploy task for each project
proj.tasks.register('deploy') {
group = 'deployment'
description = "Deploys ${moduleName} artifact(s) to the selected environment(s) (-Penv=authoring|delivery)"
dependsOn rootProject.tasks.named('buildBaseEnvs')
mustRunAfter project.tasks.named('build')
doLast {
rootProject.getEnvironments().each { environment ->
println "Deploying ${moduleName} to ${environment}"
rootProject.deployEnvironment(
environment,
[moduleName],
rootProject.overwriteChangedFiles
)
}
}
}
}
def allowedModules = (rootProject.getDeployModules() as List).toSet()
def moduleDeployTasks = deployModuleProjects
.findAll { path, name -> allowedModules.contains(name) }
.collect { path, name -> rootProject.project(path).tasks.named('deploy') }
// Make the root deploy task depend on all module deploy tasks
rootProject.tasks.named('deploy').configure {
dependsOn moduleDeployTasks
}
}