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
|
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# Copyright (C) 2015-2016 Harald Sitter <sitter@kde.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) version 3, or any
# later version accepted by the membership of KDE e.V. (or its
# successor approved by the membership of KDE e.V.), which shall
# act as a proxy defined in Section 6 of version 3 of the license.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
require 'fileutils'
require 'etc'
require_relative '../lib/ci/containment'
TOOLING_PATH = File.dirname(__dir__)
JOB_NAME = ENV.fetch('JOB_NAME')
DIST = ENV.fetch('DIST')
TYPE = ENV.fetch('TYPE')
ARCH = ENV.fetch('ARCH')
IMAGE_HOST = 'ci-image-store'
Docker.options[:read_timeout] = 4 * 60 * 60 # 4 hours.
binds = [
"#{TOOLING_PATH}:#{TOOLING_PATH}",
"#{Dir.pwd}:#{Dir.pwd}"
]
c = CI::Containment.new(JOB_NAME,
image: CI::PangeaImage.new(:ubuntu, DIST),
binds: binds,
privileged: false,
cap_add: ['SYS_ADMIN'],
security_opts: ['apparmor:unconfined'])
cmd = ["#{TOOLING_PATH}/kci/imager/build.sh", Dir.pwd, DIST, ARCH, TYPE, "#{Etc.getpwuid.uid}"]
status_code = c.run(Cmd: cmd)
post_code = c.run(Cmd: ["#{TOOLING_PATH}/kci/imager/post_build.sh", Dir.pwd, "#{Etc.getpwuid.uid}"])
exit status_code unless status_code == 0
exit post_code unless post_code == 0
DATE = File.read('result/date_stamp').strip
PUB_PATH = "/srv/jenkins/public/images/#{JOB_NAME}/#{DATE}".freeze
puts 'Generate sha256 checksum for image...'
unless system('sha256sum result/*.iso | tee result/SHA256SUM')
abort 'Failed to generate checksum file'
end
unless system("ssh #{IMAGE_HOST} mkdir -p #{PUB_PATH}/")
abort 'Failed to create target directory'
end
puts 'Copy build to image storage...'
%w(*.iso *.manifest *.zsync SHA256SUM).each do |type|
unless system("rsync -avz result/#{type} #{IMAGE_HOST}:#{PUB_PATH}/")
abort "File type #{type} failed to copy to public directory."
end
end
puts 'Publish image...'
unless system("ssh #{IMAGE_HOST} publish-ci-image #{PUB_PATH}")
abort 'Failed to publish image'
end
exit 0
|