Day 1: Deploying Flask Portfolio with DevOps Stack
From bare Ubuntu VM to a production-ready Flask app with Gunicorn, Nginx, Prometheus, and CI/CD โ all from the terminal.
โ๏ธ Stack & Tools
- Ubuntu 22.04 on IONOS Cloud VM
- Gunicorn for running Flask
- Nginx as a reverse proxy
- systemd for service management
- UFW for firewall control
- Prometheus + Node Exporter for monitoring
- GitHub Actions for CI/CD deployment (WIP)
๐ Directory Structure
/opt/portfolio/
โโโ app.py
โโโ venv/
โโโ templates/
โโโ static/
โโโ requirements.txt
โโโ .github/workflows/deploy.yml
๐ Phase 1: Server Setup
- Created user
dipendrawith sudo privileges - Configured SSH key-based login
- Enabled UFW for ports 22, 80, 9090, 9200
๐ Phase 2: Flask Deployment
- Created Python virtual environment in
/opt/portfolio/venv - Installed all dependencies from
requirements.txt - Tested locally with Gunicorn:
gunicorn -b 127.0.0.1:8000 app:app
๐ Phase 3: systemd Service
Created /etc/systemd/system/portfolio.service:
[Unit]
Description=Gunicorn Flask Portfolio
After=network.target
[Service]
User=dipendra
Group=www-data
WorkingDirectory=/opt/portfolio
Environment="PATH=/opt/portfolio/venv/bin"
ExecStart=/opt/portfolio/venv/bin/gunicorn -w 3 -b 127.0.0.1:8000 app:app
[Install]
WantedBy=multi-user.target
- Enabled and started the service with
systemctl
๐ Phase 4: Nginx Proxy
Configured /etc/nginx/sites-available/portfolio:
server {
listen 80;
server_name _;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
- Disabled default config
- Reloaded Nginx after syntax test
๐ Phase 5: Prometheus + Node Exporter
- Installed and configured Prometheus on port
9090 - Installed Node Exporter on custom port
9200 - Linked it in
prometheus.ymlscrape configs - Verified metrics in browser via
/metricsendpoint
๐ Phase 6: GitHub Actions (WIP)
- Generated a dedicated SSH key for GitHub CI/CD
- Tested public/private pairing
- Created initial
deploy.ymlin.github/workflows - Faced key mismatch issue (to be resolved)
โ Outcome
The Flask portfolio is now running behind Gunicorn and Nginx, monitored with Prometheus & Node Exporter, and nearly ready for CI/CD automation.
๐ Lessons Learned
- How to debug
systemdservice errors - Understanding port binding conflicts
- Prometheus endpoint scraping
- CI/CD security with SSH key pairs
๐ What's Next
- Fix SSH key issue and complete GitHub Actions CI/CD
- Install Grafana for visual dashboards
- Enable SSL with Let's Encrypt (when domain is ready)