This repository contains a simple FastAPI application that is deployed to Azure Web Apps with CI/CD using GitHub Actions.
This project includes a basic FastAPI application that returns a JSON response with the message "Hello, Azure Web Apps!" when accessed at the root endpoint. The deployment process is automated using GitHub Actions to deploy to Azure Web Apps.
main.py: Contains the FastAPI application code.requirements.txt: Lists the Python dependencies for the application..github/workflows/deploy.yml: GitHub Actions workflow file for CI/CD.
- Python 3.x
pip(Python package installer)- Git
-
Clone the Repository
git clone https://github.com/Cetyl/fastapi-azure-web-app.git cd fastapi-azure-web-app -
Install Dependencies
pip install -r requirements.txt
-
Run the Application Locally
uvicorn main:app --reload
- Visit
http://127.0.0.1:8000in your browser to see the application in action.
- Visit
-
Create an Azure Web App
- Go to the Azure Portal.
- Create a new App Service with Python as the runtime stack.
- Note the App Service name for later use.
-
Set Up GitHub Actions
- In the Azure Portal, go to your Web App's "Overview" section and click on "Get publish profile".
- In GitHub, navigate to your repository's "Settings" > "Secrets" > "Actions".
- Add a new repository secret with the name
AZURE_WEBAPP_PUBLISH_PROFILEand paste the content of the publish profile.
-
Deploy the Application
- Ensure your code is pushed to the
mainbranch of your GitHub repository. - GitHub Actions will automatically trigger the deployment workflow to deploy the application to Azure Web Apps.
- Ensure your code is pushed to the
The deployment workflow is defined in .github/workflows/deploy.yml. It performs the following steps:
- Checks out the code from the repository.
- Sets up Python.
- Installs the application dependencies.
- Deploys the application to Azure Web Apps using the publish profile.
-
Access the Deployed Application
- Visit the URL of your Azure Web App (e.g.,
https://fastapi-azure-internship-eqbgamffauh0cdfq.eastasia-01.azurewebsites.net). - You should see the JSON response:
{"message": "Hello, Azure Web Apps!"}.
- Visit the URL of your Azure Web App (e.g.,
- Ensure all required secrets are set up in GitHub.
- Check the GitHub Actions logs for deployment issues.
- Verify that the Azure Web App is correctly configured and running.
Feel free to fork the repository and submit pull requests. For any issues or feature requests, please use the GitHub Issues page.
This project is licensed under the MIT License - see the LICENSE file for details.