Skip to content

Commit e7d2a9e

Browse files
authored
fix(docker): Multi does not launch a second Jenkins controller anymore. (#792)
* fix(docker): Multi does not launch a second Jenkins controller anymore. * fix(docker): The single quotes prevent $JENKINS_CONTROLLER from being expanded. * fix(docker): Improve the fallback mechanism implementation. * fix(docker): Adding error handling for when both controllers are unreachable. And making the timeout duration configurable. * fix(ga): Follows the official documentation for the action https://github.com/docker/login-action?tab=readme-ov-file#github-container-registry
1 parent 09d28e1 commit e7d2a9e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

.github/workflows/github-docker-registry-push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ jobs:
9191
uses: docker/login-action@v3
9292
with:
9393
registry: ghcr.io
94-
username: ${{ env.GHCR_USERNAME }}
95-
password: ${{ env.GHCR_TOKEN }}
94+
username: ${{ github.actor }}
95+
password: ${{ secrets.GITHUB_TOKEN }}
9696

9797
- name: Extract branch name
9898
# This step extracts the branch name

docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ services:
5959
- python
6060
- node
6161
- android
62-
- multi
6362
- golang
6463
- default
6564
# The CASC_RELOAD_TOKEN environment variable is used by the Jenkins controller to restart the Configuration as Code (JCasc) plugin configuration.

dockerfiles/agent-discovery/find-name.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,31 @@ while true; do
7979
sleep 2 # Wait for 5 seconds before the next iteration of the loop.
8080
done
8181

82+
# Check if jenkins_controller is reachable, otherwise fall back to multi_jenkins_controller
83+
JENKINS_CONTROLLER="jenkins_controller"
84+
if ! curl -s -f "http://${JENKINS_CONTROLLER}:8080/login" > /dev/null; then
85+
echo "Primary controller not reachable, falling back to multi controller..."
86+
JENKINS_CONTROLLER="multi_jenkins_controller"
87+
if ! curl -s -f "http://${JENKINS_CONTROLLER}:8080/login" > /dev/null; then
88+
echo "Error: Neither primary nor multi controller is reachable"
89+
exit 1
90+
fi
91+
fi
92+
8293
# Check If Jenkins is running or not
8394
# If the message is found, awk exits with a non-zero status (1), and the loop continues.
8495
# If the message is not found, the loop exits, and the "Jenkins is running" message is displayed.
85-
timeout 60 bash -c 'until curl -s -f http://jenkins_controller:8080/login > /dev/null; do sleep 5; done' && echo "Jenkins is running" || echo "Jenkins is not running"
96+
timeout 60 bash -c "until curl -s -f http://${JENKINS_CONTROLLER}:8080/login > /dev/null; do sleep 5; done" && echo "Jenkins is running" || echo "Jenkins is not running"
97+
# The colon (:) is a no-op command in Bash, which means it does nothing and always returns a true exit status. It is often used as a placeholder or to evaluate expressions without executing any commands.
98+
# The ${JENKINS_STARTUP_TIMEOUT:=60} part is a parameter expansion. It checks if the JENKINS_STARTUP_TIMEOUT variable is set and not null. If it is not set, it assigns the value 60 to JENKINS_STARTUP_TIMEOUT
99+
: "${JENKINS_STARTUP_TIMEOUT:=60}" # Default to 60 seconds if not set
100+
timeout "${JENKINS_STARTUP_TIMEOUT}" bash -c "until curl -s -f http://${JENKINS_CONTROLLER}:8080/login > /dev/null; do sleep 5; done" && echo "Jenkins is running" || echo "Jenkins is not running"
101+
86102
echo "Jenkins is ready"
87103
# Get the Jenkins version
88-
JENKINS_VERSION=$(curl -s -I -k http://admin:admin@jenkins_controller:8080 | grep -i '^X-Jenkins:' | awk '{print $2}')
104+
JENKINS_VERSION=$(curl -s -I -k http://admin:admin@$JENKINS_CONTROLLER:8080 | grep -i '^X-Jenkins:' | awk '{print $2}')
89105
echo "Jenkins version is: $JENKINS_VERSION"
90106

91107
# Use the token in the curl command to reload the configuration
92-
# curl -X POST "http://admin:admin@jenkins_controller:8080/reload-configuration-as-code/?casc-reload-token=$JCASC_TOKEN"
93-
curl -X POST "http://admin:admin@jenkins_controller:8080/reload-configuration-as-code/?casc-reload-token=thisisnotsecure"
108+
# curl -X POST "http://admin:admin@$JENKINS_CONTROLLER:8080/reload-configuration-as-code/?casc-reload-token=$JCASC_TOKEN"
109+
curl -X POST "http://admin:admin@$JENKINS_CONTROLLER:8080/reload-configuration-as-code/?casc-reload-token=thisisnotsecure"

0 commit comments

Comments
 (0)