Skip to content

Commit

Permalink
Puts pull-mechanism for build images into inside_container() and also…
Browse files Browse the repository at this point in the history
… applies to build-cmk-distro-package

CMK-20968

Change-Id: I3818eab61626c06f5afcd1ae857051ebe16f3b70
  • Loading branch information
Frans Fürst committed Jan 2, 2025
1 parent b193c6e commit 119f54e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 1 addition & 7 deletions buildscripts/scripts/build-cmk-distro-package.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ def main() {
}
}

stage("Pull distro image") {
shout("Pull distro image");
docker.withRegistry(DOCKER_REGISTRY, 'nexus') {
docker.image("${distro}:${docker_tag}").pull();
}
}

stage("(lock resources)") {
lock(label: "bzl_lock_${env.NODE_NAME.split('\\.')[0].split('-')[-1]}", quantity: 1, resource : null) {
def package_name = {
Expand All @@ -131,6 +124,7 @@ def main() {
// if that didn't work falls back to the fully qualified name
inside_container(
image: docker.image("${docker_registry_no_http}/${distro}:${docker_tag}"),
pull: true,
args: [
"--name ${container_name}",
" --hostname ${distro}",
Expand Down
7 changes: 2 additions & 5 deletions buildscripts/scripts/build-cmk-packages.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,21 @@ def main() {

lock(label: 'bzl_lock_' + env.NODE_NAME.split("\\.")[0].split("-")[-1], quantity: 1, resource : null) {
docker.withRegistry(DOCKER_REGISTRY, 'nexus') {
def build_image = docker.image("${docker_registry_no_http}/${distro}:${docker_tag}");
/// we need to pull the image because `inside_container` runs `docker inspect`
/// before we could have pulled the image using `--pull always`
build_image.pull();
// For the package build we need a higher ulimit
// * Bazel opens many files which can lead to crashes
// * See CMK-12159
inside_container(
// supplying the registry explicitly might not be needed but it looks like image.inside() will
// first try to use the image without registry and only if that didn't work falls back to the
// fully qualified name
image: build_image,
image: docker.image("${docker_registry_no_http}/${distro}:${docker_tag}"),
args: [
"--ulimit nofile=16384:32768",
"-v ${checkout_dir}:${checkout_dir}:ro",
"--hostname ${distro}",
],
init: true,
pull: true,
) {
stage("${distro} initialize workspace") {
cleanup_directory("${WORKSPACE}/versions");
Expand Down
5 changes: 5 additions & 0 deletions buildscripts/scripts/utils/docker_image_aliases_helper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ inside_container = {Map arg1=[:], Closure arg2 ->
def image = args.image ?: docker_reference_image();
def privileged = args.get("priviliged", false).asBoolean();
def init = args.get("init", false).asBoolean();
def pull = args.get("pull", false).asBoolean();
def mount_reference_repo = args.get("mount_reference_repo", true).asBoolean();
def mount_credentials = args.get("mount_credentials", false).asBoolean();
def set_docker_group_id = args.get("set_docker_group_id", false).asBoolean();
Expand All @@ -73,6 +74,10 @@ inside_container = {Map arg1=[:], Closure arg2 ->
// calling `image_distro()` has to be done inside `withRegistry` in order to
// have `image.imageName()` contain the registry
docker.withRegistry(DOCKER_REGISTRY, "nexus") {
/// we don't just use `--pull always` here, because we also need it for `image_distro()`
if (pull && args.image) {
args.image.pull();
}
// We need to separate the mounts into the container distro-wise, at least for the following tools
// - pipenv pip's wheel cache does not separate its cache in terms of platform/distro, see:
// https://github.com/pypa/pip/issues/5453
Expand Down

0 comments on commit 119f54e

Please sign in to comment.