Weather WebApp
A simple weather web app built with Python, using Flask, Nginx and Gunicorn. CI/CD pipeline done with GitHub Actions.
Table of Contents
Features
- Check current weather conditions for any location.
- Built using Flask and Gunicorn for efficient handling of requests.
- Dockerized for easy deployment.
- Integrated security checks with Snyk and Gitleaks.
- Automated tests with pytest and linting with flake8 and pylint.
Technologies Used
- Python 3.12
- Flask
- Gunicorn
- Docker
- GitHub Actions for CI/CD
- Snyk for security scanning
- Gitleaks for secret detection
- API: open-meteo
Installation
To run this project locally, follow these steps:
- Clone the repository:
git clone https://github.com/niv-devops/weather-webapp.git cd weather-webapp
-
Active env, install dependencies, run application
cd existing_repo . .venv/bin/activate pip install --break-system-packages --user <dependency> python3 weather.py
-
Install dependencies:
python -m pip install --upgrade pip pip install -r requirements.txt
- Set up environment variables as needed (e.g., API keys for weather services).
Usage
To run the application locally, use the following command:
gunicorn --bind 0.0.0.0:5000 wsgi:app
You can then access the application at http://localhost:5000
.
Running Tests
To run the tests, execute:
pytest tests/
Docker
To build and run the application using Docker, follow these steps:
- Build the Docker image:
docker build -t weather-webapp .
- Run the Docker container:
docker run -p 5000:5000 weather-webapp
Continuous Integration
This project uses GitHub Actions for CI/CD. The pipeline includes:
- Running tests and linting on every push and pull request.
- Building and pushing Docker images to GitHub Container Registry.
- Scanning for vulnerabilities using Snyk and Gitleaks.
Pipeline Steps
- Test: Runs all tests and checks for code quality.
- Build: Builds the Docker image and pushes it to the GitHub Container Registry.
- Monitor: Sends notifications to a Slack channel regarding the pipeline status.
GitLab additional options
- Create or upload files
- Add files using the command line or push an existing Git repository with the following command:
cd existing_repo
git remote add origin http://3.122.61.221/niv/webapp.git
git branch -M main
git push -uf origin main
- Invite team members and collaborators
- Create a new merge request
- Automatically close issues from merge requests
- Enable merge request approvals
- Get started with GitLab CI/CD
- Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)
- Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy
- Use pull-based deployments for improved Kubernetes management
- Set up protected environments