This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
invfile.lua
147 lines (123 loc) · 4.33 KB
/
invfile.lua
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
-- http://stackoverflow.com/questions/19262761/lua-need-to-split-at-comma/19263313#19263313
function string:split( inSplitPattern, outResults )
if not outResults then
outResults = { }
end
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
local repo = VAR.REPO
local channel_args = ''
local channels = VAR.CHANNELS:split(",")
for i = 1, #channels do
channel_args = channel_args .. " -c " .. channels[i]
end
local target_args = ''
local targets = VAR.TARGETS:split(",")
for i = 1, #targets do
target_args = target_args .. " " .. targets[i]
end
local bind_args = {}
local binds_table = VAR.BINDS:split(",")
for i = 1, #binds_table do
table.insert(bind_args, binds_table[i])
end
local test_bind_args = {}
local test_binds_table = VAR.TEST_BINDS:split(",")
for i = 1, #test_binds_table do
table.insert(test_bind_args, test_binds_table[i])
end
local conda_image = VAR.CONDA_IMAGE
if conda_image == '' then
conda_image = 'continuumio/miniconda3:latest'
end
local singularity_image = VAR.SINGULARITY_IMAGE
if singularity_image == '' then
singularity_image = 'quay.io/biocontainers/singularity:2.3--0'
end
local singularity_image_dir = VAR.SINGULARITY_IMAGE_DIR
if singularity_image_dir == '' then
singularity_image_dir = 'singularity_import'
end
local destination_base_image = VAR.DEST_BASE_IMAGE
if destination_base_image == '' then
destination_base_image = 'bgruening/busybox-bash:0.1'
end
local verbose = VAR.VERBOSE
if verbose == '' then
verbose = '--quiet'
else
verbose = '--verbose'
end
local preinstall = VAR.PREINSTALL
if preinstall ~= '' then
preinstall = preinstall .. ' && '
end
local postinstall = VAR.POSTINSTALL
if postinstall ~= '' then
postinstall = '&&' .. postinstall
end
inv.task('build')
.using(conda_image)
.withHostConfig({binds = {"build:/data"}})
.run('rm', '-rf', '/data/dist')
.using(conda_image)
.withHostConfig({binds = bind_args})
.run('/bin/sh', '-c', preinstall
.. 'conda install '
.. channel_args .. ' '
.. target_args
.. ' -p /usr/local --copy --yes '
.. verbose
.. postinstall)
.wrap('build/dist')
.at('/usr/local')
.inImage(destination_base_image)
.as(repo)
if VAR.SINGULARITY ~= '' then
inv.task('singularity')
.using(singularity_image)
.withHostConfig({binds = {"build:/data",singularity_image_dir .. ":/import"}, privileged = true})
.withConfig({entrypoint = {'/bin/sh', '-c'}})
-- for small containers (less than 7MB), double the size otherwise, add a little bit more as half the conda size
.run("size=$(du -sc /data/dist/ | tail -n 1 | cut -f 1 | awk '{print int($1/1024)}' ) && if [ $size -lt '10' ]; then echo 20; else echo $(($size+$size*7/10)); fi")
.run("singularity create --size `size=$(du -sc /data/dist/ | tail -n 1 | cut -f 1 | awk '{print int($1/1024)}' ) && if [ $size -lt '10' ]; then echo 20; else echo $(($size+$size*7/10)); fi` /import/" .. VAR.SINGULARITY_IMAGE_NAME)
.run('mkdir -p /usr/local/var/singularity/mnt/container && singularity bootstrap /import/' .. VAR.SINGULARITY_IMAGE_NAME .. ' /import/Singularity')
.run('chown ' .. VAR.USER_ID .. ' /import/' .. VAR.SINGULARITY_IMAGE_NAME)
end
inv.task('cleanup')
.using(conda_image)
.withHostConfig({binds = {"build:/data"}})
.run('rm', '-rf', '/data/dist')
if VAR.TEST_BINDS == '' then
inv.task('test')
.using(repo)
.withConfig({entrypoint = {'/bin/sh', '-c'}})
.run(VAR.TEST)
else
inv.task('test')
.using(repo)
.withHostConfig({binds = test_bind_args})
.withConfig({entrypoint = {'/bin/sh', '-c'}})
.run(VAR.TEST)
end
inv.task('push')
.push(repo)
inv.task('build-and-test')
.runTask('build')
.runTask('singularity')
.runTask('cleanup')
.runTask('test')
inv.task('all')
.runTask('build')
.runTask('singularity')
.runTask('cleanup')
.runTask('test')
.runTask('push')