From bba927d30c832d6acb27a1b47a7e5a5106e211ef Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Wed, 6 Dec 2023 11:44:30 -0500 Subject: [PATCH] Separate building & starting of containers Separate the build step from startup for environment containers. Build step is very slow, and we want to be able to start the containers without rebuilding when troubleshooting Jenkins jobs. TESTS ============================== Run both steps from Jenkins Story: 2010226 Task: 49212 Depends-On: https://review.opendev.org/c/starlingx/tools/+/902792 Signed-off-by: Davlet Panech Change-Id: I3462de0a9550310c931cbed2555de1b3a6bc53f9 --- pipelines/monolithic.Jenkinsfile | 1 + .../parts/build-env-containers.Jenkinsfile | 62 +++++++++++++++++++ pipelines/parts/start-containers.Jenkinsfile | 9 --- scripts/build-env-containers.sh | 37 +++++++++++ scripts/start-containers.sh | 29 ++------- 5 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 pipelines/parts/build-env-containers.Jenkinsfile create mode 100755 scripts/build-env-containers.sh diff --git a/pipelines/monolithic.Jenkinsfile b/pipelines/monolithic.Jenkinsfile index e1e35c0..f4816e4 100644 --- a/pipelines/monolithic.Jenkinsfile +++ b/pipelines/monolithic.Jenkinsfile @@ -280,6 +280,7 @@ or with paths relative to repo root: // Delete or keep packages, aptly state, etc depending on build params runPart ("clean-build") // start containers + runPart ("build-env-containers") runPart ("start-containers") // login to docker early to catch login errors runPart ("docker-login") diff --git a/pipelines/parts/build-env-containers.Jenkinsfile b/pipelines/parts/build-env-containers.Jenkinsfile new file mode 100644 index 0000000..b2b5745 --- /dev/null +++ b/pipelines/parts/build-env-containers.Jenkinsfile @@ -0,0 +1,62 @@ +// vim: syn=groovy + +// +// Copyright (c) 2022 Wind River Systems, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// + +library "common@${params.JENKINS_SCRIPTS_BRANCH}" + +setBuildDescr() + +pipeline { + agent any + options { + timestamps() + } + parameters { + string ( + name: 'MASTER_JOB_NAME' + ) + string ( + name: 'MASTER_BUILD_NUMBER' + ) + string ( + name: 'JENKINS_SCRIPTS_BRANCH' + ) + string ( + name: 'BUILD_HOME', + ) + string ( + name: 'TIMESTAMP' + ) + string ( + name: 'PUBLISH_TIMESTAMP' + ) + booleanParam ( + name: 'SHELL_XTRACE' + ) + booleanParam ( + name: 'REBUILD_BUILDER_IMAGES' + ) + booleanParam ( + name: 'BUILDER_USE_DOCKER_CACHE' + ) + booleanParam ( + name: 'USE_DOCKER_CACHE' + ) + } + stages { + stage ("start-containers") { + steps { + sh ("${Constants.SCRIPTS_DIR}/build-env-containers.sh") + } + } + } + post { + cleanup { + cleanupPartJob() + } + } +} diff --git a/pipelines/parts/start-containers.Jenkinsfile b/pipelines/parts/start-containers.Jenkinsfile index f7961e5..725d31e 100644 --- a/pipelines/parts/start-containers.Jenkinsfile +++ b/pipelines/parts/start-containers.Jenkinsfile @@ -37,15 +37,6 @@ pipeline { booleanParam ( name: 'SHELL_XTRACE' ) - booleanParam ( - name: 'REBUILD_BUILDER_IMAGES' - ) - booleanParam ( - name: 'BUILDER_USE_DOCKER_CACHE' - ) - booleanParam ( - name: 'USE_DOCKER_CACHE' - ) } stages { stage ("start-containers") { diff --git a/scripts/build-env-containers.sh b/scripts/build-env-containers.sh new file mode 100755 index 0000000..7dbdbd3 --- /dev/null +++ b/scripts/build-env-containers.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# +# Copyright (c) 2022 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set -e +source $(dirname "$0")/lib/job_utils.sh + +require_job_env BUILD_HOME +require_job_env REBUILD_BUILDER_IMAGES +require_job_env USE_DOCKER_CACHE + +set -x +load_build_env + +# Check whether we need to login to docker hub +dockerhub_login= +for spec in $DOCKER_REGISTRY_LOGIN_LIST ; do + if [[ "$(parse_docker_registry "$spec" | awk '{print $1}')" == "docker.io" ]] ; then + dockerhub_login="--dockerhub-login" + break + fi +done + +# build or download containers +cache_opts= +if $BUILDER_USE_DOCKER_CACHE ; then + cache_opts="--cache" +fi +rebuild_opts= +if $REBUILD_BUILDER_IMAGES ; then + rebuild_opts="--rebuild" +fi +./stx-init-env $rebuild_opts $cache_opts --no-start $dockerhub_login diff --git a/scripts/start-containers.sh b/scripts/start-containers.sh index 4f91cd8..8d19522 100755 --- a/scripts/start-containers.sh +++ b/scripts/start-containers.sh @@ -10,32 +10,13 @@ set -e source $(dirname "$0")/lib/job_utils.sh require_job_env BUILD_HOME -require_job_env REBUILD_BUILDER_IMAGES -require_job_env USE_DOCKER_CACHE +load_build_env +require_job_env BUILDER_POD_STARTUP_TIMEOUT set -x -load_build_env - -# Check whether we need to login to docker hub -dockerhub_login= -for spec in $DOCKER_REGISTRY_LOGIN_LIST ; do - if [[ "$(parse_docker_registry "$spec" | awk '{print $1}')" == "docker.io" ]] ; then - dockerhub_login="--dockerhub-login" - break - fi -done - -# start containers -if $BUILDER_USE_DOCKER_CACHE ; then - cache_opts="--cache" -fi -if $REBUILD_BUILDER_IMAGES ; then - notice "rebuilding & starting containers" - ./stx-init-env --rebuild $cache_opts $dockerhub_login -else - notice "rebuilding containers" - bash ./stx-init-env $cache_opts $dockerhub_login -fi +stx control stop +stx config --upgrade +stx control start # wait for startup notice "waiting for containers to startup ($BUILDER_POD_STARTUP_TIMEOUT seconds)"