Documentation

How this application works and how to run it.

Local Setup

Prerequisites:

  • Python 3.8+
  • MySQL 8.0+ (or use Docker for MySQL)
  • pip (Python package manager)

Steps:

  1. Clone the repository
  2. Create a virtual environment: python -m venv venv
  3. Activate the virtual environment:
    • Windows: venv\Scripts\activate
    • Linux/Mac: source venv/bin/activate
  4. Install dependencies: pip install -r requirements.txt
  5. Create a .env file with database credentials
  6. Set up the MySQL database and create the notes table
  7. Run the Flask app: python app.py
  8. Access the application at http://localhost:5000

Docker Setup

Prerequisites:

  • Docker Desktop installed
  • Docker Compose (included with Docker Desktop)

Quick Start:

  1. Create a .env file in the project root with:
    DB_HOST=mysql
    DB_USER=root
    DB_PASSWORD=rootpassword
    DB_NAME=devops_notes
    MYSQL_ROOT_PASSWORD=rootpassword
  2. Build and start containers:
    docker compose up --build
  3. Initialize the database (one-time setup):

    docker exec -it devops-mysql mysql -uroot -prootpassword devops_notes

    # Then run SQL:

    CREATE TABLE notes ( id INT AUTO_INCREMENT PRIMARY KEY, command VARCHAR(255) NOT NULL, description TEXT NOT NULL, category VARCHAR(50), tags VARCHAR(255), example TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
  4. Access the application at http://localhost:5000

Useful Commands:

  • Stop containers: docker compose down
  • Stop and remove volumes: docker compose down -v
  • View logs: docker compose logs -f
  • Rebuild after changes: docker compose up --build

DevOps Concepts Practiced

This project demonstrates:

  • Containerization: Application and database run in isolated Docker containers
  • Service Orchestration: Docker Compose manages multi-container setup
  • Environment Variables: Secure configuration using .env files
  • Persistent Storage: Docker volumes for database data persistence
  • Service Discovery: Containers communicate via Docker network

Database Schema

The application uses a MySQL database with the following table structure:

CREATE TABLE notes (
  id INT AUTO_INCREMENT PRIMARY KEY,
  command VARCHAR(255) NOT NULL,
  description TEXT NOT NULL,
  category VARCHAR(50),
  tags VARCHAR(255),
  example TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Fields:

  • id: Primary key, auto-incrementing
  • command: The DevOps command or operation name
  • description: Detailed explanation (HTML formatted)
  • category: Predefined category for organization

REST API Usage

The application now supplies a REST API for programmatic access to your notes.

Authentication:

All API requests require an X-API-Token header. You can generate your token in the Settings page.

curl -H "X-API-Token: YOUR_TOKEN" http://localhost/api/notes

Endpoints:

  • GET /api/notes - List all notes (supports -category=X&search=Y)
  • GET /api/notes/<id> - Get a single note
  • POST /api/notes - Create a new note (JSON body required)
  • GET /api/categories - List all available categories

Example Creation:

curl -X POST http://localhost/api/notes \
  -H "X-API-Token: YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"command": "ls -la", "description": "List all files", "category": "Linux"}'