I know that Gitub action is for CI/ CD but I need to deploy a model FastAPI application . I’m deploying a FastAPI application using GitHub Actions. The app is served with Uvicorn and exposed through Ngrok. Although the logs show that everything is running correctly and provide a public Ngrok URL, I am unable to access the application at the provided URL.
Configuration Details:
FastAPI App: Runs on Uvicorn at 0.0.0.0:8000.
Ngrok: Exposes the app to a public URL.
GitHub Actions: Orchestrates the setup, installation, and server running.
GitHub Actions Log Output:
Run uvicorn scripts.main:app --host 0.0.0.0 --port 8000 &
INFO: Started server process [2832]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
FastAPI app running at https://c3f3-20-161-78-239.ngrok-free.app
Firewall Settings:
Allowed TCP traffic on port 8000.
Issue:
The FastAPI app URL https://c3f3-20-161-78-239.ngrok-free.app is not accessible.
Questions:
Could the GitHub Actions environment be affecting the Ngrok tunnel’s stability or availability?
Are there any common pitfalls or configurations I might be missing that could prevent access to the Ngrok URL?
How can I ensure the Ngrok tunnel remains active and accessible as long as the GitHub Actions workflow is running?
my action yml file
name: Deploy FastAPI Application
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
train-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Train model
run: python scripts/train_model.py
env:
PYTHONPATH: ${{ github.workspace }}
- name: Public IP
id: ip
uses: haythem/[email protected]
- name: Print Public IP
run: |
echo "Public IPv4: ${{ steps.ip.outputs.ipv4 }}"
echo "Public IPv6: ${{ steps.ip.outputs.ipv6 }}"
- name: Install Ngrok
run: |
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc > /dev/null
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
sudo apt update && sudo apt install ngrok
- name: Allow port 8000 through UFW
run: |
sudo ufw allow 8000/tcp
sudo ufw enable
sudo ufw status
- name: Start Ngrok
run: |
ngrok authtoken ${{ secrets.ngrok}}
ngrok http 8000 &
sleep 10 # Wait for ngrok to initialize
NGROK_URL=$(curl --silent http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')
echo "NGROK_URL=${NGROK_URL}" >> $GITHUB_ENV
- name: Deploy FastAPI application
run: |
uvicorn scripts.main:app --host 0.0.0.0 --port 8000 &
sleep 10 # Allow server to start
echo "FastAPI app running at ${{ env.NGROK_URL }}"
- name: Debug Running Services
run: |
echo "Running processes:"
ps aux
echo "Docker containers:"
docker ps
echo "Listening ports:"
sudo netstat -tulpn