forked from nextflow-io/nextflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packing.gradle
370 lines (308 loc) · 13 KB
/
packing.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
configurations {
capsule
defaultCfg.extendsFrom api
//provided
console.extendsFrom defaultCfg
ga4gh.extendsFrom defaultCfg
google.extendsFrom defaultCfg
amazon.extendsFrom defaultCfg
azure.extendsFrom defaultCfg
legacy.extendsFrom defaultCfg
tower.extendsFrom defaultCfg
}
dependencies {
api project(':nextflow')
// include Ivy at runtime in order to have Grape @Grab work correctly
defaultCfg "org.apache.ivy:ivy:2.5.1"
// default cfg = runtime + httpfs + amazon + tower client
defaultCfg project(':nf-httpfs')
// Capsule manages the fat jar building process
capsule 'io.nextflow:capsule:1.1.1'
capsule 'io.nextflow:capsule-maven:1.0.3.2'
console project(':plugins:nf-console')
ga4gh project(':plugins:nf-ga4gh')
google project(':plugins:nf-google')
amazon project(':plugins:nf-amazon')
azure project(':plugins:nf-azure')
tower project(':plugins:nf-tower')
}
ext.mainClassName = 'nextflow.cli.Launcher'
ext.homeDir = System.properties['user.home']
ext.nextflowDir = "$homeDir/.nextflow/framework/$version"
ext.releaseDir = "$buildDir/releases"
ext.s3CmdOpts="--acl public-read --storage-class STANDARD --region eu-west-1"
protected error(String message) {
logger.error message
throw new StopExecutionException(message)
}
protected checkVersionExits(String version) {
if(version.endsWith('-SNAPSHOT'))
return
def cmd = "AWS_ACCESS_KEY_ID=${System.env.NXF_AWS_ACCESS} AWS_SECRET_ACCESS_KEY=${System.env.NXF_AWS_SECRET} aws s3 ls s3://www2.nextflow.io/releases/v$version/nextflow"
def status=['bash','-c', cmd].execute().waitFor()
if( status == 0 )
error("STOP!! Version $version already deployed!")
}
protected resolveDeps( String configName, String... x ) {
final deps = [] as Set
final config = configurations.getByName(configName)
//final root = config.getIncoming().getResolutionResult().root.moduleVersion.toString()
config.getResolvedConfiguration().getResolvedArtifacts().each{ deps << coordinates(it) }
if( x )
deps.addAll(x as List)
logger.info ">> Dependencies for configuration: $configName"
deps.sort().each { logger.info " - $it" }
// make sure there aren't any version conflict
def conflicts = deps.countBy { it.tokenize(":")[0..1].join(':') }.findAll { k,v -> v>1 }
if( conflicts ) {
def err = "There are multiple versions for the following lib(s):"
conflicts.each { name, count -> err += "\n- $name: " + deps.findAll{ it.startsWith(name) }.collect{ it.tokenize(':')[2] } }
throw new IllegalStateException(err)
}
//println "** $configName\n${deps.sort().collect{"- $it"}.join('\n')}\n"
//println ">> Config: $configName \n${deps.sort().join('\n')}\n\n"
return deps.collect{ "$it(*:*)" }.join(' ')
}
protected coordinates( it ) {
if( it instanceof Dependency )
return "${it.group}:${it.name}:${it.version}".toString()
if( it instanceof ResolvedArtifact ) {
def result = it.moduleVersion.id.toString()
if( it.classifier ) result += ":${it.classifier}"
return result
}
throw new IllegalArgumentException("Not a valid dependency object [${it?.class?.name}]: $it")
}
/*
* Default nextflow package. It contains the capsule loader
*/
task packOne(type: Jar) {
dependsOn configurations.capsule, configurations.defaultCfg
archiveName = "nextflow-${version}-one.jar"
from (configurations.capsule.collect { zipTree(it) })
// main manifest attributes
def deps = resolveDeps('defaultCfg')
manifest.attributes(
'Main-Class' : 'NextflowLoader',
'Application-Name' : 'nextflow',
'Application-Class' : mainClassName,
'Application-Version': version,
'Min-Java-Version' : '1.8.0',
'Caplets' : 'MavenCapsule',
'Dependencies' : deps
)
// enable snapshot dependencies lookup
if( version.endsWith('-SNAPSHOT') ) {
manifest.attributes 'Allow-Snapshots': true
manifest.attributes 'Repositories': 'local https://oss.sonatype.org/content/repositories/snapshots central seqera'
}
else {
manifest.attributes 'Repositories': 'central seqera'
}
doLast {
ant.copy(file: "$buildDir/libs/nextflow-${version}-one.jar", todir: releaseDir, overwrite: true)
ant.copy(file: "$buildDir/libs/nextflow-${version}-one.jar", todir: nextflowDir, overwrite: true)
println "\n+ Nextflow package `ONE` copied to: $releaseDir"
}
}
task packAll(type: Jar) {
dependsOn configurations.capsule, configurations.defaultCfg
archiveName = "nextflow-${version}-all.jar"
from jar // embed our application jar
from (configurations.amazon + configurations.google + configurations.tower)
from (configurations.capsule.collect { zipTree(it) })
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest.attributes( 'Main-Class' : 'NextflowLoader',
'Application-Name' : 'nextflow-all',
'Application-Class' : mainClassName,
'Application-Version': version,
'Min-Java-Version' : '1.8.0'
)
manifest.attributes('Main-Class': 'NextflowLoader', 'amazon')
manifest.attributes('Main-Class': 'NextflowLoader', 'google')
if( project.hasProperty('GA4GH') ) {
println "The build will include GA4GH dependencies."
from(configurations.ga4gh)
manifest.attributes('Main-Class': 'CapsuleLoader', 'ga4gh')
}
doLast {
file(releaseDir).mkdir()
// cleanup
def source = file("$buildDir/libs/nextflow-${version}-all.jar")
def target = file("$releaseDir/nextflow-${version}-all"); target.delete()
// append the big jar
target.withOutputStream {
it << file('nextflow').text.replaceAll(/NXF_PACK\=.*/, 'NXF_PACK=all')
it << new FileInputStream(source)
}
// execute permission
"chmod +x $target".execute()
// done
println "+ Nextflow package `ALL` copied to: $releaseDir\n"
}
}
task packCore(type: Jar) {
dependsOn configurations.capsule, configurations.defaultCfg
archiveName = "nextflow-${version}-core.jar"
from jar // embed our application jar
from (configurations.defaultCfg)
from (configurations.capsule.collect { zipTree(it) })
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest.attributes( 'Main-Class' : 'NextflowLoader',
'Application-Name' : 'nextflow-core',
'Application-Class' : mainClassName,
'Application-Version': version,
'Min-Java-Version' : '1.8.0'
)
doLast {
file(releaseDir).mkdir()
// cleanup
def source = file("$buildDir/libs/nextflow-${version}-core.jar")
def target = file("$releaseDir/nextflow-${version}-core"); target.delete()
// append the big jar
target.withOutputStream {
it << file('nextflow').text.replaceAll(/NXF_PACK\=.*/, 'NXF_PACK=all')
it << new FileInputStream(source)
}
// execute permission
"chmod +x $target".execute()
// done
println "+ Nextflow package `CORE` copied to: $releaseDir\n"
}
}
/*
* Compile and pack all packages
*/
task pack( dependsOn: [packOne, packAll]) {
}
task deploy( type: Exec, dependsOn: [clean, compile, pack]) {
def temp = File.createTempFile('upload',null)
temp.deleteOnExit()
def files = []
doFirst {
checkVersionExits(version)
def path = new File(releaseDir)
if( !path.exists() ) error("Releases path does not exists: $path")
path.eachFile {
if( it.name.startsWith("nextflow-$version"))
files << it
}
if( !files ) error("Can't find any file to upload -- Check path: $path")
files << file('nextflow').absoluteFile
files << file('nextflow.sha1').absoluteFile
files << file('nextflow.sha256').absoluteFile
files << file('nextflow.md5').absoluteFile
println "Uploading artifacts: "
files.each { println "- $it"}
def script = []
script << "export AWS_ACCESS_KEY_ID=${System.env.NXF_AWS_ACCESS}"
script << "export AWS_SECRET_ACCESS_KEY=${System.env.NXF_AWS_SECRET}"
script.addAll( files.collect { "aws s3 cp ${it} s3://www2.nextflow.io/releases/v${version}/${it.name} ${s3CmdOpts}"})
temp.text = script.join('\n')
}
commandLine 'bash', '-e', temp.absolutePath
}
task installLauncher(type: Copy, dependsOn: ['pack']) {
from "$releaseDir/nextflow-$version-one.jar"
into "$homeDir/.nextflow/framework/$version/"
}
/*
* build, tag and publish a and new docker packaged nextflow release
*/
task dockerImage(type: Exec) {
def temp = File.createTempFile('upload',null)
temp.deleteOnExit()
temp.text = """\
grep $version nextflow
cp nextflow docker/nextflow
cd docker
make release version=$version
""".stripIndent()
commandLine 'bash', '-e', temp.absolutePath
}
/*
* Build a docker container image with the current snapshot
* DO NOT CALL IT DIRECTLY! Use the `make dockerPack` command instead
*/
task dockerPack(type: Exec, dependsOn: ['packOne']) {
def source = new File("$releaseDir/nextflow-$version-one.jar")
def target = new File("$buildDir/docker/.nextflow/framework/$version/")
def dockerBase = new File("$buildDir/docker")
if( dockerBase.exists() ) dockerBase.deleteDir()
dockerBase.mkdirs()
def dockerFile = new File("$buildDir/docker/Dockerfile")
dockerFile.text = """
FROM amazoncorretto:17-alpine-jdk
RUN apk update && apk add bash && apk add coreutils && apk add curl
COPY .nextflow /.nextflow
COPY nextflow /usr/local/bin/nextflow
COPY entry.sh /usr/local/bin/entry.sh
COPY dist/docker /usr/local/bin/docker
ENV NXF_HOME=/.nextflow
RUN touch /.nextflow/dockerized && rm -rf /.nextflow/launch-classpath
RUN chmod +x /usr/local/bin/nextflow /usr/local/bin/entry.sh
RUN nextflow info
ENTRYPOINT ["/usr/local/bin/entry.sh"]
"""
def temp = File.createTempFile('upload',null)
temp.deleteOnExit()
temp.text = """\
mkdir -p $target
cp $source $target
cp nextflow $buildDir/docker
cp docker/entry.sh $buildDir/docker
cd $buildDir/docker
mkdir -p dist
curl -fsSLO https://get.docker.com/builds/Linux/x86_64/docker-17.03.1-ce.tgz && tar --strip-components=1 -xvzf docker-17.03.1-ce.tgz -C dist
NXF_HOME=\$PWD/.nextflow ./nextflow info
docker build -t nextflow/nextflow:$version .
""".stripIndent()
commandLine 'bash', '-e', temp.absolutePath
}
/*
* Tag and upload the release
*
* https://github.com/aktau/github-release/
*/
task release(type: Exec, dependsOn: [pack, dockerImage]) {
def launcherFile = file('nextflow').absoluteFile
def launcherSha1 = file('nextflow.sha1').absoluteFile
def launcherSha256 = file('nextflow.sha256').absoluteFile
def nextflowAllFile = file("$releaseDir/nextflow-${version}-all")
def snapshot = version ==~ /^.+(-RC\d+|-SNAPSHOT)$/
def edge = version ==~ /^.+(-edge|-EDGE)$/
def isLatest = !snapshot && !edge
def cmd = """\
# tag the release
git push || exit \$?
(git tag -a v$version -m 'Tagging version $version [release]' -f && git push origin v$version -f) || exit \$?
sleep 1
gh release create --repo nextflow-io/nextflow --prerelease --title "Version $version" v$version
sleep 1
gh release upload --repo nextflow-io/nextflow v$version ${launcherFile} ${nextflowAllFile}
""".stripIndent()
if( edge )
cmd += """
# publish the script as the latest
export AWS_ACCESS_KEY_ID=${System.env.NXF_AWS_ACCESS}
export AWS_SECRET_ACCESS_KEY=${System.env.NXF_AWS_SECRET}
aws s3 cp $launcherFile s3://www2.nextflow.io/releases/edge/nextflow $s3CmdOpts
aws s3 cp $launcherSha1 s3://www2.nextflow.io/releases/edge/nextflow.sha1 $s3CmdOpts
aws s3 cp $launcherSha256 s3://www2.nextflow.io/releases/edge/nextflow.sha256 $s3CmdOpts
aws s3 cp $launcherSha256 s3://www2.nextflow.io/releases/edge/nextflow.md5 $s3CmdOpts
""".stripIndent()
else if( isLatest )
cmd += """
# publish the script as the latest
export AWS_ACCESS_KEY_ID=${System.env.NXF_AWS_ACCESS}
export AWS_SECRET_ACCESS_KEY=${System.env.NXF_AWS_SECRET}
aws s3 cp $launcherFile s3://www2.nextflow.io/releases/latest/nextflow $s3CmdOpts
aws s3 cp $launcherSha1 s3://www2.nextflow.io/releases/latest/nextflow.sha1 $s3CmdOpts
aws s3 cp $launcherSha256 s3://www2.nextflow.io/releases/latest/nextflow.sha256 $s3CmdOpts
aws s3 cp $launcherSha256 s3://www2.nextflow.io/releases/latest/nextflow.md5 $s3CmdOpts
""".stripIndent()
def temp = File.createTempFile('upload',null)
temp.deleteOnExit()
temp.text = cmd
commandLine 'bash', '-e', temp.absolutePath
}