Ant Media Server Release #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Ant Media Server Release | |
on: | |
push: | |
branches: [ "add_helm_repo" ] | |
paths-ignore: | |
- '**/README.md' | |
- '**/.github/**' | |
- '**/package.sh' | |
- '**/ams-k8s-ssl.sh' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
setup-runner: | |
runs-on: ubuntu-latest | |
outputs: | |
server_id: ${{ steps.set-server-id.outputs.server_id }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3-pip python3-dev libffi-dev libssl-dev | |
sudo pip3 install python-openstackclient | |
- name: server-id | |
id: set-server-id | |
run: | | |
REPO=$(echo "$REPO" | cut -d'/' -f2) | |
SERVER_ID="ci-$REPO" | |
echo "server_id=$SERVER_ID" >> $GITHUB_OUTPUT | |
- name: Configure OpenStack CLI and Create Instance | |
run: | | |
echo "Setting up OpenStack CLI environment variables..." | |
export OS_USERNAME=$OS_USERNAME | |
export OS_PASSWORD=$OS_PASSWORD | |
export OS_PROJECT_NAME=$OS_PROJECT_NAME | |
export OS_AUTH_URL=$OS_AUTH_URL | |
export OS_REGION_NAME=$OS_REGION_NAME | |
export OS_USER_DOMAIN_NAME | |
export OS_API_VERSION | |
export OS_TENANT_NAME | |
export OS_TENANT_ID | |
echo "GITHUB_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV | |
sed -i "s/^GITHUB_TOKEN=.*$/GITHUB_TOKEN=${GITHUB_TOKEN}/" user_data.sh | |
sed -i "s|RUNNER_ORG=\"[^\"]*\"|RUNNER_ORG=\"$REPO\"|g" user_data.sh | |
SERVER_ID="${{ steps.set-server-id.outputs.server_id }}" | |
echo $SERVER_ID | |
openstack server create --flavor "$INSTANCE_TYPE" --image "$IMAGE_ID" --key-name ovh --security-group default --user-data user_data.sh --network Ext-Net $SERVER_ID | |
echo "Server creation initiated." | |
STATUS=$(openstack server show $SERVER_ID -f value -c status) | |
echo "Current server status: $STATUS" | |
while [[ "$STATUS" != "ACTIVE" && "$STATUS" != "ERROR" ]]; do | |
echo "Waiting for server to be ACTIVE. Current status: $STATUS" | |
sleep 10 | |
STATUS=$(openstack server show $SERVER_ID -f value -c status) | |
done | |
if [[ "$STATUS" == "ERROR" ]]; then | |
echo "Server creation failed." | |
exit 1 | |
fi | |
- name: Check runner status and wait if offline | |
id: check_status | |
run: | | |
RUNNER_STATUS=$(curl -s -L \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$REPO/actions/runners | jq -r '.runners[0].status') | |
echo "Initial Runner status is: $RUNNER_STATUS" | |
while [[ "$RUNNER_STATUS" != "online" ]]; do | |
echo "Runner is $RUNNER_STATUS. Waiting for 10 seconds..." | |
sleep 10 | |
RUNNER_STATUS=$(curl -s -L \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$REPO/actions/runners | jq -r '.runners[0].status') | |
echo "Runner status is: $RUNNER_STATUS" | |
done | |
echo "::set-output name=runner_status::$RUNNER_STATUS" | |
- name: Cancel workflow if runner is still offline | |
if: steps.check_status.outputs.runner_status == 'offline' | |
run: | | |
exit 1 | |
local_tests: | |
needs: setup-runner | |
runs-on: self-hosted | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Minikube | |
run: | | |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 | |
sudo install minikube-linux-amd64 /usr/local/bin/minikube | |
- name: Stop/Start Minikube - Docker | |
run: | | |
echo $USER | |
sudo usermod -aG docker $USER && newgrp docker | |
sudo chown $USER /var/run/docker.sock | |
minikube start --driver=docker | |
- name: Install Helm | |
run: | | |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash | |
- name: Install dependencies | |
run: | | |
helm dependency update . | |
- name: Lint Helm chart | |
run: | | |
helm lint . | |
- name: Deploy Helm chart to Minikube | |
run: | | |
helm repo add antmedia https://ant-media.github.io/helm | |
helm repo update | |
helm search repo | |
helm install antmedia antmedia/antmedia --set origin=origin.antmedia.cloud --namespace antmedia --create-namespace | |
- name: Wait for containers to be ready | |
run: | | |
while true; do | |
STATUS=$(kubectl get pods -n antmedia -o jsonpath='{.items[0].status.containerStatuses[0].ready}') | |
if [ "$STATUS" == "true" ]; then | |
break | |
fi | |
sleep 5 | |
done | |
- name: Get Minikube IP | |
id: minikube_ip | |
run: echo "::set-output name=ip::$(minikube ip)" | |
- name: Test pod using curl | |
id: curl_result | |
run: | | |
sleep 30 | |
status_code=$(curl -s -o /dev/null -w "%{http_code}" http://${{ steps.minikube_ip.outputs.ip }}:5080) | |
echo "::set-output name=status_code::$status_code" | |
- name: Check curl result | |
run: | | |
if [[ "${{ steps.curl_result.outputs.status_code }}" -eq 200 ]]; then | |
echo "Ant Media Server is running successfully." | |
else | |
echo "Ant Media Server is not accessible. HTTP status code: ${{ steps.curl_result.outputs.status_code }}" | |
exit 1 | |
fi | |
- name: Uninstall Helm release | |
run: | | |
helm uninstall antmedia -n antmedia | |
- name: Stop Minikube | |
run: minikube stop | |
release: | |
needs: local_tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get version | |
id: version | |
run: echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT | |
- uses: "marvinpinto/action-automatic-releases@latest" | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
if: steps.version.outputs.released == 'true | |
automatic_release_tag: ${{ steps.version.outputs.version }} | |
prerelease: false | |
files: | | |
antmedia-${{ steps.version.outputs.version }}.tgz | |
clean: | |
needs: [setup-runner, local_tests] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Delete runner | |
if: ${{ always() }} | |
run: | | |
echo "GITHUB_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV | |
RUNNER_ID=$(curl -s -H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$REPO/actions/runners | jq -r '.runners[0].id') | |
echo "Deleting runner with ID: $RUNNER_ID" | |
curl -X DELETE -H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$REPO/actions/runners/$RUNNER_ID | |
echo "Runner deleted successfully." | |
- name: Install Dependencies | |
if: ${{ always() }} | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3-pip python3-dev libffi-dev libssl-dev | |
sudo pip3 install python-openstackclient | |
- name: Delete CI Instance | |
if: ${{ always() }} | |
run: | | |
SERVER_ID="${{ needs.setup-runner.outputs.server_id }}" | |
echo "server id" $SERVER_ID | |
export OS_USERNAME=$OS_USERNAME | |
export OS_PASSWORD=$OS_PASSWORD | |
export OS_PROJECT_NAME=$OS_PROJECT_NAME | |
export OS_AUTH_URL=$OS_AUTH_URL | |
export OS_REGION_NAME=$OS_REGION_NAME | |
export OS_USER_DOMAIN_NAME | |
export OS_API_VERSION | |
export OS_TENANT_NAME | |
export OS_TENANT_ID | |
openstack server delete $SERVER_ID |