Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,6 @@ gallery/how_to/work_with_microtvm/micro_tvmc.py

# Test sample data files
!tests/python/ci/sample_prs/*.json

# Used in CI to communicate between Python and Jenkins
.docker-image-names/
75 changes: 60 additions & 15 deletions Jenkinsfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jenkins/Deploy.groovy.j2
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def deploy() {
}
}
}
if (env.BRANCH_NAME == 'main' && env.DEPLOY_DOCKER_IMAGES == 'yes' && rebuild_docker_images && upstream_revision != null) {
if (env.BRANCH_NAME == 'main' && env.PUSH_DOCKER_IMAGES == 'yes' && rebuild_docker_images && upstream_revision != null) {
node('CPU') {
ws({{ m.per_exec_ws('tvm/deploy-docker') }}) {
try {
Expand Down
28 changes: 20 additions & 8 deletions jenkins/Prepare.groovy.j2
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ def prepare() {
{{ image.name }} = params.{{ image.name }}_param ?: {{ image.name }}
{% endfor %}

sh (script: """
echo "Docker images being used in this build:"
{% for image in images %}
echo " {{ image.name }} = ${ {{- image.name -}} }"
{% endfor %}
""", label: 'Docker image names')

is_docs_only_build = sh (
returnStatus: true,
script: './tests/scripts/git_change_docs.sh',
Expand All @@ -161,13 +154,32 @@ def prepare() {
skip_slow_tests = should_skip_slow_tests(env.CHANGE_ID)
rebuild_docker_images = sh (
returnStatus: true,
script: './tests/scripts/git_change_docker.sh',
script: './tests/scripts/should_rebuild_docker.py',
label: 'Check for any docker changes',
)
if (skip_ci) {
// Don't rebuild when skipping CI
rebuild_docker_images = false
}
if (!rebuild_docker_images) {
// Pull image names from the results of should_rebuild_docker.py
if (env.USE_AUTOUPDATED_DOCKER_IMAGES == 'yes') {
{% for image in images %}
{{ image.name }} = sh(
script: "cat .docker-image.names/{{ image.name }}",
label: "Find docker image name for {{ image.name }}",
returnStdout: true,
).trim()
{% endfor %}
}
}

sh (script: """
echo "Docker images being used in this build:"
{% for image in images %}
echo " {{ image.name }} = ${ {{- image.name -}} }"
{% endfor %}
""", label: 'Docker image names')
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions tests/scripts/should_rebuild_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@


from http_utils import get
from cmd_utils import Sh, init_log
from cmd_utils import Sh, init_log, REPO_ROOT


DOCKER_API_BASE = "https://hub.docker.com/v2/"
DOCKER_USER = "tlcpack"
PAGE_SIZE = 25
TEST_DATA = None

Expand Down Expand Up @@ -111,7 +112,9 @@ def find_commit_in_repo(tags: List[Dict[str, Any]]):

def main():
# Fetch all tlcpack images
images = docker_api("repositories/tlcpack")
images = docker_api(f"repositories/{DOCKER_USER}")
NAMES_DIR = REPO_ROOT / ".docker-image-names"
NAMES_DIR.mkdir(exist_ok=True)

# Ignore all non-ci images
relevant_images = [image for image in images["results"] if image["name"].startswith("ci-")]
Expand All @@ -120,7 +123,7 @@ def main():

for image in relevant_images:
# Check the tags for the image
tags = docker_api(f"repositories/tlcpack/{image['name']}/tags")
tags = docker_api(f"repositories/{DOCKER_USER}/{image['name']}/tags")

# Find the hash of the most recent tag
shorthash, tag = find_commit_in_repo(tags)
Expand All @@ -132,6 +135,11 @@ def main():
logging.info(f"Found docker changes from {shorthash} when checking {name}")
logging.info(diff)
exit(2)
else:
fullname = f"{DOCKER_USER}/{image['name']}:{name}"
logging.info(f"Using image {fullname} for {image}")
with open(NAMES_DIR / image["name"], "w") as f:
f.write(fullname)

logging.info("Did not find changes, no rebuild necessary")
exit(0)
Expand All @@ -140,7 +148,8 @@ def main():
if __name__ == "__main__":
init_log()
parser = argparse.ArgumentParser(
description="Exits 0 if Docker images don't need to be rebuilt, 1 otherwise"
description="Exits 0 if Docker images don't need to be rebuilt, 1 otherwise. "
"If 0, image names will be written to a .docker-image-names folder"
)
parser.add_argument(
"--testing-docker-data",
Expand Down