Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules/
.next/
dist/
build/
.terraform/
*.tfstate
*.tfstate.backup
.env
.env.local
__pycache__/
venv/
25 changes: 25 additions & 0 deletions Terraform/environments/dev/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Terraform/environments/dev/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
backend "s3" {
bucket = "shamitha-0924"
key = "dev/terraform.tfstate"
region = "ap-south-1"
dynamodb_table = "terraform-lock-table"
encrypt = true
}
}
25 changes: 25 additions & 0 deletions Terraform/environments/dev/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module "vpc" {
source = "../../modules/vpc"

vpc_cidr = var.vpc_cidr
}

module "security_group" {
source = "../../modules/security-groups"

vpc_id = module.vpc.vpc_id
}

module "iam" {
source = "../../modules/iam"
}

module "ec2" {
source = "../../modules/ec2"

ami_id = var.ami_id
instance_type = var.instance_type
subnet_id = module.vpc.public_subnet_id
sg_id = module.security_group.sg_id
instance_profile = module.iam.instance_profile
}
14 changes: 14 additions & 0 deletions Terraform/environments/dev/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">= 1.5.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}

provider "aws" {
region = var.region
}
4 changes: 4 additions & 0 deletions Terraform/environments/dev/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
region = "ap-south-1"
vpc_cidr = "10.0.0.0/16"
ami_id = "ami-0607784b46cbe5816"
instance_type = "t2.medium"
4 changes: 4 additions & 0 deletions Terraform/environments/dev/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "vpc_cidr" {}
variable "ami_id" {}
variable "instance_type" {}
variable "region" {}
11 changes: 11 additions & 0 deletions Terraform/modules/ec2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_instance" "main" {
ami = var.ami_id
instance_type = var.instance_type
subnet_id = var.subnet_id
vpc_security_group_ids = [var.sg_id]
iam_instance_profile = var.instance_profile

tags = {
Name = "Terraform-EC2"
}
}
14 changes: 14 additions & 0 deletions Terraform/modules/ec2/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "instance_id" {
description = "EC2 Instance ID"
value = aws_instance.main.id
}

output "public_ip" {
description = "Public IP of EC2"
value = aws_instance.main.public_ip
}

output "private_ip" {
description = "Private IP of EC2"
value = aws_instance.main.private_ip
}
5 changes: 5 additions & 0 deletions Terraform/modules/ec2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "ami_id" {}
variable "instance_type" {}
variable "subnet_id" {}
variable "sg_id" {}
variable "instance_profile" {}
19 changes: 19 additions & 0 deletions Terraform/modules/iam/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "aws_iam_role" "ec2_role" {
name = "ec2-role"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
})
}

resource "aws_iam_instance_profile" "profile" {
name = "ec2-instance-profile"
role = aws_iam_role.ec2_role.name
}
3 changes: 3 additions & 0 deletions Terraform/modules/iam/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "instance_profile" {
value = aws_iam_instance_profile.profile.name
}
45 changes: 45 additions & 0 deletions Terraform/modules/security-groups/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
resource "aws_security_group" "main" {
vpc_id = var.vpc_id

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 8000
to_port = 8000
protocol = "tcp"
cidr_blocks = ["49.204.123.10/32"]
}

ingress {
from_port = 3000
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["49.204.123.10/32"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
3 changes: 3 additions & 0 deletions Terraform/modules/security-groups/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "sg_id" {
value = aws_security_group.main.id
}
1 change: 1 addition & 0 deletions Terraform/modules/security-groups/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variable "vpc_id" {}
28 changes: 28 additions & 0 deletions Terraform/modules/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
}

resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
}

resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
}

resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.main.id
}

resource "aws_route" "internet_access" {
route_table_id = aws_route_table.public_rt.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}

resource "aws_route_table_association" "public_assoc" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public_rt.id
}
7 changes: 7 additions & 0 deletions Terraform/modules/vpc/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "vpc_id" {
value = aws_vpc.main.id
}

output "public_subnet_id" {
value = aws_subnet.public.id
}
1 change: 1 addition & 0 deletions Terraform/modules/vpc/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variable "vpc_cidr" {}
14 changes: 14 additions & 0 deletions Terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">= 1.5.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}

provider "aws" {
region = var.region
}
1 change: 1 addition & 0 deletions Terraform/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
region = "ap-south-1"
4 changes: 4 additions & 0 deletions Terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "region" {
description = "AWS region"
type = string
}
10 changes: 10 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__
*.pyc
*.pyo
venv
.env
.git
.gitignore
README.md
.pytest_cache
.coverage
14 changes: 14 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Python Backend
FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["python", "app/main.py"]
4 changes: 4 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ async def health_check():
@app.get("/api/message")
async def get_message():
return {"message": "You've successfully integrated the backend!"}

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5000)
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

services:
backend:
build: ./backend
container_name: devops-backend
ports:
- "5000:5000"
environment:
- FLASK_APP=app/main.py
- FLASK_ENV=development
volumes:
- ./backend:/app
command: python app/main.py

frontend:
build: ./frontend
container_name: devops-frontend
ports:
- "3000:3000"
environment:
- NEXT_PUBLIC_API_URL=http://localhost:5000
volumes:
- ./frontend:/app
- /app/node_modules
command: npm run dev
depends_on:
- backend

networks:
default:
name: devops-network
10 changes: 10 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
npm-debug.log
.git
.gitignore
README.md
.env
.env.local
build
dist
coverage
2 changes: 1 addition & 1 deletion frontend/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_API_URL=http://localhost:5000
14 changes: 14 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Node.js Frontend
FROM node:18-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "run", "dev"]
Loading