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

Add supervisor to Dockerfile for process management #338

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
87 changes: 87 additions & 0 deletions .github/workflows/docker-supervisor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Test Dockerfile with supervisor and without supervisor

on: [push]
env:
DEBUG: true

jobs:
test-docker-builds:
runs-on: ubuntu-latest
strategy:
matrix:
supervisor: [ true, false]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Download the latest version of Ant Media Server
run: curl -L -o ant-media-server-community.zip $(curl -s https://api.github.com/repos/ant-media/Ant-Media-Server/releases/latest | grep "browser_download_url" | cut -d '"' -f 4)

- name: Build with Supervisor=${{ matrix.supervisor }}
run: |
docker build -f docker/Dockerfile_Process \
--build-arg UseSupervisor=${{ matrix.supervisor }} \
--build-arg AntMediaServer=ant-media-server-community.zip \
-t antmedia:${{ matrix.supervisor }} .

- name: Test Container (Supervisor=${{ matrix.supervisor }})
run: |
docker images
docker run -d -p 5080:5080 --name antmedia-${{ matrix.supervisor }} antmedia:${{ matrix.supervisor }}
docker ps -a
docker logs antmedia-${{ matrix.supervisor }}
sleep 30
docker ps
AMS_PID=$(docker exec antmedia-${{ matrix.supervisor }} pgrep -f "antmedia")
if [ "${{ matrix.supervisor }}" = "true" ]; then
# With supervisor: AMS should NOT run with PID 1
if [ "$AMS_PID" = "1" ]; then
echo "Error: Ant Media Server is running with PID 1 when supervisor is enabled"
docker logs antmedia-${{ matrix.supervisor }}
exit 1
else
echo "Success: Ant Media Server is running with PID $AMS_PID (with supervisor)"
fi
else
# Without supervisor: AMS should run with PID 1
if [ "$AMS_PID" = "1" ]; then
echo "Success: Ant Media Server is running with PID 1 (without supervisor)"
else
echo "Error: Ant Media Server is not running with PID 1 when supervisor is disabled"
docker logs antmedia-${{ matrix.supervisor }}
exit 1
fi
fi

# Additional validation: Check if supervisor is running when enabled
if [ "${{ matrix.supervisor }}" = "true" ]; then
SUPERVISOR_RUNNING=$(docker exec antmedia-${{ matrix.supervisor }} pgrep -f "supervisord" || echo "")
if [ -z "$SUPERVISOR_RUNNING" ]; then
echo "Error: Supervisor process not found when it should be enabled"
exit 1
fi
fi

- name: Check Ant Media Server health with a timeout
run: |
timeout=120
start_time=$(date +%s)
until wget http://localhost:5080 -O index.html; do
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))

if [ $elapsed_time -gt $timeout ]; then
echo "Timeout reached. Ant Media Server did not start within $timeout seconds."
exit 1
fi

echo "Waiting for Ant Media Server to start..."
sleep 10
done



28 changes: 26 additions & 2 deletions docker/Dockerfile_Process
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@
# * InstallMediaPush: Set this variable to 'true' to enable headless Chrome on the server for recording and streaming web pages back to Ant Media Server.
# --build-arg InstallMediaPush='true'
#
# * Supervisor Configuration (Optional): If you want to use Supervisor to manage the Ant Media Server process, you can enable as follows. With this configuration, you can easily restart, stop the service, or run the `enable_ssl.sh` script for Ant Media Server.
# --build-arg UseSupervisor='true'
#

FROM ubuntu:22.04

ARG AntMediaServer
ARG LicenseKey
ARG InstallMediaPush

ARG UseSupervisor=false
ARG BranchName=master

ENV UseSupervisor=${UseSupervisor}

#Running update and install makes the builder not to use cache which resolves some updates
RUN apt-get update && apt-get install -y curl wget iproute2 cron logrotate dnsutils iptables

Expand Down Expand Up @@ -92,4 +97,23 @@ RUN if [ "true" = "$InstallMediaPush" ]; then \
# Example usage: ./start.sh -e 60


ENTRYPOINT ["/usr/local/antmedia/start.sh"]
##################### supervisor configuration ##############################
RUN if [ "true" = "$UseSupervisor" ]; then \
apt-get update && apt-get install -y supervisor && \
echo '[supervisord]\n\
nodaemon=true\n\
\n\
[program:antmedia]\n\
command=/bin/bash -c "/usr/local/antmedia/start.sh $@"\n\
autostart=true\n\
autorestart=true\n\
user=antmedia\n\
stdout_logfile_maxbytes = 0\n\
stderr_logfile_maxbytes = 0\n\
stdout_logfile=/dev/stdout\n\
stderr_logfile=/dev/stderr' > /etc/supervisor/supervisord.conf; \
fi

##############################################################################

ENTRYPOINT [ "sh", "-c", "if [ \"$UseSupervisor\" = \"true\" ]; then exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf; else exec /usr/local/antmedia/start.sh \"$@\"; fi", "--" ]
Loading