Skip to content

Commit

Permalink
Merge branch 'master' into remove_instanceid
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya authored Feb 21, 2025
2 parents 7e30000 + a277e8f commit 538bdfc
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 9 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/antmedia-cf-template-validation-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Ant Media Server Cloudformation Deployment

on:
on:
schedule:
- cron: '0 0 * * 1'

Expand Down Expand Up @@ -77,3 +77,23 @@ jobs:
run: |
aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}
- name: Send Slack Notification on Failure
if: failure()
uses: slackapi/[email protected]
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: "<@murat> CloudFormation deployment failed! :x:\nWorkflow: ${{ github.workflow }}\nJob: ${{ github.job }}\nCheck the logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Send Slack Notification on Success
if: success()
uses: slackapi/[email protected]
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: "CloudFormation deployment completed successfully! :white_check_mark:\nWorkflow: ${{ github.workflow }}\nJob: ${{ github.job }}"
97 changes: 97 additions & 0 deletions .github/workflows/docker-supervisor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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
export LICENSE_KEY="test-test"
docker run -d -p 5080:5080 --name antmedia-${{ matrix.supervisor }} antmedia:${{ matrix.supervisor }} -l $LICENSE_KEY
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)"
# we dont check license key when supervisor is enabled because passing command line parameters has not been supported yet
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)"
AMS_LICENSE_KEY=$(docker exec antmedia-${{ matrix.supervisor }} cat /usr/local/antmedia/conf/red5.properties | grep "server.licence_key" | cut -d'=' -f2)
echo "AMS_LICENSE_KEY: $AMS_LICENSE_KEY"
#check if the license key is set correctly. It validates that docker file accepts the parameters from command line
if [ "$AMS_LICENSE_KEY" != "$LICENSE_KEY" ]; then
echo "Error: License key mismatch"
exit 1
fi
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", "--" ]
9 changes: 3 additions & 6 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
INITIALIZED=/usr/local/antmedia/conf/initialized
if [ ! -f "$INITIALIZED" ]
then
TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
## Local IPV4

export LOCAL_IPv4=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
export LOCAL_IPv4=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-ipv4`

# $HOSTNAME ip-172-30-0-216
HOST_NAME=`hostname`
Expand All @@ -27,7 +28,7 @@ then
fi
fi
## Instance ID
export INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
export INSTANCE_ID=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id`

## Add Initial User with curl
RESULT=`curl -s -X POST -H "Content-Type: application/json" -d '{"email": "JamesBond", "password": "'$INSTANCE_ID'", "scope": "system", "userType": "ADMIN"}' http://localhost:5080/rest/v2/users/initial`
Expand All @@ -46,8 +47,4 @@ then

fi
touch $INITIALIZED
## Add default ServerSecretKey
SECRET_KEY=$(openssl rand -base64 32 | head -c 32)
sudo sed -i "/^server.jwtServerControlEnabled=/s|.*|server.jwtServerControlEnabled=true|" /usr/local/antmedia/conf/red5.properties
sudo sed -i "/^server.jwtServerSecretKey=/s|.*|server.jwtServerSecretKey=$SECRET_KEY|" /usr/local/antmedia/conf/red5.properties
fi

0 comments on commit 538bdfc

Please sign in to comment.