+21
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import hashlib
|
||||
import os
|
||||
import pathlib
|
||||
import shlex
|
||||
@@ -136,6 +137,9 @@ RUN python -m pip install --no-cache-dir conan=={CONAN_VERSION}
|
||||
WORKDIR /workspace
|
||||
"""
|
||||
|
||||
def build_requirements_digest():
|
||||
return hashlib.sha256((repo_root() / "tools/requirements.txt").read_bytes()).hexdigest()
|
||||
|
||||
def product_build_dockerfile():
|
||||
return f"""FROM {DEFAULT_BUILD_BASE_IMAGE}
|
||||
|
||||
@@ -202,6 +206,8 @@ COPY tools/requirements.txt /tmp/vamp-build-requirements.txt
|
||||
RUN python -m pip install --no-cache-dir \\
|
||||
conan=={CONAN_VERSION} -r /tmp/vamp-build-requirements.txt
|
||||
|
||||
LABEL org.khodo.product-vamp.build-requirements="{build_requirements_digest()}"
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
RUN mkdir -p /opt && touch /opt/modulus-build-image
|
||||
@@ -482,6 +488,19 @@ def delegate(command, argv):
|
||||
ensure_runtime(root)
|
||||
sys.path.insert(0, str(root / RUNTIME_DIR))
|
||||
import modulus.cli
|
||||
original_image_available = modulus.cli.docker_image_available
|
||||
|
||||
def current_build_image(context):
|
||||
if not original_image_available(context):
|
||||
return False
|
||||
inspected = subprocess.run(
|
||||
["docker", "image", "inspect", context.docker_image, "--format",
|
||||
'{{index .Config.Labels "org.khodo.product-vamp.build-requirements"}}'],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
return inspected.returncode == 0 and inspected.stdout.strip() == build_requirements_digest()
|
||||
|
||||
modulus.cli.docker_image_available = current_build_image
|
||||
original_docker_run = modulus.cli.docker_run
|
||||
|
||||
def docker_run_with_host_socket(context, command, docker_args=None, env_overrides=None):
|
||||
@@ -502,6 +521,8 @@ def delegate(command, argv):
|
||||
try:
|
||||
return modulus.cli.main(command)
|
||||
finally:
|
||||
modulus.cli.docker_image_available = original_image_available
|
||||
modulus.cli.docker_run = original_docker_run
|
||||
os.chdir(previous_cwd)
|
||||
sys.argv = previous_argv
|
||||
|
||||
|
||||
Reference in New Issue
Block a user