diff --git a/.ci/jenkins/Jenkinsfile.build-kogito-ci-image b/.ci/jenkins/Jenkinsfile.build-kogito-ci-image index c86ec42ae..af1b45dca 100644 --- a/.ci/jenkins/Jenkinsfile.build-kogito-ci-image +++ b/.ci/jenkins/Jenkinsfile.build-kogito-ci-image @@ -1,12 +1,12 @@ import org.jenkinsci.plugins.workflow.libs.Library -@Library('jenkins-pipeline-shared-libraries')_ - pipeline { agent { label 'ubuntu' } - + libraries { + lib("jenkins-pipeline-shared-libraries@${BRANCH_NAME}") + } environment { DOCKER_CONFIG = "${WORKSPACE}/.docker" @@ -65,8 +65,13 @@ pipeline { } } steps { + echo 'Init docker' + script { + util.waitForDocker() + } echo 'Debug basics' sh ''' + sh --version locale printenv ''' diff --git a/apache-nodes/Dockerfile.kogito-ci-build b/apache-nodes/Dockerfile.kogito-ci-build index fbe793b75..cf9eddd04 100644 --- a/apache-nodes/Dockerfile.kogito-ci-build +++ b/apache-nodes/Dockerfile.kogito-ci-build @@ -157,10 +157,19 @@ ENV CONTAINER_ENGINE_TLS_OPTIONS="" WORKDIR /project/directory USER root -COPY start-docker.sh entrypoint.sh /usr/local/bin/ +COPY start-docker.sh wait-for-docker.sh wait-for-process.sh entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/start-docker.sh \ - /usr/local/bin/entrypoint.sh + /usr/local/bin/entrypoint.sh \ + /usr/local/bin/wait-for-docker.sh \ + /usr/local/bin/wait-for-process.sh USER nonrootuser +RUN echo "source wait-for-docker.sh" >> ~/.bashrc + +# Use bash as default instead of dash (BEGIN) +RUN sudo bash -c "echo \"dash dash/sh boolean false\" | debconf-set-selections" +RUN sudo bash -c "DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash" +# Use bash as default instead of dash (END) + ENTRYPOINT ["entrypoint.sh"] CMD ["bash"] diff --git a/apache-nodes/entrypoint.sh b/apache-nodes/entrypoint.sh index a12477418..61d79e220 100755 --- a/apache-nodes/entrypoint.sh +++ b/apache-nodes/entrypoint.sh @@ -1,11 +1,9 @@ #!/bin/bash set -e -# Start docker -start-docker.sh # cgroup v2: enable nesting if [ -f /sys/fs/cgroup/cgroup.controllers ]; then - echo "in cgroupv2 branch" + echo "in cgroupv2 branch" # move the processes from the root group to the /init group, # otherwise writing subtree_control fails with EBUSY. # An error during moving non-existent process (i.e., "cat") is ignored. @@ -15,6 +13,10 @@ if [ -f /sys/fs/cgroup/cgroup.controllers ]; then sudo bash -c "sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers > /sys/fs/cgroup/cgroup.subtree_control" fi +# Start docker and print logs +start-docker.sh + +# process the command passed, after docker is started if [ $# -gt 0 ]; then exec "$@" fi \ No newline at end of file diff --git a/apache-nodes/start-docker.sh b/apache-nodes/start-docker.sh index bebdf338c..9b1422d9a 100755 --- a/apache-nodes/start-docker.sh +++ b/apache-nodes/start-docker.sh @@ -1,31 +1,15 @@ #!/bin/bash source /opt/bash-utils/logger.sh -function wait_for_process () { - local max_time_wait=30 - local process_name="$1" - local waited_sec=0 - while ! pgrep "$process_name" >/dev/null && ((waited_sec < max_time_wait)); do - INFO "Process $process_name is not running yet. Retrying in 1 seconds" - INFO "Waited $waited_sec seconds of $max_time_wait seconds" - sleep 1 - ((waited_sec=waited_sec+1)) - if ((waited_sec >= max_time_wait)); then - return 1 - fi - done - sudo chown root:docker /var/run/docker.sock - return 0 -} - INFO "Starting supervisor" sudo bash -c "/usr/bin/supervisord >> /dev/null 2>&1" & INFO "Waiting for docker to be running" -wait_for_process dockerd +source wait-for-docker.sh if [ $? -ne 0 ]; then ERROR "dockerd is not running after max time" exit 1 else + sudo chown root:docker /var/run/docker.sock INFO "dockerd is running" fi \ No newline at end of file diff --git a/apache-nodes/wait-for-docker.sh b/apache-nodes/wait-for-docker.sh new file mode 100644 index 000000000..ee636f9c3 --- /dev/null +++ b/apache-nodes/wait-for-docker.sh @@ -0,0 +1,4 @@ +#!/bin/bash +source wait-for-process.sh + +wait_for_process dockerd \ No newline at end of file diff --git a/apache-nodes/wait-for-process.sh b/apache-nodes/wait-for-process.sh new file mode 100644 index 000000000..9cfc0a8dc --- /dev/null +++ b/apache-nodes/wait-for-process.sh @@ -0,0 +1,19 @@ +#!/bin/bash +source /opt/bash-utils/logger.sh +set -e +function wait_for_process () { + local max_time_wait=30 + local process_name="$1" + local waited_sec=0 + while ! pgrep "$process_name" >/dev/null && ((waited_sec < max_time_wait)); do + INFO "Process $process_name is not running yet. Retrying in 1 seconds" + INFO "Waited $waited_sec seconds of $max_time_wait seconds" + sleep 1 + ((waited_sec=waited_sec+1)) + if ((waited_sec >= max_time_wait)); then + return 1 + fi + done + INFO "Process $process_name successfully started." + return 0 +} \ No newline at end of file diff --git a/dsl/scripts/pr_check.groovy b/dsl/scripts/pr_check.groovy index 59b5ec6ba..49ab0fef3 100644 --- a/dsl/scripts/pr_check.groovy +++ b/dsl/scripts/pr_check.groovy @@ -40,8 +40,9 @@ void launch() { void launchInDocker(String builderImage) { docker.image(builderImage).inside(dockerArgs.join(' ')) { - // Debug. To be removed in the future - sh "printenv" + sh 'printenv > env_props' + archiveArtifacts artifacts: 'env_props' + util.waitForDocker() sh 'ls -last /var/run/docker.sock' try { launchStages() diff --git a/dsl/seed/jenkinsfiles/Jenkinsfile.buildchain b/dsl/seed/jenkinsfiles/Jenkinsfile.buildchain index d0a7e9db8..912a3e681 100644 --- a/dsl/seed/jenkinsfiles/Jenkinsfile.buildchain +++ b/dsl/seed/jenkinsfiles/Jenkinsfile.buildchain @@ -62,6 +62,7 @@ pipeline { script { sh 'printenv > env_props' archiveArtifacts artifacts: 'env_props' + util.waitForDocker() sh 'ls -last /var/run/docker.sock' if (mavenDeployArtifacts) { diff --git a/jenkins-pipeline-shared-libraries/vars/util.groovy b/jenkins-pipeline-shared-libraries/vars/util.groovy index 30e00587f..94ba17e23 100644 --- a/jenkins-pipeline-shared-libraries/vars/util.groovy +++ b/jenkins-pipeline-shared-libraries/vars/util.groovy @@ -547,3 +547,11 @@ String displayDurationFromSeconds(int durationInSec) { result += "${seconds}s" return result } + +/** + * Method to wait for dockerd to be started. Put in initial pipeline stages to make sure all starts in time. + */ +void waitForDocker() { + sleep(10) // give it some ahead time not to invoke docker exec immediately after container start + sh 'wait-for-docker.sh' // script in kogito-ci-build image itself put in /usr/local/bin +}