add support for --build-arg flag
This commit is contained in:
parent
2a0b4373ac
commit
a4d9ede97d
@ -6,10 +6,14 @@
|
|||||||
conf_date = 2024,
|
conf_date = 2024,
|
||||||
comment = "There are two dockerfiles. a dockerfile from the authors that serves as a base image. we will only rebuild the base image. the top level image appear to be mostly a copy + compile, no install",
|
comment = "There are two dockerfiles. a dockerfile from the authors that serves as a base image. we will only rebuild the base image. the top level image appear to be mostly a copy + compile, no install",
|
||||||
virtualization = "docker",
|
virtualization = "docker",
|
||||||
buildfile_dir = ".",
|
buildfile_dir = "xpn-docker-euro-par2024",
|
||||||
dockerfile_path = ".docker/base/dockerfile",
|
dockerfile_path = "docker/base/dockerfile",
|
||||||
|
build_args = [
|
||||||
|
"UID=1234",
|
||||||
|
"GID=1000"
|
||||||
|
],
|
||||||
package_managers = [ "dpkg" ],
|
package_managers = [ "dpkg" ],
|
||||||
misc_packages = [
|
misc_packages = [
|
||||||
{ name = "mpich-4.1.1", url = "https://www.mpich.org/static/downloads/4.1.1/mpich-4.1.1.tar.gz" }
|
{ name = "mpich-4.1.1", url = "https://www.mpich.org/static/downloads/4.1.1/mpich-4.1.1.tar.gz" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,10 @@ def buildresult_saver(result, buildstatus_path, config_path):
|
|||||||
timestamp = str(datetime.datetime.timestamp(now))
|
timestamp = str(datetime.datetime.timestamp(now))
|
||||||
buildstatus_file.write(f"{artifact_name},{timestamp},{result}\n")
|
buildstatus_file.write(f"{artifact_name},{timestamp},{result}\n")
|
||||||
|
|
||||||
def build_image(path, dockerfile_path, image_name):
|
def build_image(path, dockerfile_path, image_name, build_args):
|
||||||
logging.info(f"Starting building image {image_name}")
|
logging.info(f"Starting building image {image_name}")
|
||||||
build_command = f"docker build --no-cache -t {image_name} -f {dockerfile_path} ."
|
build_args_str = " ".join(map(lambda x: f"--build-arg {x}", build_args))
|
||||||
|
build_command = f"docker build --no-cache -t {image_name} {build_args_str} -f {dockerfile_path} ."
|
||||||
build_process = subprocess.run(build_command.split(" "), cwd=path, capture_output=True)
|
build_process = subprocess.run(build_command.split(" "), cwd=path, capture_output=True)
|
||||||
build_output = f"stdout:\n{build_process.stdout.decode('utf-8')}\nstderr:\n{build_process.stderr.decode('utf-8')}"
|
build_output = f"stdout:\n{build_process.stdout.decode('utf-8')}\nstderr:\n{build_process.stderr.decode('utf-8')}"
|
||||||
logging.info(f"Output of '{build_command}':\n\n{build_output}")
|
logging.info(f"Output of '{build_command}':\n\n{build_output}")
|
||||||
@ -253,7 +254,7 @@ def ecg(artifact_name, config_path, pkglist_path, buildstatus_path, arthashlog_p
|
|||||||
|
|
||||||
if artifact_dir != "":
|
if artifact_dir != "":
|
||||||
path = os.path.join(artifact_dir, config["buildfile_dir"])
|
path = os.path.join(artifact_dir, config["buildfile_dir"])
|
||||||
return_code, build_output = build_image(path, config["dockerfile_path"], artifact_name)
|
return_code, build_output = build_image(path, config["dockerfile_path"], artifact_name, config["build_args"])
|
||||||
if return_code == 0:
|
if return_code == 0:
|
||||||
status = "success"
|
status = "success"
|
||||||
check_env(config, artifact_dir, artifact_name, pkglist_path)
|
check_env(config, artifact_dir, artifact_name, pkglist_path)
|
||||||
|
@ -82,6 +82,11 @@ in
|
|||||||
| doc "Path to the Dockerfile from the build directory"
|
| doc "Path to the Dockerfile from the build directory"
|
||||||
| FilePath
|
| FilePath
|
||||||
| default = "Dockerfile",
|
| default = "Dockerfile",
|
||||||
|
build_args
|
||||||
|
| doc "Build arguments for Docker ('--build-arg')"
|
||||||
|
| optional
|
||||||
|
| Array String
|
||||||
|
| default = [],
|
||||||
package_managers
|
package_managers
|
||||||
| doc "Package Managers used in the container. Possible values: dpkg, rpm, pacman, pip, conda"
|
| doc "Package Managers used in the container. Possible values: dpkg, rpm, pacman, pip, conda"
|
||||||
| optional
|
| optional
|
||||||
|
Loading…
Reference in New Issue
Block a user