Skip to content

Commit 9e21679

Browse files
author
Jeff Frontz
committed
Add support for a centos-based distro
1 parent ee18066 commit 9e21679

4 files changed

Lines changed: 79 additions & 17 deletions

File tree

bin/gbuild

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def build_one_configuration(suite, arch, build_desc)
4646
ENV["LXC_SUITE"] = suite
4747
end
4848

49+
if ENV["USE_DOCKER"] and build_desc["distro"].eql? "centos"
50+
ontarget_root_extra = "-w /root"
51+
else
52+
ontarget_root_extra = ""
53+
end
54+
4955
suitearch = "#{suite}-#{arch}"
5056

5157
info "Stopping target if it is up"
@@ -73,7 +79,7 @@ def build_one_configuration(suite, arch, build_desc)
7379

7480
system! "on-target true"
7581

76-
system! "on-target -u root tee -a /etc/sudoers.d/#{ENV['DISTRO'] || 'ubuntu'} > /dev/null << EOF
82+
system! "on-target -u root #{ontarget_root_extra} tee -a /etc/sudoers.d/#{ENV['DISTRO'] || 'ubuntu'} > /dev/null << EOF
7783
%#{ENV['DISTRO'] || 'ubuntu'} ALL=(ALL) NOPASSWD: ALL
7884
EOF" if build_desc["sudo"] and @options[:allow_sudo]
7985

@@ -98,29 +104,55 @@ EOF" if build_desc["sudo"] and @options[:allow_sudo]
98104
if build_desc["multiarch"]
99105
info "Adding multiarch support (log in var/install.log)"
100106
for a in build_desc["multiarch"]
101-
system! "on-target -u root dpkg --add-architecture #{a} >> var/install.log 2>&1"
107+
system! "on-target -u root #{ontarget_root_extra} dpkg --add-architecture #{a} >> var/install.log 2>&1"
102108
end
103109
end
104110

105-
info "Updating apt-get repository (log in var/install.log)"
106-
system! "on-target -u root apt-get update >> var/install.log 2>&1"
111+
case build_desc["distro"]
112+
when "centos"
113+
info "Updating yum repository (log in var/install.log)"
114+
system! "on-target -u root #{ontarget_root_extra} yum -y makecache fast >> var/install.log 2>&1"
115+
else
116+
info "Updating apt-get repository (log in var/install.log)"
117+
system! "on-target -u root #{ontarget_root_extra} apt-get update >> var/install.log 2>&1"
118+
end
107119

108120
info "Installing additional packages (log in var/install.log)"
109-
system! "on-target -u root -e DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install #{build_desc["packages"].join(" ")} >> var/install.log 2>&1"
121+
122+
case build_desc["distro"]
123+
when "centos"
124+
system! "on-target -u root #{ontarget_root_extra} yum -y install #{build_desc["packages"].join(" ")} > var/install.log 2>&1"
125+
else
126+
system! "on-target -u root #{ontarget_root_extra} -e DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install #{build_desc["packages"].join(" ")} >> var/install.log 2>&1"
127+
end
110128

111129
if build_desc["alternatives"]
112130
info "Set alternatives (log in var/install.log)"
113131
for a in build_desc["alternatives"]
114-
system! "on-target -u root update-alternatives --set #{a["package"]} #{a["path"]} >> var/install.log 2>&1"
132+
system! "on-target -u root #{ontarget_root_extra} update-alternatives --set #{a["package"]} #{a["path"]} >> var/install.log 2>&1"
115133
end
116134
end
117135

118-
if @options[:upgrade] || system("on-target -u root '[ ! -e /var/cache/gitian/initial-upgrade ]'")
136+
if @options[:upgrade] || system("on-target -u root #{ontarget_root_extra} '[ ! -e /var/cache/gitian/initial-upgrade ]'")
119137
info "Upgrading system, may take a while (log in var/install.log)"
120-
system! "on-target -u root bash < target-bin/upgrade-system.sh >> var/install.log 2>&1"
138+
case build_desc["distro"]
139+
when "centos"
140+
system! "on-target -u root #{ontarget_root_extra} mkdir -p /var/cache/gitian"
141+
system! "on-target -u root #{ontarget_root_extra} yum -y update > var/upgrade.log 2>&1"
142+
system! "copy-to-target #{@quiet_flag} var/upgrade.log /var/cache/gitian/upgrade.log"
143+
system! "on-target -u root #{ontarget_root_extra} touch /var/cache/gitian/initial-upgrade"
144+
else
145+
system! "on-target -u root #{ontarget_root_extra} bash < target-bin/upgrade-system.sh >> var/install.log 2>&1"
146+
end
121147
end
122148
info "Creating package manifest"
123-
system! "on-target -u root bash < target-bin/grab-packages.sh > var/base-#{suitearch}.manifest"
149+
150+
case build_desc["distro"]
151+
when "centos"
152+
system! "on-target -u root #{ontarget_root_extra} yumdb get checksum_data | awk '/checksum_data =/ { print $3, package; next } { package=$1 }' | sort --key 2 > var/base-#{suitearch}.manifest"
153+
else
154+
system! "on-target -u root #{ontarget_root_extra} bash < target-bin/grab-packages.sh > var/base-#{suitearch}.manifest"
155+
end
124156

125157
info "Creating build script (var/build-script)"
126158

@@ -143,7 +175,7 @@ EOF" if build_desc["sudo"] and @options[:allow_sudo]
143175
build_desc["remotes"].each do |remote|
144176
dir = sanitize(remote["dir"], remote["dir"])
145177

146-
author_date = `cd inputs/#{dir} && git log --format=@%at -1 | date +"%F %T" -u -f -`.strip
178+
author_date = `cd inputs/#{dir} > /dev/null && git log --format=@%at -1 | date +"%F %T" -u -f -`.strip
147179
raise "error looking up author date in #{dir}" unless $?.exitstatus == 0
148180

149181
system! "copy-to-target #{@quiet_flag} inputs/#{dir} build/"
@@ -220,11 +252,13 @@ in_sums = []
220252
build_dir = 'build'
221253
result_dir = 'result'
222254
cache_dir = 'cache'
255+
work_dir = 'var'
223256
enable_cache = build_desc["enable_cache"]
224257

225258
FileUtils.rm_rf(build_dir)
226259
FileUtils.mkdir(build_dir)
227260
FileUtils.mkdir_p(result_dir)
261+
FileUtils.mkdir_p(work_dir)
228262

229263
package_name = build_desc["name"] or raise "must supply name"
230264
package_name = sanitize(package_name, "package name")
@@ -290,13 +324,15 @@ build_desc["remotes"].each do |remote|
290324
end
291325
system!("cd inputs/#{dir} && git fetch --update-head-ok #{sanitize_path(remote["url"], remote["url"])} +refs/tags/*:refs/tags/* +refs/heads/*:refs/heads/*")
292326
commit = sanitize(remote["commit"], remote["commit"])
293-
commit = `cd inputs/#{dir} && git log --format=%H -1 #{commit}`.strip
327+
commit = `cd inputs/#{dir} > /dev/null && git log --format=%H -1 #{commit}`.strip
294328
raise "error looking up commit for tag #{remote["commit"]}" unless $?.exitstatus == 0
329+
info("commit is #{commit}")
295330
system!("cd inputs/#{dir} && git checkout -q #{commit}")
296331
system!("cd inputs/#{dir} && git submodule update --init --recursive --force")
297332
in_sums << "git:#{commit} #{dir}"
298333
end
299334

335+
300336
base_manifests = YAML::Omap.new
301337

302338
suites.each do |suite|
@@ -333,7 +369,7 @@ Dir.glob(File.join(out_dir, '**', '*'), File::FNM_DOTMATCH).sort.each do |file_i
333369
next if File.directory?(file_in_out)
334370
file = file_in_out.sub(out_dir + File::SEPARATOR, '')
335371
file = sanitize_path(file, file_in_out)
336-
out_sums[file] = `cd #{out_dir} && sha256sum #{file}`
372+
out_sums[file] = `cd #{out_dir} > /dev/null && sha256sum #{file}`
337373
raise "failed to sum #{file}" unless $? == 0
338374
puts out_sums[file] unless @options[:quiet]
339375
end
@@ -343,15 +379,15 @@ if enable_cache
343379
next if File.directory?(file_in_out)
344380
file = file_in_out.sub(cache_common_dir + File::SEPARATOR, '')
345381
file = sanitize_path(file, file_in_out)
346-
cache_common_sums[file] = `cd #{cache_common_dir} && sha256sum #{file}`
382+
cache_common_sums[file] = `cd #{cache_common_dir} > /dev/null && sha256sum #{file}`
347383
raise "failed to sum #{file}" unless $? == 0
348384
end
349385

350386
Dir.glob(File.join(cache_package_dir, '**', '*'), File::FNM_DOTMATCH).sort.each do |file_in_out|
351387
next if File.directory?(file_in_out)
352388
file = file_in_out.sub(cache_package_dir + File::SEPARATOR, '')
353389
file = sanitize_path(file, file_in_out)
354-
cache_package_sums[file] = `cd #{cache_package_dir} && sha256sum #{file}`
390+
cache_package_sums[file] = `cd #{cache_package_dir} > /dev/null && sha256sum #{file}`
355391
raise "failed to sum #{file}" unless $? == 0
356392
end
357393
end

bin/make-base-vm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,20 @@ if [ $DOCKER = "1" ]; then
184184
base_image="$DISTRO:$SUITE"
185185
fi
186186

187+
if [ $DISTRO = "centos" ]; then
188+
UPDATE_FROM_REPO="yum -y update && yum -y install epel-release"
189+
INSTALL_FROM_REPO="yum -y install"
190+
else
191+
UPDATE_FROM_REPO="apt-get update"
192+
INSTALL_FROM_REPO="apt-get --no-install-recommends -y install"
193+
fi
194+
187195
# Generate the dockerfile
188196
cat << EOF > $OUT.Dockerfile
189197
FROM $base_image
190198
191199
ENV DEBIAN_FRONTEND=noninteractive
192-
RUN apt-get update && apt-get --no-install-recommends -y install $addpkg
200+
RUN $UPDATE_FROM_REPO && $INSTALL_FROM_REPO $addpkg
193201
194202
RUN useradd -ms /bin/bash -U $DISTRO
195203
USER $DISTRO:$DISTRO

libexec/copy-to-target

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ fi
4949
if [ -n "$USE_DOCKER" ]; then
5050
docker exec -u $TUSER gitian-target mkdir -p "/home/$TUSER/$2"
5151
docker cp "$1" gitian-target:"/home/$TUSER/$2"
52-
docker exec -u root gitian-target chown -R $TUSER:$TUSER "/home/$TUSER/$2"
52+
# newer docker version is strict about non-default-user working directories
53+
if docker exec -u root -w /root gitian-target true > /dev/null 2>&1
54+
then
55+
docker exec -u root -w /root gitian-target chown -R $TUSER:$TUSER "/home/$TUSER/$2"
56+
else
57+
docker exec -u root gitian-target chown -R $TUSER:$TUSER "/home/$TUSER/$2"
58+
fi
5359
elif [ -z "$USE_LXC" ]; then
5460
src="${1%/}" # remove trailing / which triggers special rsync behaviour
5561
rsync --checksum -a $QUIET_FLAG -e "ssh -oConnectTimeout=30 -oNoHostAuthenticationForLocalhost=yes -i ${GITIAN_BASE:-.}/var/id_rsa -p $VM_SSH_PORT" "${src}" "$TUSER@localhost:$2"

libexec/on-target

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ if [ $# != 0 ] ; then
3030
ENV="$2"
3131
shift 2
3232
;;
33+
--workdir|-w)
34+
if [ -n "$USE_DOCKER" ]; then
35+
if docker exec -u root -w /root gitian-target true > /dev/null 2>&1; then
36+
# newer docker version is strict about non-default-user working dir
37+
TWORKDIR="-w $2"
38+
fi
39+
shift 2
40+
else
41+
echo "unrecognized option $1"
42+
exit 1
43+
fi
44+
;;
3345
--*)
3446
echo "unrecognized option $1"
3547
exit 1
@@ -47,7 +59,7 @@ fi
4759
#fi
4860

4961
if [ -n "$USE_DOCKER" ]; then
50-
docker exec -u $TUSER -i gitian-target $*
62+
docker exec -u $TUSER $TWORKDIR -i gitian-target $*
5163
elif [ -z "$USE_LXC" ]; then
5264
ssh -oConnectTimeout=30 -oNoHostAuthenticationForLocalhost=yes -i ${GITIAN_BASE:-.}/var/id_rsa -p $VM_SSH_PORT $TUSER@localhost $*
5365
else

0 commit comments

Comments
 (0)