”””
Introduction
Deployment is the final step in the software development lifecycle. Before we push our project live, it is crucial to ensure that everything is properly set up, from the frontend to the backend. This guide outlines the essential steps required for deploying a full-stack application, covering everything from server configuration to DNS setup. “””
Preparing for Deployment
print(“Ensure that the test server runs smoothly locally before deploying.”) print(“Document the deployment process, including terms, visuals, and troubleshooting steps.”) print(“Clearly define roles for Deployment Admins and prepare necessary configuration files in the repository.”)
Deployment Steps
def build_and_test(): “"”Build and test the application locally.””” print(“Building application…”) print(“Testing application…”) print(“Ensure everything works as expected before proceeding.”)
build_and_test()
Configuration Files
nginx_config = “”” server { listen 80; listen [::]:80; server_name motor.stu.nighthawkcodingsociety.com;
location / {
proxy_pass http://localhost:8104;
if ($request_method ~* "(GET|POST|PUT|DELETE)") {
add_header "Access-Control-Allow-Origin" *;
}
if ($request_method = OPTIONS) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, PUT, DELETE, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
} } """ print("NGINX configuration ready.")
Docker Compose Configuration
docker_compose = “”” version: ‘3’ services: web: image: motorsports build: . env_file: - .env ports: - “8104:8104” volumes: - ./instance:/instance restart: unless-stopped “”” print(“Docker Compose configuration ready.”)
Dockerfile Configuration
dockerfile = “”” FROM docker.io/python:3.12.8
WORKDIR /
RUN apt-get update && apt-get upgrade -y &&
apt-get install -y python3 python3-pip git
COPY . / RUN pip install –no-cache-dir -r requirements.txt RUN pip install gunicorn RUN ./scripts/db_init.py
ENV GUNICORN_CMD_ARGS=”–workers=3 –bind=0.0.0.0:8104” EXPOSE 8104 ENV FLASK_ENV=production CMD [ “gunicorn”, “main:app” ] “”” print(“Dockerfile ready.”)
Deploy to AWS EC2
def deploy_to_ec2(): “"”Clone repository, create .env file, and run Docker commands on AWS EC2.””” commands = [ “git clone https://github.com/Tvick22/personal_flocker_backend.git motor_backend”, “cd motor_backend”, “touch .env”, “echo "ADMIN_USER=’toby’" » .env”, “echo "ADMIN_PASSWORD=’123Toby!’" » .env”, “echo "DEFAULT_USER=’hop’" » .env”, “echo "DEFAULT_PASSWORD=’123Hop!’" » .env”, “docker-compose build”, “docker-compose up -d”, “docker ps”, “curl localhost:8104” ] for cmd in commands: print(f”Run: {cmd}”)
deploy_to_ec2()
DNS Configuration
print(“Configure Route 53 to point the domain to the EC2 instance.”)
Frontend and Backend Integration
print(“Frontend communicates with backend via NGINX as a reverse proxy.”)
TCP/IP Model
print(“Application Layer: Frontend web server (GitHub Pages)”) print(“Transport Layer: TCP protocol and NGINX”) print(“Network Layer: IP protocol and Router”) print(“Physical Layer: Ethernet, Wi-Fi, or fiber optic cable”)