Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Mar 16, 2022
1 parent f700e72 commit 98256b0
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
108 changes: 108 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ tvm_multilib_tsim = 'build/libvta_tsim.so, ' +

// command to start a docker container
docker_run = 'docker/bash.sh'
docker_build = 'docker/build.sh'
// timeout in minutes
max_time = 240
needs_relint = false
rebuild_docker_images = true

def per_exec_ws(folder) {
return "workspace/exec_${env.EXECUTOR_NUMBER}/" + folder
Expand Down Expand Up @@ -205,6 +208,16 @@ stage('Sanity Check') {
)
skip_ci = should_skip_ci(env.CHANGE_ID)
skip_slow_tests = should_skip_slow_tests(env.CHANGE_ID)
found_docker_changes = sh(
returnStatus: true,
script: 'git diff --no-commit-id --name-only -r origin/main | grep -q "docker/"',
label: 'Check for docker/ changes'
)
rebuild_docker_images = found_docker_changes == 0
rebuild_docker_images = true
if (rebuild_docker_images) {
return
}
sh (
script: "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh",
label: 'Run lint',
Expand All @@ -214,6 +227,101 @@ stage('Sanity Check') {
}
}

def build_image(image_name) {
hash = sh(
returnStdout: true,
script: 'git log -1 --format=\'%h\''
).trim()
hash = "${env.BRANCH_NAME}-${hash}"
sh(
script: "${docker_build} ${image_name} --spec ${image_name}:${hash}",
label: 'Building docker image'
)
sh "echo NYI: Uploading docker image to registry..."
}

if (rebuild_docker_images) {
stage('Docker') {
// TODO in a follow up PR: Upload to ECR, find tag and use in
// subsequent builds
parallel 'ci-lint': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_lint')
}
}
}, 'ci-cpu': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_cpu')
}
}
}, 'ci-gpu': {
node('GPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_gpu')
}
}
}, 'ci-qemu': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_qemu')
}
}
}, 'ci-i386': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_i386')
}
}
}, 'ci-arm': {
node('ARM') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_arm')
}
}
}, 'ci-wasm': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_wasm')
}
}
}, 'ci-hexagon': {
node('CPU') {
timeout(time: max_time, unit: 'MINUTES') {
init_git()
build_image('ci_hexagon')
}
}
}
}
TODO: Once we are able to use the built images, enable this step
// If the docker images changed, we need to run the image build before the lint
// can run since it requires a base docker image. Most of the time the images
// aren't build though so it's faster to use the same node that checks for
// docker changes to run the lint in the usual case.
stage('Sanity Check (re-run)') {
timeout(time: max_time, unit: 'MINUTES') {
node('CPU') {
ws(per_exec_ws('tvm/sanity')) {
init_git()
sh "exit 1" // TODO: Kill the build
sh (
script: "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh",
label: 'Run lint',
)
}
}
}
}
}

// Run make. First try to do an incremental make from a previous workspace in hope to
// accelerate the compilation. If something is wrong, clean the workspace and then
Expand Down
13 changes: 13 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# [--dockerfile <DOCKERFILE_PATH>] [-it]
# [--net=host] [--cache-from <IMAGE_NAME>]
# [--name CONTAINER_NAME] [--context-path <CONTEXT_PATH>]
# [--spec DOCKER_IMAGE_SPEC]
# [<COMMAND>]
#
# CONTAINER_TYPE: Type of the docker container used the run the build,
Expand All @@ -36,6 +37,9 @@
# this optional value is not supplied (via the --dockerfile
# flag), will use Dockerfile.CONTAINER_TYPE in default
#
# DOCKER_IMAGE_SPEC: Override the default logic to determine the image name and
# tag
#
# IMAGE_NAME: An image to be as a source for cached layers when building the
# Docker image requested.
#
Expand Down Expand Up @@ -73,6 +77,11 @@ if [[ "$1" == "-it" ]]; then
shift 1
fi

if [[ "$1" == "--spec" ]]; then
OVERRIDE_IMAGE_SPEC="$2"
shift 2
fi

if [[ "$1" == "--net=host" ]]; then
CI_DOCKER_EXTRA_PARAMS+=('--net=host')
CI_DOCKER_BUILD_EXTRA_PARAMS+=("--network=host")
Expand Down Expand Up @@ -162,6 +171,10 @@ DOCKER_IMG_NAME=$(echo "${DOCKER_IMG_NAME}" | tr '[:upper:]' '[:lower:]')
# Compose the full image spec with "name:tag" e.g. "tvm.ci_cpu:v0.03"
DOCKER_IMG_SPEC="${DOCKER_IMG_NAME}:${DOCKER_IMAGE_TAG}"

if [[ -n ${OVERRIDE_IMAGE_SPEC+x} ]]; then
DOCKER_IMG_SPEC="$OVERRIDE_IMAGE_SPEC"
fi

# Print arguments.
echo "WORKSPACE: ${WORKSPACE}"
echo "CI_DOCKER_EXTRA_PARAMS: ${CI_DOCKER_EXTRA_PARAMS[@]}"
Expand Down

0 comments on commit 98256b0

Please sign in to comment.