Skip to content

Commit 2f21ada

Browse files
authored
CLOUDP-331886 - add new agent binaries as base (#292)
# Summary - those scripts are required for agent matrix removal. They are placed here - since we overwrite the tag and this would race with the images created in other e2e tests ### Dockerfile updates: * Updated `docker/mongodb-agent-non-matrix/Dockerfile` to copy new scripts (`agent-launcher-shim.sh`, `setup-agent-files.sh`, `dummy-probe.sh`, `dummy-readinessprobe.sh`) into the container at build time. These scripts are placed in `/usr/local/bin` for execution. * Updated `docker/mongodb-agent-non-matrix/Dockerfile.builder` to include the same script files in the build process, ensuring they are available in the image. ### New scripts added: * [`agent-launcher-shim.sh`](diffhunk://#diff-7050c43142cef16fa7268fd7d1356e96bdf5de2c8bc0d050f277babee01a397cR1-R31): A script to initialize the agent launcher by setting up agent files and starting the launcher if the required script is found. * [`setup-agent-files.sh`](diffhunk://#diff-fbe2cd71b8fc58242e04e18562c58b1085f6b059dce42d94a2f4e5cbdf7a3469R1-R95): A script to set up dummy probe scripts initially, wait for an init container to provide real probe and launcher scripts, and replace the dummy scripts with the real ones. * [`dummy-probe.sh`](diffhunk://#diff-ff81b0610fd08dd2d32bcbe72c0d78fb402d5f6dbe8a388bad94c7cdf9b95e3bR1-R5): A dummy liveness probe script that always returns success to keep the container alive during the setup process. * [`dummy-readinessprobe.sh`](diffhunk://#diff-4378f36df04937eb7473771a47dc6ac5a424ec8ffdb171e201b9fc8052a54c26R1-R5): A dummy readiness probe script that always returns a "not ready" status until the real probe script is available. ## Proof of Work - not used anywhere, ci needs to pass - used by this pr (that contains more information on how its used): #267 ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes?
1 parent 2988311 commit 2f21ada

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

docker/mongodb-agent-non-matrix/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ COPY --from=base /data/mongodb-agent.tar.gz /agent
5555
COPY --from=base /data/mongodb-tools.tgz /agent
5656
COPY --from=base /data/LICENSE /licenses/LICENSE
5757

58+
# Copy scripts to a safe location that won't be overwritten by volume mount
59+
COPY --from=base /opt/scripts/agent-launcher-shim.sh /usr/local/bin/agent-launcher-shim.sh
60+
COPY --from=base /opt/scripts/setup-agent-files.sh /usr/local/bin/setup-agent-files.sh
61+
COPY --from=base /opt/scripts/dummy-probe.sh /usr/local/bin/dummy-probe.sh
62+
COPY --from=base /opt/scripts/dummy-readinessprobe.sh /usr/local/bin/dummy-readinessprobe
63+
5864
RUN tar xfz /agent/mongodb-agent.tar.gz \
5965
&& mv mongodb-mms-automation-agent-*/mongodb-mms-automation-agent /agent/mongodb-agent \
6066
&& chmod +x /agent/mongodb-agent \

docker/mongodb-agent-non-matrix/Dockerfile.builder

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ ADD https://mciuploads.s3.amazonaws.com/mms-automation/mongodb-mms-build-agent/b
99
ADD https://downloads.mongodb.org/tools/db/mongodb-database-tools-${tools_distro}-${tools_version}.tgz /data/mongodb-tools.tgz
1010

1111
COPY ./docker/mongodb-kubernetes-init-database/content/LICENSE /data/LICENSE
12+
COPY ./docker/mongodb-agent/agent-launcher-shim.sh /opt/scripts/agent-launcher-shim.sh
13+
COPY ./docker/mongodb-agent/setup-agent-files.sh /opt/scripts/setup-agent-files.sh
14+
COPY ./docker/mongodb-agent/dummy-probe.sh /opt/scripts/dummy-probe.sh
15+
COPY ./docker/mongodb-agent/dummy-readinessprobe.sh /opt/scripts/dummy-readinessprobe.sh
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPTS_DIR="/opt/scripts"
5+
6+
# Function to start the agent launcher
7+
start_agent_launcher() {
8+
echo "Starting agent launcher..."
9+
echo "Final contents of $SCRIPTS_DIR:"
10+
ls -la "$SCRIPTS_DIR"
11+
12+
if [[ -f "$SCRIPTS_DIR/agent-launcher.sh" ]]; then
13+
echo "Found agent-launcher.sh, executing..."
14+
exec "$SCRIPTS_DIR/agent-launcher.sh"
15+
else
16+
echo "ERROR: agent-launcher.sh not found"
17+
exit 1
18+
fi
19+
}
20+
21+
main() {
22+
echo "Running setup-agent-files.sh..."
23+
if ! /usr/local/bin/setup-agent-files.sh; then
24+
echo "ERROR: Failed to set up agent files"
25+
exit 1
26+
fi
27+
28+
start_agent_launcher
29+
}
30+
31+
main "$@"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
# Dummy liveness probe that returns success to keep container alive during script copying
3+
# This prevents container from being killed while waiting for real probe scripts
4+
echo "Using dummy liveness probe - keeping container alive until real probe script is copied"
5+
exit 0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
# Dummy readiness probe that returns NOT READY until real probe is copied
3+
# Container should not be marked ready until real probe scripts are available
4+
echo "Using dummy readiness probe - container not ready until real probe script is copied"
5+
exit 1
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPTS_DIR="/opt/scripts"
5+
6+
# Set up dummy probe scripts
7+
# liveness always returns success
8+
# readiness always returns failure
9+
setup_dummy_probes() {
10+
echo "Setting up dummy probe scripts..."
11+
cp /usr/local/bin/dummy-probe.sh "$SCRIPTS_DIR/probe.sh"
12+
cp /usr/local/bin/dummy-readinessprobe "$SCRIPTS_DIR/readinessprobe"
13+
echo "Dummy probe scripts ready"
14+
}
15+
16+
# wait max 5m for init container to be ready
17+
find_init_container() {
18+
for i in {1..150}; do
19+
local pid
20+
pid=$(pgrep -f "agent-utilities-holder_marker" | head -n1)
21+
if [[ -n "$pid" && -d "/proc/$pid/root/scripts" ]]; then
22+
echo "$pid"
23+
return 0
24+
fi
25+
echo "Waiting for init container... (attempt $i)" >&2
26+
sleep 2
27+
done
28+
return 1
29+
}
30+
31+
link_agent_scripts() {
32+
local init_scripts_dir="$1"
33+
34+
echo "Linking agent launcher scripts..."
35+
for script in agent-launcher.sh agent-launcher-lib.sh; do
36+
ln -sf "$init_scripts_dir/$script" "$SCRIPTS_DIR/$script"
37+
echo "Linked $script"
38+
done
39+
}
40+
41+
# Link probe scripts from init container, replacing dummy ones
42+
link_probe_scripts() {
43+
local init_probes_dir="$1"
44+
45+
echo "Linking probe scripts..."
46+
for probe in probe.sh readinessprobe; do
47+
if [[ -f "$init_probes_dir/$probe" ]]; then
48+
ln -sf "$init_probes_dir/$probe" "$SCRIPTS_DIR/$probe"
49+
echo "Replaced dummy $probe with real one"
50+
else
51+
echo "WARNING: $probe not found in init container"
52+
exit 1
53+
fi
54+
done
55+
}
56+
57+
# Main function to set up all files
58+
main() {
59+
setup_dummy_probes
60+
61+
if init_pid=$(find_init_container); then
62+
echo "Found init container with PID: $init_pid"
63+
64+
init_root="/proc/$init_pid/root"
65+
init_scripts="$init_root/scripts"
66+
init_probes="$init_root/probes"
67+
68+
# Verify scripts directory exists
69+
if [[ ! -d "$init_scripts" ]]; then
70+
echo "ERROR: Scripts directory $init_scripts not found"
71+
exit 1
72+
fi
73+
74+
# Verify probes directory exists
75+
if [[ ! -d "$init_probes" ]]; then
76+
echo "ERROR: Probes directory $init_probes not found"
77+
exit 1
78+
fi
79+
80+
# Link scripts from init container
81+
link_agent_scripts "$init_scripts"
82+
link_probe_scripts "$init_probes"
83+
84+
echo "File setup completed successfully"
85+
exit 0
86+
else
87+
echo "No init container found"
88+
exit 1
89+
fi
90+
}
91+
92+
# Only run main if script is executed directly
93+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
94+
main "$@"
95+
fi

0 commit comments

Comments
 (0)