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: 0 additions & 11 deletions Dockerfile

This file was deleted.

11 changes: 11 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.7.11-slim

WORKDIR /app/python-api

COPY . /app/python-api

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

EXPOSE 5000

CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions infra/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
provider "aws" {
region = "us-west-2"
}

resource "aws_ecr_repository" "flask_ecr" {
name = "flask-api-repository"
}

resource "aws_ecs_cluster" "flask_cluster" {
name = "flask-cluster"
}

resource "aws_ecs_task_definition" "flask_task" {
family = "flask-api-task"
network_mode = "awsvpc"
cpu = "256"
memory = "512"
requires_compatibilities = ["FARGATE"]

container_definitions = jsonencode([{
name = "flask-api"
image = "${aws_ecr_repository.flask_ecr.repository_url}:latest"
cpu = 256
memory = 512
essential = true
portMappings = [{
containerPort = 5000
hostPort = 5000
protocol = "tcp"
}]
}])
}

resource "aws_ecs_service" "flask_service" {
name = "flask-service"
cluster = aws_ecs_cluster.flask_cluster.id
task_definition = aws_ecs_task_definition.flask_task.arn
desired_count = 1

network_configuration {
subnets = ["subnet-xxxxxxxx"]
security_groups = ["sg-xxxxxxxx"]
assign_public_ip = true
}
}
3 changes: 3 additions & 0 deletions infra/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "ecr_repository_url" {
value = aws_ecr_repository.flask_ecr.repository_url
}
1 change: 1 addition & 0 deletions infra/terraform/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aws_region = "us-west-2"
3 changes: 3 additions & 0 deletions infra/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "aws_region" {
default = "us-west-2"
}
26 changes: 26 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

AWS_REGION="us-west-2"
ECR_REPOSITORY="flask-api-repository"
DOCKER_IMAGE_NAME="flask-api"
ECR_URI=$(aws ecr describe-repositories --repository-names $ECR_REPOSITORY --query "repositories[0].repositoryUri" --output text)

aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_URI

docker build -t $DOCKER_IMAGE_NAME .

docker tag $DOCKER_IMAGE_NAME:latest $ECR_URI:latest

docker push $ECR_URI:latest

echo "Docker image pushed to ECR: $ECR_URI:latest"

HEALTH_CHECK_URL="http://your-ecs-service-public-ip:5000"
STATUS_CODE=$(curl --write-out "%{http_code}" --silent --output /dev/null $HEALTH_CHECK_URL)

if [ $STATUS_CODE -eq 200 ]; then
echo "Health check passed. Flask API is running!"
else
echo "Health check failed."
exit 1
fi