Add entrypoint.sh scripts to allow replacing binaries in containers directly

This commit is contained in:
Michael Hohn
2025-01-14 14:23:58 -08:00
committed by =Michael Hohn
parent 38de5249e7
commit b3563331c2
7 changed files with 105 additions and 27 deletions

View File

@@ -25,11 +25,11 @@ ENV DEBIAN_FRONTEND=noninteractive
ARG CODEQL_VERSION=latest
# Install packages
RUN apt-get update && apt-get install --no-install-recommends --assume-yes \
unzip \
curl \
ca-certificates \
default-jdk
RUN echo 'Acquire::http::Proxy "http://127.0.0.1:3142";' \
> /etc/apt/apt.conf.d/01proxy && \
apt-get update && apt-get install --no-install-recommends --assume-yes \
unzip curl ca-certificates default-jdk && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# If the version is 'latest', lsget the latest release version from GitHub, unzip the bundle into /opt, and delete the archive
RUN if [ "$CODEQL_VERSION" = "latest" ]; then \
@@ -51,6 +51,9 @@ ENV CODEQL_JAVA_HOME=/usr
# Copy the built binary from the builder stage
COPY --from=builder /app/mrvaagent-binary /usr/local/bin/mrvaagent
# Run the agent with the default mode set to container
ENTRYPOINT ["/usr/local/bin/mrvaagent"]
# Copy the binary-replacement support script to the container
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
# Run the agent with the default mode set to container
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

View File

@@ -7,7 +7,7 @@ mrvaagent.tmp:
MAG_TARGET := mrva-agent:0.1.24
mag: mk.mrvaagent
mk.mrvaagent: mrvaagent.tmp
docker build --no-cache -t ${MAG_TARGET} .
docker build --no-cache --network host -t ${MAG_TARGET} .
touch $@
magserve: mag

View File

@@ -3,23 +3,37 @@
#+BEGIN_SRC sh
# Build the container via
cd ~/work-gh/mrva/mrva-docker/containers/agent/
make mk.mrvaagent
# Run the container in standalone mode via
MAG_TARGET=mrva-agent:0.1.24
docker build --no-cache --network host -t ${MAG_TARGET} .
# Run bash in the container in standalone mode
cd ~/work-gh/mrva/mrva-docker/containers/agent/
make magserve
docker run --env-file ../../.env.container --rm -it \
--entrypoint /bin/bash \
${MAG_TARGET}
'
ls /usr/local/bin/
entrypoint.sh mrvaagent
'
#+END_SRC
- Tag the container. This is sufficient for further use on the local machine.
#+BEGIN_SRC sh
docker tag ${MAG_TARGET} ghcr.io/hohn/${MAG_TARGET}
#+END_SRC
- Push this container
#+BEGIN_SRC sh
# Push container
cd ~/work-gh/mrva/mrva-docker/containers/agent/
make mk.mag-push
docker push ghcr.io/hohn/${MAG_TARGET}
#+END_SRC
- Test the registry image
#+BEGIN_SRC sh
# Test pushed container
make mag-test
docker pull ghcr.io/hohn/${MAG_TARGET}
docker run --env-file ../../.env.container --rm -it \
--entrypoint /bin/bash \
${MAG_TARGET}
#+END_SRC

23
containers/agent/entrypoint.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
set -e
# Function to handle termination signals (e.g., SIGTERM)
cleanup() {
echo "Stopping agent..."
kill $PID
wait $PID 2>/dev/null
exit 0
}
# Trap termination signals to clean up properly
trap cleanup SIGTERM SIGINT
# Loop to restart the agent if it stops
while true; do
echo "Starting agent..."
/usr/local/bin/mrvaagent &
PID=$!
wait $PID
echo "Agent stopped. Restarting..."
sleep 1
done

View File

@@ -25,11 +25,11 @@ ENV DEBIAN_FRONTEND=noninteractive
ARG CODEQL_VERSION=latest
# Install packages
RUN apt-get update && apt-get install --no-install-recommends --assume-yes \
unzip \
curl \
ca-certificates \
default-jdk
RUN echo 'Acquire::http::Proxy "http://127.0.0.1:3142";' \
> /etc/apt/apt.conf.d/01proxy && \
apt-get update && apt-get install --no-install-recommends --assume-yes \
unzip curl ca-certificates default-jdk && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# If the version is 'latest', lsget the latest release version from GitHub, unzip the bundle into /opt, and delete the archive
RUN if [ "$CODEQL_VERSION" = "latest" ]; then \
@@ -51,6 +51,9 @@ ENV CODEQL_JAVA_HOME=/usr
# Copy the built binary from the builder stage
COPY --from=builder /app/mrvaserver-binary /usr/local/bin/mrvaserver
# Copy the binary-replacement support script to the container
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
# Run the server with the default mode set to container
ENTRYPOINT ["/usr/local/bin/mrvaserver"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["--mode=container"]

View File

@@ -3,21 +3,33 @@
#+BEGIN_SRC sh
# Build the container via
cd ~/work-gh/mrva/mrva-docker/containers/server/
docker build --no-cache -t mrva-server:0.1.24 .
docker build --no-cache --network host -t mrva-server:0.1.24 .
# The --network host is needed when using ../aptcacher/
# Run the container in standalone mode via
cd ~/work-gh/mrva/mrva-docker/containers/server/
docker run -d mrva-server:0.1.24
docker run --env-file ../../.env.container --rm -it \
-it mrva-server:0.1.24 --mode=container --loglevel=debug \
/bin/bash
# Just run bash in the container
docker run --env-file ../../.env.container --rm -it \
--entrypoint /bin/bash \
mrva-server:0.1.24
# In the container:
'
ls /opt/codeql/codeql
/opt/codeql/codeql version |head -1
CodeQL command-line toolchain release 2.20.1.
'
#+END_SRC
- Tag the container. This is sufficient for further use on the local machine.
#+BEGIN_SRC sh
docker tag mrva-server:0.1.24 ghcr.io/hohn/mrva-server:0.1.24
#+END_SRC
- Push this container
#+BEGIN_SRC sh
# Push container
docker tag mrva-server:0.1.24 ghcr.io/hohn/mrva-server:0.1.24
docker push ghcr.io/hohn/mrva-server:0.1.24
#+END_SRC

23
containers/server/entrypoint.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
set -e
# Function to handle termination signals (e.g., SIGTERM)
cleanup() {
echo "Stopping server..."
kill $PID
wait $PID 2>/dev/null
exit 0
}
# Trap termination signals to clean up properly
trap cleanup SIGTERM SIGINT
# Loop to restart the server if it stops
while true; do
echo "Starting server..."
/usr/local/bin/mrvaserver "$@" &
PID=$!
wait $PID
echo "Server stopped. Restarting..."
sleep 1
done