|
@@ -23,23 +23,23 @@ def create_args_parser():
|
23
|
23
|
|
24
|
24
|
return parser
|
25
|
25
|
|
26
|
|
-def download_and_extract_rkt(dest_dir, verbose=True):
|
|
26
|
+def download_and_extract_rkt(dest_dir, debug=False):
|
27
|
27
|
'''Download and extract rkt to the given destination directory'''
|
28
|
|
- rkt_archive_path = tamarin.download_rkt()
|
29
|
|
- system.extract_tar(rkt_archive_path, workspace_tmp)
|
|
28
|
+ rkt_archive_path = tamarin.download_rkt(debug=debug)
|
|
29
|
+ system.extract_tar(rkt_archive_path, workspace_tmp, debug=debug)
|
30
|
30
|
rkt_archive_dir = tamarin.get_rkt_achive_dest_dir()
|
31
|
31
|
shutil.rmtree(local_rkt_dir, ignore_errors=True)
|
32
|
32
|
os.rename(rkt_archive_dir, dest_dir)
|
33
|
33
|
|
34
|
|
-def download_and_extract_acbuild(dest_dir, verbose=True):
|
|
34
|
+def download_and_extract_acbuild(dest_dir, debug=False):
|
35
|
35
|
'''Download and extract acbuild to the given destination directory'''
|
36
|
|
- acbuild_archive_path = tamarin.download_acbuild()
|
37
|
|
- system.extract_tar(acbuild_archive_path, workspace_tmp)
|
|
36
|
+ acbuild_archive_path = tamarin.download_acbuild(debug=debug)
|
|
37
|
+ system.extract_tar(acbuild_archive_path, workspace_tmp, debug=debug)
|
38
|
38
|
acbuild_archive_dir = tamarin.get_acbuild_achive_dest_dir()
|
39
|
39
|
shutil.rmtree(local_acbuild_dir, ignore_errors=True)
|
40
|
40
|
os.rename(acbuild_archive_dir, dest_dir)
|
41
|
41
|
|
42
|
|
-def get_cached_image_path(profile):
|
|
42
|
+def get_cached_image_path(profile, debug=False):
|
43
|
43
|
'''Compute and return the path for an hypothetic cached image for the given profile'''
|
44
|
44
|
containerbuild_hooks = profile['containerbuild']['hooks']
|
45
|
45
|
hasher = hashlib.sha1()
|
|
@@ -49,23 +49,23 @@ def get_cached_image_path(profile):
|
49
|
49
|
cache_dir = tamarin.get_workspace_subdir('cache')
|
50
|
50
|
return os.path.join(os.sep, cache_dir, '{:s}.aci'.format(image_hash[:12]));
|
51
|
51
|
|
52
|
|
-def build_image(build_workspace, aci_file, base_image, profile):
|
|
52
|
+def build_image(build_workspace, aci_file, base_image, profile, debug=False):
|
53
|
53
|
|
54
|
54
|
acbuild_flags = ["--work-path", build_workspace]
|
55
|
55
|
|
56
|
56
|
# Find and export base image from rkt' store
|
57
|
57
|
name_pattern = base_image.split('/')[-1] + '$'
|
58
|
58
|
image = rkt.find_image_by_name(name_pattern, rkt_flags=rkt_flags)
|
59
|
|
- rkt.export_image(image['id'], aci_file, rkt_flags=rkt_flags);
|
|
59
|
+ rkt.export_image(image['id'], aci_file, rkt_flags=rkt_flags, debug=debug);
|
60
|
60
|
|
61
|
61
|
# Build image
|
62
|
|
- tamarin.run_acbuild(acbuild_flags+["begin", aci_file])
|
63
|
|
- tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)])
|
64
|
|
- tamarin.run_acbuild(acbuild_flags+["mount", "add", "src", "/src", "--read-only"])
|
65
|
|
- tamarin.run_acbuild(acbuild_flags+["mount", "add", "dist", "/dist"])
|
66
|
|
- tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-hooks", "/tamarin/hooks", "--read-only"])
|
67
|
|
- tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-lib", "/tamarin/lib", "--read-only"])
|
68
|
|
- tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-profiles", "/tamarin/profiles", "--read-only"])
|
|
62
|
+ tamarin.run_acbuild(acbuild_flags+["begin", aci_file], debug=debug)
|
|
63
|
+ tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)], debug=debug)
|
|
64
|
+ tamarin.run_acbuild(acbuild_flags+["mount", "add", "src", "/src", "--read-only"], debug=debug)
|
|
65
|
+ tamarin.run_acbuild(acbuild_flags+["mount", "add", "dist", "/dist"], debug=debug)
|
|
66
|
+ tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-hooks", "/tamarin/hooks", "--read-only"], debug=debug)
|
|
67
|
+ tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-lib", "/tamarin/lib", "--read-only"], debug=debug)
|
|
68
|
+ tamarin.run_acbuild(acbuild_flags+["mount", "add", "tamarin-profiles", "/tamarin/profiles", "--read-only"], debug=debug)
|
69
|
69
|
|
70
|
70
|
# Configure "containerbuild" hooks environment
|
71
|
71
|
hooks_env = os.environ.copy()
|
|
@@ -74,26 +74,26 @@ def build_image(build_workspace, aci_file, base_image, profile):
|
74
|
74
|
hooks_env["TAMARIN_ACBUILD_ENGINE"] = "chroot" if not system.which('systemctl') else "systemd-nspawn"
|
75
|
75
|
|
76
|
76
|
# Run hooks
|
77
|
|
- tamarin.run_profile_hooks(profile, 'containerbuild', cwd=build_workspace, env=hooks_env)
|
|
77
|
+ tamarin.run_profile_hooks(profile, 'containerbuild', cwd=build_workspace, env=hooks_env, debug=debug)
|
78
|
78
|
|
79
|
|
- tamarin.run_acbuild(acbuild_flags+["write", "--overwrite", aci_file])
|
80
|
|
- tamarin.run_acbuild(acbuild_flags+["end"])
|
|
79
|
+ tamarin.run_acbuild(acbuild_flags+["write", "--overwrite", aci_file], as_root=True, debug=debug)
|
|
80
|
+ tamarin.run_acbuild(acbuild_flags+["end"], as_root=True, debug=debug)
|
81
|
81
|
|
82
|
82
|
return aci_file
|
83
|
83
|
|
84
|
|
-def cleanup(build_workspace, rkt_flags):
|
|
84
|
+def cleanup(build_workspace, rkt_flags, debug=False):
|
85
|
85
|
|
86
|
86
|
# Nettoyage des conteneurs
|
87
|
87
|
rkt.run([
|
88
|
88
|
"gc",
|
89
|
89
|
"--grace-period=0"
|
90
|
|
- ] + rkt_flags, as_root=True)
|
|
90
|
+ ] + rkt_flags, as_root=True, debug=debug)
|
91
|
91
|
|
92
|
92
|
# Nettoyage des images obsolètes du store
|
93
|
93
|
rkt.run([
|
94
|
94
|
"image",
|
95
|
95
|
"gc"
|
96
|
|
- ] + rkt_flags, as_root=True)
|
|
96
|
+ ] + rkt_flags, as_root=True, debug=debug)
|
97
|
97
|
|
98
|
98
|
# Suppression de l'espace de travail de build
|
99
|
99
|
shutil.rmtree(build_workspace, ignore_errors=True)
|
|
@@ -113,7 +113,7 @@ if __name__ == "__main__":
|
113
|
113
|
output_dir = os.path.abspath(args.output)
|
114
|
114
|
|
115
|
115
|
# Load build profile
|
116
|
|
- profile = tamarin.load_profile(args.profile)
|
|
116
|
+ profile = tamarin.load_profile(args.profile, debug=args.debug)
|
117
|
117
|
|
118
|
118
|
workspace = tamarin.get_workspace_dir()
|
119
|
119
|
workspace_tmp = tamarin.get_workspace_subdir('tmp')
|
|
@@ -140,16 +140,16 @@ if __name__ == "__main__":
|
140
|
140
|
"fetch",
|
141
|
141
|
"--insecure-options=image",
|
142
|
142
|
base_image
|
143
|
|
- ] + rkt_flags)
|
|
143
|
+ ] + rkt_flags, debug=args.debug)
|
144
|
144
|
|
145
|
145
|
aci_file = os.path.join(os.sep, build_workspace, 'image.aci')
|
146
|
|
- cached_image_file = get_cached_image_path(profile)
|
|
146
|
+ cached_image_file = get_cached_image_path(profile, debug=args.debug)
|
147
|
147
|
|
148
|
148
|
if not args.rebuild and os.path.exists(cached_image_file):
|
149
|
149
|
# Copy cached image
|
150
|
150
|
shutil.copyfile(cached_image_file, aci_file)
|
151
|
151
|
else:
|
152
|
|
- build_image(build_workspace, aci_file, base_image, profile)
|
|
152
|
+ build_image(build_workspace, aci_file, base_image, profile, debug=args.debug)
|
153
|
153
|
# Cache image
|
154
|
154
|
shutil.copyfile(aci_file, cached_image_file)
|
155
|
155
|
|
|
@@ -172,11 +172,13 @@ if __name__ == "__main__":
|
172
|
172
|
|
173
|
173
|
if args.debug:
|
174
|
174
|
rkt_args += ["--interactive", "--exec", "/bin/bash"]
|
|
175
|
+ helper_cmd = " ".join(["/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture])
|
|
176
|
+ print("Executer '{:s}' pour lancer la construction du paquet.".format(helper_cmd))
|
175
|
177
|
else:
|
176
|
178
|
rkt_args += ["--exec", "/usr/bin/python3", "--", "/tamarin/lib/build.py", args.profile, args.architecture]
|
177
|
179
|
|
178
|
180
|
# Start container
|
179
|
|
- rkt.run(rkt_flags+rkt_args, as_root=True)
|
|
181
|
+ rkt.run(rkt_flags+rkt_args, as_root=True, debug=args.debug)
|
180
|
182
|
|
181
|
183
|
# Cleanup
|
182
|
|
- cleanup(build_workspace, rkt_flags)
|
|
184
|
+ cleanup(build_workspace, rkt_flags, debug=args.debug)
|