-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from A3Data/feature/docker-deploy
Feature/docker deploy
- Loading branch information
Showing
16 changed files
with
1,112 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,6 @@ dmypy.json | |
cython_debug/ | ||
|
||
/data | ||
|
||
# terraform | ||
.terraform* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Use a imagem base do Python | ||
FROM python:3.10-slim | ||
|
||
# Define a pasta de trabalho dentro do container | ||
WORKDIR /app | ||
|
||
# Instala o Poetry via pip | ||
RUN pip install poetry | ||
|
||
# Copia o arquivo pyproject.toml para instalar dependências | ||
COPY pyproject.toml . | ||
|
||
# Instala as dependências do projeto sem utilizar o poetry.lock | ||
RUN poetry lock \ | ||
&& poetry install --no-dev | ||
|
||
COPY artifacts/ artifacts/ | ||
COPY api/ api/ | ||
COPY src/ src/ | ||
COPY config/ config/ | ||
|
||
# Expõe a porta 8000 para o servidor FastAPI | ||
EXPOSE 8000 | ||
|
||
# Comando para rodar a aplicação FastAPI com Uvicorn | ||
CMD ["poetry", "run", "uvicorn", "api.app.main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
resource "aws_iam_role" "ecs_instance_role" { | ||
name = "${local.default_prefix}-ecs-instance-role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "ec2.amazonaws.com" | ||
}, | ||
Action = "sts:AssumeRole" | ||
}] | ||
}) | ||
|
||
tags = { | ||
Name = "${local.default_prefix}-ecs-instance-role" | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "ecs_instance_role_policy" { | ||
role = aws_iam_role.ecs_instance_role.name | ||
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role" | ||
} | ||
|
||
resource "aws_iam_instance_profile" "ecs_instance_profile" { | ||
name = "${local.default_prefix}-ecs-instance-profile" | ||
role = aws_iam_role.ecs_instance_role.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
resource "tls_private_key" "private_key" { | ||
algorithm = "RSA" | ||
rsa_bits = 2048 | ||
} | ||
|
||
resource "aws_key_pair" "generated_key" { | ||
key_name = "${local.default_prefix}-ec2-key" | ||
public_key = tls_private_key.private_key.public_key_openssh | ||
} | ||
|
||
|
||
data "aws_ami" "ecs_ami" { | ||
most_recent = true | ||
owners = ["amazon"] | ||
|
||
filter { | ||
name = "name" | ||
values = ["amzn2-ami-ecs-hvm-*-x86_64-ebs"] | ||
} | ||
} | ||
|
||
resource "aws_instance" "ecs_instance" { | ||
ami = data.aws_ami.ecs_ami.id | ||
instance_type = var.ec2_type | ||
key_name = aws_key_pair.generated_key.key_name | ||
iam_instance_profile = aws_iam_instance_profile.ecs_instance_profile.name | ||
|
||
user_data = <<-EOF | ||
#!/bin/bash | ||
echo ECS_CLUSTER=${aws_ecs_cluster.eml_cluster.name} >> /etc/ecs/ecs.config | ||
EOF | ||
|
||
subnet_id = data.aws_subnets.default.ids[0] | ||
|
||
vpc_security_group_ids = [aws_security_group.app_sg.id] | ||
|
||
associate_public_ip_address = true | ||
|
||
tags = { | ||
Name = "${local.default_prefix}-ecs-instance" | ||
} | ||
depends_on = [aws_ecs_cluster.eml_cluster] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
resource "aws_iam_role" "ecs_execution_role" { | ||
name = "${local.default_prefix}-execution-role" | ||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "ecs-tasks.amazonaws.com" | ||
}, | ||
Action = "sts:AssumeRole" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role" "ecs_task_role" { | ||
name = "${local.default_prefix}-task-role" | ||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "ecs-tasks.amazonaws.com" | ||
}, | ||
Action = "sts:AssumeRole" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_policy" "ecr_policy" { | ||
name = "${local.default_prefix}_ECR_Access_Policy" | ||
description = "Allows ECS execution role to pull from ECR" | ||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Action = [ | ||
"ecr:GetAuthorizationToken", | ||
"ecr:BatchCheckLayerAvailability", | ||
"ecr:GetDownloadUrlForLayer", | ||
"ecr:BatchGetImage" | ||
], | ||
Resource = "*" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_policy" "logs_service_policy" { | ||
name = "${local.default_prefix}_Logs_Service_Policy" | ||
description = "Allows service to log" | ||
policy = jsonencode({ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": [ | ||
"${aws_cloudwatch_log_group.ecs_service_logs.arn}:*" | ||
] | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "ecr_policy_attachment" { | ||
role = aws_iam_role.ecs_execution_role.name | ||
policy_arn = aws_iam_policy.ecr_policy.arn | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "log_policy_attachment" { | ||
role = aws_iam_role.ecs_execution_role.name | ||
policy_arn = aws_iam_policy.logs_service_policy.arn | ||
} |
Oops, something went wrong.