πŸ“’ Poway Auto Deployment Guide: Step-by-Step

Welcome to the official deployment guide for our project! πŸš€ This guide provides an exhaustive step-by-step walkthrough for deploying our backend to AWS using EC2, Docker, and Cockpit. It demonstrates the exact steps we will follow in order for succesful deployment. Diagrams at the bottom, and the first three steps are the crucial ones.


πŸ“Œ Step 1: Clone & Configure Project

  1. Clone Your Repository
    git clone https://github.com/YOUR_USERNAME/YOUR_BACKEND_REPO.git my_backend
    

    Example:

    git clone https://github.com/Ahaanv19/sprint4_flocker_backend.git
    
  2. Navigate into the Project
    cd my_backend
    
  3. Create .env File (WE DO NOT COMMIT THIS FILE!)
    touch .env
    nano .env
    

    πŸ’‘ Example .env structure: We will decide on a password and username just our example

    SECRET_KEY=supersecretkey
    DATABASE_URL=postgresql://user:password@localhost/dbname
    DEBUG=True
    

    Press CTRL + X, then Y, then Enter to save.

  4. Initialize Database
    ./scripts/db_init.py
    

πŸ“Œ Step 2: Run Your Application with Docker

  1. Build Docker Image
    docker-compose build
    
  2. Run Docker Containers in Detached Mode
    docker-compose up -d
    
  3. Verify Running Containers
    docker ps
    

    βœ… Look for your application and its assigned port.

  4. Test if the Server is Running
    curl localhost:8103
    

    βœ… If successful, you’ll see an HTTP response from your Flask backend.


πŸ“Œ Step 3: Post-Deployment Checks & Monitoring

πŸ”Ή Check Logs

docker logs -f CONTAINER_ID

πŸ”Ή Check Application Health

curl http://OUR_DOMAIN_OR_IP

πŸ”Ή Monitor Performance

Use Cockpit Backdoor for system health and logs.

Test you DNS server

You can test in any terminal (MacOs, WSL, or AWS). Be sure it command returns IP address in answer section. Example result below

Deployment Process Overview

Deployment Diagram and Ubuntu

Deployment Process Overview

Deployment Process Overview

πŸ“Œ Final Notes, Security Best Practices, & Reference Steps for Future Use

βœ… WE DO NOT commit .env files or sensitive credentials.

βœ… Regularly check logs & server health via Cockpit.

Reference Steps Below

These steps are for our reference, focus only on the steps 1,2, and 3, these steps can possibly causes issues but is still useful for future reference. DO NOT WITHOUT PERMISSION USE THESE STEPS!!!

πŸ“Œ Reference Step: Initial Setup and Accessing AWS EC2

πŸ”Ή : Get Your AWS EC2 Credentials

  1. Access AWS EC2 Console:
    • Navigate to AWS EC2 Dashboard.
    • Ensuring we are using the correct AWS region (e.g., us-west-1).
  2. Locate or Create an EC2 Instance:
    • If you already have an instance running, find its Public IPv4 Address under Instances.
    • If you need to create a new one:
      • Click Launch Instance
      • Choose Ubuntu 22.04 LTS
      • Select instance type: t2.micro (free-tier eligible)
      • Configure key pair (download .pem file!)
      • Allow inbound traffic (ports 22, 8080, 443, etc.)
      • Click Launch
  3. Find Your EC2 Public IP
    • Go to Instances β†’ Your Instance β†’ Details
    • Copy Public IPv4 Address

πŸ”Ή Step 1.2: Accessing EC2 via SSH

πŸ’‘ Use Cockpit for easier management: Cockpit Backdoor

Alternatively, use SSH:

ssh -i /path/to/my-key.pem ubuntu@YOUR_INSTANCE_IP

Example:

ssh -i ~/.ssh/aws_key.pem ubuntu@18.234.56.78

βœ… Success Check: You should now be inside the EC2 terminal!


πŸ“ŒReference Step: Initial Server Setup

  1. Update & Upgrade Packages
    sudo apt update && sudo apt upgrade -y
    
  2. Install Required Software
    sudo apt install -y git docker.io docker-compose
    
  3. Start & Enable Docker
    sudo systemctl enable docker
    sudo systemctl start docker
    
  4. Verify Docker Installation
    docker --version
    

    βœ… Expected Output: Docker version XX.XX.XX


πŸ“Œ Reference Step: Route Setup: Route53 Domain Setup (Optional)

  1. Go to AWS Route 53
  2. Register a domain name
  3. Create an A Record:
    • Name: @
    • Type: A
    • Value: OUR_INSTANCE_IP

This is an example, DON’T USE ANY INFO BESIDES VALUE, just use for example

Deployment Process Overview

πŸ“ŒReference Step Expose the Application to the Internet

  1. Find Your Instance’s Public IP
    echo $(curl -s ifconfig.me)
    

    βœ… Copy the output and use it to test in a browser!

  2. Allow Traffic on Port 8103 (Our specfied port number)
    sudo ufw allow 8103/tcp
    sudo ufw enable
    
  3. Test Access from Your Machine
    curl http://OUR_INSTANCE_IP:8103
    

    βœ… Expected: Flask server response.

  4. Set Up Reverse Proxy (Optional, for Nginx Support)
    sudo apt install nginx -y
    
  5. Configure Nginx
    sudo nano /etc/nginx/sites-available/my_backend
    

    πŸ’‘ Example Nginx Config:

    server {
     listen 80;
     server_name YOUR_DOMAIN_OR_IP;
    
     location / {
         proxy_pass http://localhost:8805;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
     }
    }
    

Link to Issue