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 dipendra with 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.yml scrape configs
  • Verified metrics in browser via /metrics endpoint

๐Ÿ”„ Phase 6: GitHub Actions (WIP)

  • Generated a dedicated SSH key for GitHub CI/CD
  • Tested public/private pairing
  • Created initial deploy.yml in .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 systemd service 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)