-
Notifications
You must be signed in to change notification settings - Fork 642
/
packing.gradle
289 lines (241 loc) · 10.1 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
configurations {
defaultCfg.extendsFrom api
//provided
console.extendsFrom defaultCfg
google.extendsFrom defaultCfg
amazon.extendsFrom defaultCfg
azure.extendsFrom defaultCfg
legacy.extendsFrom defaultCfg
tower.extendsFrom defaultCfg
wave.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.2"
// default cfg = runtime + httpfs + amazon + tower client + wave client
defaultCfg project(':nf-httpfs')
console project(':plugins:nf-console')
google project(':plugins:nf-google')
amazon project(':plugins:nf-amazon')
azure project(':plugins:nf-azure')
tower project(':plugins:nf-tower')
wave project(':plugins:nf-wave')
}
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")
}
/*
* Compile and pack all packages
*/
task packOne( dependsOn: [compile, ":nextflow:shadowJar"]) {
doLast {
def source = "modules/nextflow/build/libs/nextflow-${version}-one.jar"
ant.copy(file: source, todir: releaseDir, overwrite: true)
ant.copy(file: source, todir: nextflowDir, overwrite: true)
println "\n+ Nextflow package `ONE` copied to: $releaseDir/nextflow-${version}-one.jar"
}
}
task packDist( dependsOn: [compile, ":nextflow:shadowJar"]) {
doLast {
file(releaseDir).mkdirs()
// cleanup
def source = file("modules/nextflow/build/libs/nextflow-${version}-one.jar")
def target = file("$releaseDir/nextflow-${version}-dist"); target.delete()
// append the big jar
target.withOutputStream {
it << file('nextflow').text.replaceAll(/NXF_PACK\=.*/, 'NXF_PACK=dist')
it << new FileInputStream(source)
}
// execute permission
"chmod +x $target".execute()
// done
println "+ Nextflow package `ALL` copied to: $target\n"
}
}
/*
* Compile and pack all packages
*/
task pack( dependsOn: [packOne, packDist]) {
}
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 exist: $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/"
}
task installScratch(type: Copy, dependsOn: ['pack']) {
from "$releaseDir/nextflow-$version-one.jar"
into "${rootProject.projectDir}/test-e2e/.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 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}-dist")
def versionFile = file('VERSION').absoluteFile
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
aws s3 cp $versionFile s3://www2.nextflow.io/releases/edge/version $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
aws s3 cp $versionFile s3://www2.nextflow.io/releases/latest/version $s3CmdOpts
""".stripIndent()
def temp = File.createTempFile('upload',null)
temp.deleteOnExit()
temp.text = cmd
commandLine 'bash', '-e', temp.absolutePath
}