Skip to content

Commit

Permalink
Merge branch 'ci/cd_upgrade_validation_test' of https://github.com/an…
Browse files Browse the repository at this point in the history
…t-media/Scripts.git into ci/cd_upgrade_validation_test
  • Loading branch information
mekya committed Mar 10, 2024
2 parents c688e0d + 6cd2aa7 commit 78e5663
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 36 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/24x7-test1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python 24x7 script

on:
schedule:
- cron: '*/5 * * * *'

jobs:
run-selenium:
runs-on: ubuntu-latest
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK }}
SERVER_IP: ${{ secrets.SERVER_IP }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}

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

- name: Set up Python 3
uses: actions/setup-python@v3
with:
python-version: 3.x

- name: Install dependencies
run: |
pip install requests
pip install paramiko
- name: Run staging script
run: |
python 24x7-testing/24x7-test1.py
80 changes: 80 additions & 0 deletions .github/workflows/ant-media-server-docker-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI/CD for Docker Images - Ant Media Server (Ubuntu & Rocky Linux)

on: [push]

jobs:
ams_ubuntu_docker_test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@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: Download Dockerfile
run: wget --quiet https://raw.githubusercontent.com/ant-media/Scripts/master/docker/Dockerfile_Process -O Dockerfile

- name: Build Docker image
run: docker build --network=host -t antmediaserver:latest --build-arg AntMediaServer=ant-media-server-community.zip .

- name: Run the image
run: docker run -d -p 5080:5080 --name antmediaserver antmediaserver

- 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
- name: Stop and remove the container
run: docker stop antmediaserver && docker rm antmediaserver

ams_rockylinux_docker_test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@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: Download Dockerfile
run: wget --quiet https://raw.githubusercontent.com/ant-media/Scripts/master/docker/Dockerfile_RockyLinux -O Dockerfile

- name: Build Docker image
run: docker build --network=host -t antmediaserver:latest --build-arg AntMediaServer=ant-media-server-community.zip .

- name: Run the image
run: docker run -d -p 5080:5080 --name antmediaserver antmediaserver

- 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
- name: Stop and remove the container
run: docker stop antmediaserver && docker rm antmediaserver
57 changes: 57 additions & 0 deletions .github/workflows/check-marketplace-jwt-token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Marketplace SSL Test

#run tests on schedule because we don't want to generate a subdomain everytime
on:
schedule:
- cron: '0 0 * * 1'



jobs:
run_build:
name: Marketplace SSL Test
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Run enable_ssl.sh for marketplace
uses: appleboy/ssh-action@master
with:
#OVH_REMOTE_HOST has marketplace version deployed
host: ${{ secrets.OVH_REMOTE_HOST }}
username: ${{ secrets.OVH_REMOTE_USERNAME }}
key: ${{ secrets.OVH_SSH_PRIVATE_KEY }}
port: ${{ secrets.OVH_REMOTE_PORT }}
# If the version is not marketplace, following enable_ssl.sh script fails
script: |
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
sudo service antmedia restart
sleep 20
OUTPUT=$(sudo bash /usr/local/antmedia/enable_ssl.sh)
echo "OUTPUT -> $OUTPUT";
HTTPS_URL=$(echo "$OUTPUT" | grep 'You can use this url: '| grep -o 'https://[^ ]*')
echo "HTTPS_URL -> $HTTPS_URL"
sleep 20
status_code=$(curl -o /dev/null -s -I -w "%{http_code}" "$HTTPS_URL")
if [ "$status_code" -eq 200 ]; then
echo "URL($HTTPS_URL) is working: $status_code"
else
echo "URL($HTTPS_URL) is not working: $status_code"
exit 1;
fi
- name: Run enable_ssl.sh for existing domain
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.OVH_REMOTE_HOST }}
username: ${{ secrets.OVH_REMOTE_USERNAME }}
key: ${{ secrets.OVH_SSH_PRIVATE_KEY }}
port: ${{ secrets.OVH_REMOTE_PORT }}
#restore the old domain to not encounter any issue
script: |
sudo bash /usr/local/antmedia/enable_ssl.sh -d ${{ secrets.OVH_REMOTE_HOST }}
1 change: 1 addition & 0 deletions 24x7-testing/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

105 changes: 105 additions & 0 deletions 24x7-testing/24x7-test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import os
import time
import requests
import paramiko
import json

webhook_url = os.environ['WEBHOOK_URL']
icon_emoji = ":ghost:"

def send_slack_message(webhook_url, message, icon_emoji=":ghost:"):
payload = {
"text": message,
"icon_emoji": icon_emoji
}
response = requests.post(webhook_url, data={"payload": json.dumps(payload)})

if response.status_code != 200:
print("Error sending Slack message: ", response.text)
else:
print("Slack message sent successfully!")

def check_stream_status(api_url):
try:
# Make the GET request to the API
response = requests.get(api_url)
response.raise_for_status() # Raise an HTTPError for bad status codes

response_data = response.json()

# Extract the required fields
status = response_data.get("status")
webRTCViewerCount = response_data.get("webRTCViewerCount")

# Check if the status is "broadcasting" and webRTCViewerCount is 1
if status == "broadcasting" and webRTCViewerCount == 1:
print("Stream is broadcasting with 1 WebRTC viewer.")
else:
message = "Stream is not broadcasting or there is no viewer"
send_slack_message(webhook_url, message, icon_emoji)
return False

except requests.exceptions.RequestException as e:
print(f"Error making the API call: {e}")
message = "Error making the API call"
send_slack_message(webhook_url, message, icon_emoji)
return False

except requests.exceptions.HTTPError as e:
print(f"HTTP error: {e}")
message = "HTTP error when making the API call"
send_slack_message(webhook_url, message, icon_emoji)
return False

except ValueError as e:
print(f"Error: {e}")
return False

except Exception as e:
print(f"Unexpected error: {e}")
return False

return True

def check_server_for_errors(server_ip, username, password):
try:
# SSH into the server
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(server_ip, username=username, password=password)

# Check for error files
file_extensions = [".log", ".hprof"]
error_files = []

for ext in file_extensions:
stdin, stdout, stderr = client.exec_command(f"ls /usr/local/antmedia/*{ext}")
error_files.extend(stdout.readlines())

if error_files:
print("Error files found:")
for file in error_files:
print(file.strip())
message = "The crash log or dump file is found on the server in 24x7 staging enviornment. Please check the logs"
send_slack_message(webhook_url, message, icon_emoji)
else:
print("No error files found")

except paramiko.AuthenticationException as e:
print(f"Authentication failed: {e}")
except paramiko.SSHException as e:
print(f"SSH error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
finally:
client.close()

if __name__ == "__main__":
api_url = "https://test.antmedia.io:5443/24x7test/rest/v2/broadcasts/24x7test"
if check_stream_status(api_url):
# Replace the following with server details
server_ip = os.environ['SERVER_IP']
username = os.environ['USERNAME']
password = os.environ['PASSWORD']

check_server_for_errors(server_ip, username, password)
22 changes: 5 additions & 17 deletions cloudformation/aws-streaming-wizard/template-custom-cert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Resources:
UbuntuGetLatestAMI:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.11
Runtime: python3.12
Handler: index.handler
Role: !Sub ${DescribeImagesRole.Arn}
Timeout: 60
Expand Down Expand Up @@ -124,7 +124,7 @@ Resources:
Handler: index.lambda_handler
Role: !Sub '${AcmCertificateImportLambdaExecutionRole.Arn}'
Runtime: python3.11
Runtime: python3.12
AcmCertificateImportLambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
Expand Down Expand Up @@ -253,6 +253,8 @@ Resources:

RTMPLoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
DependsOn:
- InternetGatewayAttachment
Properties:
Subnets:
- !Ref OriginZone
Expand Down Expand Up @@ -321,13 +323,6 @@ Resources:
MaxBatchSize: '1'
PauseTime: PT15M
WaitOnResourceSignals: 'true'
NotificationConfiguration:
TopicARN: !Ref NotificationTopic
NotificationTypes:
- 'autoscaling:EC2_INSTANCE_LAUNCH'
- 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR'
- 'autoscaling:EC2_INSTANCE_TERMINATE'
- 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR'

LaunchTemplateOrigin:
Type: 'AWS::EC2::LaunchTemplate'
Expand Down Expand Up @@ -397,13 +392,6 @@ Resources:
MaxBatchSize: '1'
PauseTime: PT15M
WaitOnResourceSignals: 'true'
NotificationConfiguration:
TopicARN: !Ref NotificationTopic
NotificationTypes:
- 'autoscaling:EC2_INSTANCE_LAUNCH'
- 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR'
- 'autoscaling:EC2_INSTANCE_TERMINATE'
- 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR'

LaunchTemplateEdge:
Type: 'AWS::EC2::LaunchTemplate'
Expand All @@ -418,7 +406,7 @@ Resources:
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: !Ref DiskSize
VolumeSize: 10
VolumeType: gp2
DeleteOnTermination: true
UserData:
Expand Down
18 changes: 3 additions & 15 deletions cloudformation/aws-streaming-wizard/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Resources:

RTMPLoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
DependsOn:
- InternetGatewayAttachment
Properties:
Subnets:
- !Ref OriginZone
Expand Down Expand Up @@ -268,13 +270,6 @@ Resources:
MaxBatchSize: '1'
PauseTime: PT15M
WaitOnResourceSignals: 'true'
NotificationConfiguration:
TopicARN: !Ref NotificationTopic
NotificationTypes:
- 'autoscaling:EC2_INSTANCE_LAUNCH'
- 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR'
- 'autoscaling:EC2_INSTANCE_TERMINATE'
- 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR'

LaunchTemplateOrigin:
Type: 'AWS::EC2::LaunchTemplate'
Expand Down Expand Up @@ -344,13 +339,6 @@ Resources:
MaxBatchSize: '1'
PauseTime: PT15M
WaitOnResourceSignals: 'true'
NotificationConfiguration:
TopicARN: !Ref NotificationTopic
NotificationTypes:
- 'autoscaling:EC2_INSTANCE_LAUNCH'
- 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR'
- 'autoscaling:EC2_INSTANCE_TERMINATE'
- 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR'

LaunchTemplateEdge:
Type: 'AWS::EC2::LaunchTemplate'
Expand All @@ -365,7 +353,7 @@ Resources:
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: !Ref DiskSize
VolumeSize: 10
VolumeType: gp2
DeleteOnTermination: true
UserData:
Expand Down
Loading

0 comments on commit 78e5663

Please sign in to comment.