Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#747: tweak CI image docker startup #1140

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
11 changes: 8 additions & 3 deletions .ci/jenkins/Jenkinsfile.build-kogito-ci-image
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -65,8 +65,13 @@ pipeline {
}
}
steps {
echo 'Init docker'
script {
util.waitForDocker()
}
echo 'Debug basics'
sh '''
sh --version
locale
printenv
'''
Expand Down
13 changes: 11 additions & 2 deletions apache-nodes/Dockerfile.kogito-ci-build
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 5 additions & 3 deletions apache-nodes/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
20 changes: 2 additions & 18 deletions apache-nodes/start-docker.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions apache-nodes/wait-for-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
source wait-for-process.sh

wait_for_process dockerd
19 changes: 19 additions & 0 deletions apache-nodes/wait-for-process.sh
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions dsl/scripts/pr_check.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions dsl/seed/jenkinsfiles/Jenkinsfile.buildchain
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions jenkins-pipeline-shared-libraries/vars/util.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
}