This is a Python Flask application that serves activities and optimal weather conditions for them, from an SQL database, with caching and deployment to Azure Web App via GitHub Actions. The API is to be used for the weather app in IN2000
- Flask web application serving weather data
- Caching using Flask-Caching
- Deployment to Azure Web App using GitHub Actions
- Simple API to fetch all activities or a specific activity
- Example JSON response if cache is not available
- Python 3.10
- Azure Web App for deployment
- GitHub repository for CI/CD pipeline
- Environment variables configured for database connection and API key
-
Clone the repository:
git clone https://github.com/your-username/in2000-weather-sqlapi.git cd in2000-weather-sqlapi
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file and set the required environment variables:api_key_update=your_api_key SQLAZURECONNSTR_SQL_activity=your_connection_string
-
Run the application:
python app.py
GET /
- Renders the main page.GET /api/activities
- Fetches all activities.GET /api/activities/<int:activity_id>
- Fetches a specific activity by ID.POST /db/updatecache
- Updates the activities cache. RequiresX-API-KEY
header.
This project uses GitHub Actions to build and deploy the application to Azure Web App.
The GitHub Actions workflow is defined in .github/workflows/main.yml
. It includes two jobs:
build
: Checks out the code, sets up Python, creates a virtual environment, installs dependencies, and uploads a zipped artifact for deployment.deploy
: Downloads the artifact, unzips it, and deploys the application to Azure Web App using the specified publish profile.
The easiest way to deploy this project is by removing the GitHub actions workflow, creating an Azure Web App and link it up to this repository. This will automatically generate a GitHub actions file that will publish the API. You then setup the environment variables in the Azure Web App.
The deployment workflow triggers on push to the master
branch or can be manually triggered via the GitHub Actions UI.