Build de l'image de base + execution build.py dans le conteneur

This commit is contained in:
wpetit 2017-01-25 14:49:30 +01:00
parent ce05d9a339
commit 38d236e09b
6 changed files with 52 additions and 9 deletions

View File

@ -1,6 +1,31 @@
#!/usr/bin/env bash
HAS_SYSTEMD=$(which systemctl)
ENGINE=chroot
if [ ! -z "${HAS_SYSTEMD}" ]; then
ENGINE=systemd-nspawn
fi
${TAMARIN_ACBUILD} environment add DEBIAN_FRONTEND noninteractive
sudo -E ${TAMARIN_ACBUILD} run -- apt-get update
sudo -E ${TAMARIN_ACBUILD} run -- apt-get install --yes --no-install-recommends build-essential devscripts equivs
if [ "${ENGINE}" == 'chroot' ]; then
# Ugly fix for Python installation in chrooted environment (require /dev/urandom)
head -c 65536 /dev/urandom > ./urandom
${TAMARIN_ACBUILD} copy ./urandom /dev/urandom
fi
sudo -E /usr/bin/env bash - <<EOF
export PATH=${PATH}
${TAMARIN_ACBUILD} run --engine "${ENGINE}" -- apt-get update
${TAMARIN_ACBUILD} run --engine "${ENGINE}" -- apt-get install --yes --no-install-recommends build-essential devscripts equivs
EOF
if [ "${ENGINE}" == 'chroot' ]; then
# Clean up Python fix (see above)
sudo -E /usr/bin/env bash - <<EOF
export PATH=${PATH}
${TAMARIN_ACBUILD} run --engine "${ENGINE}" -- rm -f /dev/urandom
EOF
fi
${TAMARIN_ACBUILD} environment remove DEBIAN_FRONTEND

View File

@ -1,6 +1,15 @@
#!/usr/bin/env bash
HAS_SYSTEMD=$(which systemctl)
ENGINE=chroot
if [ ! -z "${HAS_SYSTEMD}" ]; then
ENGINE=systemd-nspawn
fi
${TAMARIN_ACBUILD} environment add DEBIAN_FRONTEND noninteractive
sudo -E ${TAMARIN_ACBUILD} run -- apt-get update
sudo -E ${TAMARIN_ACBUILD} run -- apt-get install --yes --no-install-recommends git-core
sudo -E /usr/bin/env bash - <<EOF
export PATH=${PATH}
${TAMARIN_ACBUILD} run --engine "${ENGINE}" -- apt-get update
${TAMARIN_ACBUILD} run --engine "${ENGINE}" -- apt-get install --yes --no-install-recommends git-core
EOF
${TAMARIN_ACBUILD} environment remove DEBIAN_FRONTEND

3
lib/build.py Normal file
View File

@ -0,0 +1,3 @@
if __name__ == '__main__':
print('Test')

View File

@ -29,7 +29,7 @@ def find_image_by_name(name_pattern, rkt_flags = []):
return None
def export_image(image_id, dest_file, rkt_flags = []):
output = run([
run([
"image",
"export",
image_id,

View File

@ -6,11 +6,15 @@ def run_profile_hooks(profile, step, cwd=None, env=None):
step_hooks = profile[step]["hooks"].split(",")
for hook_name in step_hooks:
hook_path = os.path.join(hooks_dir, hook_name)
print(hook_path)
subprocess.call(hook_path, cwd=cwd, stdin=subprocess.PIPE, env=env)
def get_hooks_dir():
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../hooks")
def get_lib_dir():
return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../lib")
def load_profile(profile_name):
profile_filename = profile_name+".conf"
for profile_file in get_available_profiles():

10
package
View File

@ -86,7 +86,8 @@ if __name__ == "__main__":
# Build image
tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)])
tamarin.run_acbuild(acbuild_flags+["set-exec", "--", "/bin/sh", "-c", "echo Hello World"])
tamarin.run_acbuild(acbuild_flags+["copy-to-dir", tamarin.get_hooks_dir(), '/tamarin'])
tamarin.run_acbuild(acbuild_flags+["copy-to-dir", tamarin.get_lib_dir(), '/tamarin'])
# Execute containerbuild hooks
cpb_hooks_env = os.environ.copy()
@ -98,11 +99,12 @@ if __name__ == "__main__":
shutil.copyfile(aci_file, cached_image_file)
# Start container
rkt.run([
rkt.run(rkt_flags+[
"run",
"--insecure-options=image",
aci_file, "--net=host"
] + rkt_flags, as_root=True)
aci_file, "--net=host",
"--exec", "/usr/bin/python3", "--", "/tamarin/lib/build.py"
], as_root=True)
# Cleanup