- π’ Poway Auto Deployment Guide: Step-by-Step
- π Step 1: Clone & Configure Project
- π Step 2: Run Your Application with Docker
- π Step 3: Post-Deployment Checks & Monitoring
- Deployment Diagram and Ubuntu
- π Final Notes, Security Best Practices, & Reference Steps for Future Use
- Reference Steps Below
- π Reference Step: Initial Setup and Accessing AWS EC2
- πReference Step: Initial Server Setup
- π Reference Step: Route Setup: Route53 Domain Setup (Optional)
- πReference Step Expose the Application to the Internet
π’ 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
- 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
- Navigate into the Project
cd my_backend
- 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 exampleSECRET_KEY=supersecretkey DATABASE_URL=postgresql://user:password@localhost/dbname DEBUG=True
Press
CTRL + X
, thenY
, thenEnter
to save. - Initialize Database
./scripts/db_init.py
π Step 2: Run Your Application with Docker
- Build Docker Image
docker-compose build
- Run Docker Containers in Detached Mode
docker-compose up -d
- Verify Running Containers
docker ps
β Look for your application and its assigned port.
- 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 Diagram and Ubuntu
π 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
- Access AWS EC2 Console:
- Navigate to AWS EC2 Dashboard.
- Ensuring we are using the correct AWS region (e.g.,
us-west-1
).
- 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
- 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
- Update & Upgrade Packages
sudo apt update && sudo apt upgrade -y
- Install Required Software
sudo apt install -y git docker.io docker-compose
- Start & Enable Docker
sudo systemctl enable docker sudo systemctl start docker
- Verify Docker Installation
docker --version
β Expected Output:
Docker version XX.XX.XX
π Reference Step: Route Setup: Route53 Domain Setup (Optional)
- Go to AWS Route 53
- Register a domain name
- Create an A Record:
- Name:
@
- Type:
A
- Value:
OUR_INSTANCE_IP
- Name:
This is an example, DONβT USE ANY INFO BESIDES VALUE, just use for example
πReference Step Expose the Application to the Internet
- Find Your Instanceβs Public IP
echo $(curl -s ifconfig.me)
β Copy the output and use it to test in a browser!
- Allow Traffic on Port 8103 (Our specfied port number)
sudo ufw allow 8103/tcp sudo ufw enable
- Test Access from Your Machine
curl http://OUR_INSTANCE_IP:8103
β Expected: Flask server response.
- Set Up Reverse Proxy (Optional, for Nginx Support)
sudo apt install nginx -y
- 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; } }