forked from namecoin/ncdns-repro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rbm.conf
180 lines (167 loc) · 6.22 KB
/
rbm.conf
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
debug: '[% GET ! ENV.RBM_NO_DEBUG %]'
compress_tar: gz
output_dir: 'out/[% project %]'
tmp_dir: '[% c("basedir") %]/tmp'
_build_log: 'logs/[% project %][% IF c("var/osname") %]-[% c("var/osname") %][% END %].log'
pkg_type: build
var:
sort_deps: 1
build_id: '[% sha256(c("var/build_id_txt", { buildconf => { num_procs => 4 } })).substr(0, 6) %]'
build_id_txt: |
[% c("version") %]
[% IF c("git_hash") || c("hg_hash"); GET c("abbrev"); END; %]
[% IF c("var/container/use_container") -%]
[% c("var/container/suite") %]
[% c("var/container/arch") %]
[% END -%]
input_files: [% c("input_files_id") %]
build:
[% c("build", { filename => 'f', output_dir => '/out' }) %]
container:
dir: '[% c("rbm_tmp_dir") %]/rbm-containers/[% sha256(c("build_id")) %]'
user: rbm
input_files_list: |
[% FOREACH file IN c("input_files_by_name").keys.sort -%]
[% c("input_files_by_name/" _ file) %]
[% END -%]
set_default_env: |
set -e
[% FOREACH env = c('ENV') -%]
export [% env.key %]="[% env.value %]"
[% END -%]
rootdir=$(pwd)
export SHELL=/bin/sh
export HOME=$rootdir
umask 0022
targets:
notarget: linux-x86_64
noint:
debug: 0
ncdns-linux-x86_64:
- linux-x86_64
- linux
linux-x86_64:
arch: x86_64
var:
linux-x86_64: 1
osname: linux-x86_64
container:
arch: amd64
linux:
var:
linux: 1
compiler: gcc
container:
suite: wheezy
deps:
- build-essential
- zip
- unzip
remote_start: '[% IF c("var/container/use_container") %][% c("runc/remote_start") %][% END %]'
remote_exec: '[% IF c("var/container/use_container") %][% c("runc/remote_exec") %][% END %]'
remote_put: '[% IF c("var/container/use_container") %][% c("runc/remote_put") %][% END %]'
remote_get: '[% IF c("var/container/use_container") %][% c("runc/remote_get") %][% END %]'
remote_finish: '[% IF c("var/container/use_container") %][% c("runc/remote_finish") %][% END %]'
runc:
remote_start: |
#!/bin/sh
set -e
if [ $(ls -1 '[% c("remote_srcdir", { error_if_undef => 1 }) %]/container-image_'* | wc -l) -ne 1 ]
then
echo "Can't find container image in input files" >&2
ls -l '[% c("remote_srcdir") %]' >&2
exit 1
fi
mkdir -p '[% c("var/container/dir") %]'/rootfs/rbm
sudo tar -C '[% c("var/container/dir") %]'/rootfs -xf $(ls -1 '[% c("remote_srcdir", { error_if_undef => 1 }) %]/container-image_'*)
[% SET user = c("var/container/user") -%]
[% c("remote_exec", { exec_as_root => 1, exec_cmd => 'id ' _ user
_ ' >/dev/null 2>&1 || adduser -m ' _ user _ ' || useradd -m ' _ user }) %]
remote_exec: |
#!/bin/sh
set -e
[% IF c("interactive") -%]
echo Container directory: [% shell_quote(c("var/container/dir")) %]
[% END -%]
mkdir -p '[% c("var/container/dir", { error_if_undef => 1 }) %]'/rootfs/rbm
echo '#!/bin/sh' > '[% c("var/container/dir") %]'/rootfs/rbm/cmd
echo [% shell_quote(c('exec_cmd')) %] >> '[% c("var/container/dir") %]'/rootfs/rbm/cmd
echo '#!/bin/sh' > '[% c("var/container/dir") %]'/rootfs/rbm/run
[% IF c('exec_as_root'); SET user = 'root'; ELSE; SET user = c("var/container/user", { error_if_undef => 1 }); END; %]
echo 'su - [% user %] -c /rbm/cmd' >> '[% c("var/container/dir") %]'/rootfs/rbm/run
chmod +x '[% c("var/container/dir") %]'/rootfs/rbm/cmd
chmod +x '[% c("var/container/dir") %]'/rootfs/rbm/run
cat > '[% c("var/container/dir") %]'/config.json <<EOF
[% INCLUDE 'runc-config.json' %]
EOF
sudo runc [% IF c("var_p/runc100") %]run[% ELSE %]start[% END %] -b '[% c("var/container/dir") %]' rbm-[% sha256(c("build_id", { error_if_undef => 1 })) %] [% IF c("runc_hide_stderr") %]2>/dev/null[% END %]
remote_put: |
#!/bin/sh
set -e
[%
SET src = shell_quote(c('put_src', { error_if_undef => 1 }));
SET dst = shell_quote(c('put_dst', { error_if_undef => 1 }));
-%]
sudo mkdir -p '[% c("var/container/dir") %]'/rootfs/[% dst %]
sudo cp -aP [% src %] '[% c("var/container/dir") %]'/rootfs/[% dst %]
# On Ubuntu, the /root/.profile file contains a `mesg n` line which is
# producing some `stdin: is not a tty` messages. To hide them, we hide
# stderr from this part by setting runc_hide_stderr.
[% c("remote_exec", { exec_as_root => 1, exec_cmd => 'chown -R ' _ c("var/container/user") _ ' ' _ dst, runc_hide_stderr => 1 }) %]
remote_get: |
#!/bin/sh
set -e
[%
SET src = shell_quote(c('get_src', { error_if_undef => 1 }));
SET dst = shell_quote(c('get_dst', { error_if_undef => 1 }));
-%]
mkdir -p [% dst %]
srcdir='[% c("var/container/dir", { error_if_undef => 1 }) %]'/rootfs/[% src %]
sudo chown -R $(whoami) "$srcdir"
if [ $(ls -1 "$srcdir"/* 2> /dev/null | wc -l) -gt 0 ]
then
for file in "$srcdir"/*
do
bname="$(basename "$file")"
test -e [% dst %]/"$bname" && rm -Rf [% dst %]/"$bname"
mv -f "$file" [% dst %]/
done
fi
remote_finish: |
#!/bin/sh
set -e
sudo rm -Rf '[% c("var/container/dir", { error_if_undef => 1 }) %]'/rootfs '[% c("var/container/dir", { error_if_undef => 1 }) %]'/config.json
rmdir '[% c("var/container/dir") %]'
ENV:
TZ: UTC
LC_ALL: C
--- |
# This part of the file contains options written in perl
use IO::CaptureOutput qw(capture_exec);
my $hashlist = {};
open(my $f, '<:encoding(UTF-8)', 'hashlist') or die "Cannot open hashlist";
while (my $row = <$f>) {
chomp $row;
my @words = split / /, $row;
my $repo = $words[1];
my $hash = $words[2];
$hashlist->{$repo} = $hash;
#print "$repo = $hash\n";
}
(
var_p => {
# runc100 is true if we are using runc >= 1.0.0
# we assume that any version that is not 0.1.1 is >= 1.0.0
runc100 => sub {
my ($out) = capture_exec('sudo', 'runc', '--version');
return !($out =~ m/^runc version 0.1.1/);
},
# runc_spec100 is true if runc spec is at least 1.0.0
# We will need to update this when there is a new spec version available
runc_spec100 => sub {
my ($out) = capture_exec('sudo', 'runc', '--version');
return $out =~ m/^.*spec: 1\.[0-9]+\.[0-9]+$/m;
},
id => $hashlist,
},
)