Construction/execution d'un conteneur à partir de l'image de base spécifiée dans le profil
This commit is contained in:
parent
b88493523f
commit
487c97e88c
|
@ -59,15 +59,21 @@ def download_acbuild():
|
||||||
web.download_file(file_url=url, dest_path=file_path)
|
web.download_file(file_url=url, dest_path=file_path)
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
def run_rkt(args):
|
def run_rkt(args, asRoot = False, captureOutput=False):
|
||||||
"""Run rkt with the specified args (use the local copy if rkt is not found in the $PATH)"""
|
"""Run rkt with the specified args (use the local copy if rkt is not found in the $PATH)"""
|
||||||
rkt_bin = system.which('rkt', get_workspace_subdir('rkt'))
|
rkt_bin = system.which('rkt', get_workspace_subdir('rkt'))
|
||||||
cmd = ( ["sudo", "-E", rkt_bin] if os.geteuid() != 0 else [rkt_bin] ) + args
|
cmd = ( ["sudo", "-E", rkt_bin] if os.geteuid() != 0 and asRoot == True else [rkt_bin] ) + args
|
||||||
print(" ".join(cmd))
|
print(" ".join(cmd))
|
||||||
|
if captureOutput:
|
||||||
|
return subprocess.check_output(cmd, stdin=subprocess.PIPE)
|
||||||
|
else:
|
||||||
return subprocess.call(cmd, stdin=subprocess.PIPE)
|
return subprocess.call(cmd, stdin=subprocess.PIPE)
|
||||||
|
|
||||||
def run_acbuild(args):
|
def run_acbuild(args, captureOutput=False):
|
||||||
"""Run acbuild with the specified args (use the local copy if acbuild is not found in the $PATH)"""
|
"""Run acbuild with the specified args (use the local copy if acbuild is not found in the $PATH)"""
|
||||||
acbuild_bin = system.which('acbuild', get_workspace_subdir('acbuild'))
|
acbuild_bin = system.which('acbuild', get_workspace_subdir('acbuild'))
|
||||||
print(" ".join([acbuild_bin] + args))
|
print(" ".join([acbuild_bin] + args))
|
||||||
|
if captureOutput:
|
||||||
|
return subprocess.check_output([acbuild_bin] + args, stdin=subprocess.PIPE)
|
||||||
|
else:
|
||||||
return subprocess.call([acbuild_bin] + args, stdin=subprocess.PIPE)
|
return subprocess.call([acbuild_bin] + args, stdin=subprocess.PIPE)
|
||||||
|
|
43
package
43
package
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse, sys, shutil, os
|
import argparse, sys, shutil, os, json
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(__file__) + '/lib')
|
sys.path.append(os.path.dirname(__file__) + '/lib')
|
||||||
|
|
||||||
|
@ -52,13 +52,50 @@ if __name__ == "__main__":
|
||||||
image_path = os.path.join(os.sep, acbuild_workspace, image_name)
|
image_path = os.path.join(os.sep, acbuild_workspace, image_name)
|
||||||
acbuild_flags = ["--work-path", acbuild_workspace]
|
acbuild_flags = ["--work-path", acbuild_workspace]
|
||||||
|
|
||||||
|
rkt_flags = ["--dir={:s}".format(workspace_tmp)]
|
||||||
|
|
||||||
|
base_image = profile['profile']['default_image']
|
||||||
|
# If the base image is Docker-based, preload it and get its name from the store
|
||||||
|
if base_image.startswith('docker://'):
|
||||||
|
tamarin.run_rkt([
|
||||||
|
"fetch",
|
||||||
|
"--insecure-options=image",
|
||||||
|
base_image
|
||||||
|
] + rkt_flags)
|
||||||
|
output = tamarin.run_rkt([
|
||||||
|
"image",
|
||||||
|
"list",
|
||||||
|
"--format=json"
|
||||||
|
] + rkt_flags, captureOutput=True)
|
||||||
|
# Fetch the list of installed images
|
||||||
|
images_list = json.loads(output.decode('utf-8'))
|
||||||
|
base_image = images_list[0]['name']
|
||||||
|
|
||||||
# Start building image
|
# Start building image
|
||||||
tamarin.run_acbuild(acbuild_flags+["begin"])
|
tamarin.run_acbuild(acbuild_flags+["begin"])
|
||||||
tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)])
|
tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)])
|
||||||
# tamarin.run_acbuild(acbuild_flags+["dependency", "add", profile['profile']['default_image']])
|
tamarin.run_acbuild(acbuild_flags+["dependency", "add", base_image])
|
||||||
tamarin.run_acbuild(acbuild_flags+["set-exec", "--", "/bin/sh", "-c", "echo Hello World"])
|
tamarin.run_acbuild(acbuild_flags+["set-exec", "--", "/bin/sh", "-c", "echo Hello World"])
|
||||||
tamarin.run_acbuild(acbuild_flags+["write", image_path])
|
tamarin.run_acbuild(acbuild_flags+["write", image_path])
|
||||||
tamarin.run_acbuild(acbuild_flags+["end"])
|
tamarin.run_acbuild(acbuild_flags+["end"])
|
||||||
|
|
||||||
# rkt run --insecure-options=image ./nginx.aci --volume html,kind=host,source=/path/to/test --net=host
|
# rkt run --insecure-options=image ./nginx.aci --volume html,kind=host,source=/path/to/test --net=host
|
||||||
tamarin.run_rkt(["run", "--insecure-options=image", "--dir={:s}".format(workspace_tmp), "--stage1-name={:s}".format(profile['profile']['default_image']), image_path, "--net=host"])
|
tamarin.run_rkt([
|
||||||
|
"run",
|
||||||
|
"--insecure-options=image",
|
||||||
|
image_path, "--net=host"
|
||||||
|
] + rkt_flags, asRoot=True)
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
|
||||||
|
tamarin.run_rkt([
|
||||||
|
"gc",
|
||||||
|
"--grace-period=0"
|
||||||
|
] + rkt_flags, asRoot=True)
|
||||||
|
|
||||||
|
tamarin.run_rkt([
|
||||||
|
"image",
|
||||||
|
"gc"
|
||||||
|
] + rkt_flags, asRoot=True)
|
||||||
|
|
||||||
|
shutil.rmtree(acbuild_workspace, ignore_errors=True)
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
echo $1
|
|
Loading…
Reference in New Issue