Skip to content

Commit 3a07bd0

Browse files
committed
config files are ready for the deployment
1 parent a28485f commit 3a07bd0

File tree

6 files changed

+313
-1
lines changed

6 files changed

+313
-1
lines changed

.github/workflows/aws.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Deploy to Amazon ECS
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
env:
9+
AWS_REGION: us-east-1
10+
ECR_REPOSITORY: documentportal
11+
ECS_SERVICE: document-portal-service
12+
ECS_CLUSTER: document-portal-cluster
13+
ECS_TASK_DEFINITION: .github/workflows/task-definition.json
14+
CONTAINER_NAME: document-portal-container
15+
16+
permissions:
17+
id-token: write
18+
contents: read
19+
20+
jobs:
21+
deploy:
22+
name: Deploy
23+
runs-on: ubuntu-latest
24+
environment: production
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
30+
- name: Configure AWS credentials
31+
uses: aws-actions/configure-aws-credentials@v1
32+
with:
33+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
34+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
35+
aws-region: ${{ env.AWS_REGION }}
36+
37+
- name: Deploy ECR stack (optional)
38+
run: |
39+
aws cloudformation deploy \
40+
--template-file .github/workflows/template.yml \
41+
--stack-name ecr-repo-stack \
42+
--region ${{ env.AWS_REGION }} \
43+
--capabilities CAPABILITY_NAMED_IAM
44+
45+
- name: Login to Amazon ECR
46+
id: login-ecr
47+
uses: aws-actions/amazon-ecr-login@v1
48+
49+
- name: Build, tag, and push image to Amazon ECR
50+
id: build-image
51+
env:
52+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
53+
IMAGE_TAG: ${{ github.sha }}
54+
run: |
55+
IMAGE_URI=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
56+
docker build -t $IMAGE_URI .
57+
docker push $IMAGE_URI
58+
echo "image=$IMAGE_URI" >> $GITHUB_OUTPUT
59+
60+
- name: Fill in the new image ID in the Amazon ECS task definition
61+
id: task-def
62+
uses: aws-actions/amazon-ecs-render-task-definition@v1
63+
with:
64+
task-definition: ${{ env.ECS_TASK_DEFINITION }}
65+
container-name: ${{ env.CONTAINER_NAME }}
66+
image: ${{ steps.build-image.outputs.image }}
67+
68+
- name: Deploy Amazon ECS task definition
69+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
70+
with:
71+
task-definition: ${{ steps.task-def.outputs.task-definition }}
72+
service: ${{ env.ECS_SERVICE }}
73+
cluster: ${{ env.ECS_CLUSTER }}
74+
wait-for-service-stability: true
75+
76+
- name: Deployment success message
77+
run: echo "Deployment successful! App is live on ECS Fargate."
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"family": "documentportaltd",
3+
"networkMode": "awsvpc",
4+
"executionRoleArn": "arn:aws:iam::685057748560:role/ecsTaskExecutionRole",
5+
"requiresCompatibilities": ["FARGATE"],
6+
"cpu": "1024",
7+
"memory": "8192",
8+
"containerDefinitions": [
9+
{
10+
"name": "document-portal-container",
11+
"image": "685057748560.dkr.ecr.us-east-1.amazonaws.com/documentportal:latest",
12+
"cpu": 1024,
13+
"essential": true,
14+
"portMappings": [
15+
{
16+
"containerPort": 8080,
17+
"hostPort": 8080,
18+
"protocol": "tcp",
19+
"name": "document-portal-container-8080-tcp",
20+
"appProtocol": "http"
21+
}
22+
],
23+
"environment": [
24+
{
25+
"name": "LANGCHAIN_PROJECT",
26+
"value": "DOCUMENT PORTAL"
27+
}
28+
],
29+
"secrets": [
30+
{
31+
"name": "GROQ_API_KEY",
32+
"valueFrom": "arn:aws:secretsmanager:us-east-1:685057748560:secret:GROQ_API_KEY"
33+
},
34+
{
35+
"name": "HF_TOKEN",
36+
"valueFrom": "arn:aws:secretsmanager:us-east-1:685057748560:secret:HF_TOKEN"
37+
},
38+
{
39+
"name": "GOOGLE_API_KEY",
40+
"valueFrom": "arn:aws:secretsmanager:us-east-1:685057748560:secret:GOOGLE_API_KEY"
41+
},
42+
{
43+
"name": "LANGCHAIN_API_KEY",
44+
"valueFrom": "arn:aws:secretsmanager:us-east-1:685057748560:secret:LANGCHAIN_API_KEY"
45+
}
46+
],
47+
"logConfiguration": {
48+
"logDriver": "awslogs",
49+
"options": {
50+
"awslogs-group": "/ecs/documentportaltd",
51+
"awslogs-region": "us-east-1",
52+
"awslogs-stream-prefix": "ecs",
53+
"awslogs-create-group": "false",
54+
"mode": "non-blocking",
55+
"max-buffer-size": "25m"
56+
}
57+
}
58+
}
59+
]
60+
}

.github/workflows/template.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: CloudFormation template to create ECR + ECS infra for Document Portal
3+
4+
Parameters:
5+
VpcCIDR:
6+
Type: String
7+
Default: 10.0.0.0/16
8+
9+
Subnet1CIDR:
10+
Type: String
11+
Default: 10.0.1.0/24
12+
13+
Subnet2CIDR:
14+
Type: String
15+
Default: 10.0.2.0/24
16+
17+
ImageUrl:
18+
Type: String
19+
Description: ECR Image URI to use for container
20+
21+
Resources:
22+
MyECRRepository:
23+
Type: AWS::ECR::Repository
24+
Properties:
25+
RepositoryName: documentportal
26+
ImageScanningConfiguration:
27+
scanOnPush: true
28+
ImageTagMutability: MUTABLE
29+
30+
MyVPC:
31+
Type: AWS::EC2::VPC
32+
Properties:
33+
CidrBlock: !Ref VpcCIDR
34+
EnableDnsSupport: true
35+
EnableDnsHostnames: true
36+
Tags:
37+
- Key: Name
38+
Value: ecs-vpc
39+
40+
Subnet1:
41+
Type: AWS::EC2::Subnet
42+
Properties:
43+
VpcId: !Ref MyVPC
44+
CidrBlock: !Ref Subnet1CIDR
45+
AvailabilityZone: !Select [0, !GetAZs '']
46+
MapPublicIpOnLaunch: true
47+
Tags:
48+
- Key: Name
49+
Value: public-subnet-1
50+
51+
Subnet2:
52+
Type: AWS::EC2::Subnet
53+
Properties:
54+
VpcId: !Ref MyVPC
55+
CidrBlock: !Ref Subnet2CIDR
56+
AvailabilityZone: !Select [1, !GetAZs '']
57+
MapPublicIpOnLaunch: true
58+
Tags:
59+
- Key: Name
60+
Value: public-subnet-2
61+
62+
InternetGateway:
63+
Type: AWS::EC2::InternetGateway
64+
65+
AttachGateway:
66+
Type: AWS::EC2::VPCGatewayAttachment
67+
Properties:
68+
VpcId: !Ref MyVPC
69+
InternetGatewayId: !Ref InternetGateway
70+
71+
RouteTable:
72+
Type: AWS::EC2::RouteTable
73+
Properties:
74+
VpcId: !Ref MyVPC
75+
76+
PublicRoute:
77+
Type: AWS::EC2::Route
78+
DependsOn: AttachGateway
79+
Properties:
80+
RouteTableId: !Ref RouteTable
81+
DestinationCidrBlock: 0.0.0.0/0
82+
GatewayId: !Ref InternetGateway
83+
84+
RouteAssoc1:
85+
Type: AWS::EC2::SubnetRouteTableAssociation
86+
Properties:
87+
SubnetId: !Ref Subnet1
88+
RouteTableId: !Ref RouteTable
89+
90+
RouteAssoc2:
91+
Type: AWS::EC2::SubnetRouteTableAssociation
92+
Properties:
93+
SubnetId: !Ref Subnet2
94+
RouteTableId: !Ref RouteTable
95+
96+
ECSCluster:
97+
Type: AWS::ECS::Cluster
98+
Properties:
99+
ClusterName: document-portal-cluster
100+
101+
ECSExecutionRole:
102+
Type: AWS::IAM::Role
103+
Properties:
104+
AssumeRolePolicyDocument:
105+
Version: '2012-10-17'
106+
Statement:
107+
- Effect: Allow
108+
Principal:
109+
Service: ecs-tasks.amazonaws.com
110+
Action: sts:AssumeRole
111+
ManagedPolicyArns:
112+
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
113+
114+
ECSSecurityGroup:
115+
Type: AWS::EC2::SecurityGroup
116+
Properties:
117+
GroupDescription: Allow access to container port
118+
VpcId: !Ref MyVPC
119+
SecurityGroupIngress:
120+
- IpProtocol: tcp
121+
FromPort: 8080
122+
ToPort: 8080
123+
CidrIp: 0.0.0.0/0
124+
125+
ECSTaskDefinition:
126+
Type: AWS::ECS::TaskDefinition
127+
Properties:
128+
Family: documentportaltd
129+
Cpu: 256
130+
Memory: 512
131+
NetworkMode: awsvpc
132+
RequiresCompatibilities:
133+
- FARGATE
134+
ExecutionRoleArn: !GetAtt ECSExecutionRole.Arn
135+
ContainerDefinitions:
136+
- Name: document-portal-container
137+
Image: !Ref ImageUrl
138+
PortMappings:
139+
- ContainerPort: 8080
140+
Essential: true
141+
LogConfiguration:
142+
LogDriver: awslogs
143+
Options:
144+
awslogs-group: /ecs/documentportal
145+
awslogs-region: !Ref AWS::Region
146+
awslogs-stream-prefix: ecs
147+
148+
ECSService:
149+
Type: AWS::ECS::Service
150+
DependsOn: AttachGateway
151+
Properties:
152+
ServiceName: document-portal-service
153+
Cluster: !Ref ECSCluster
154+
LaunchType: FARGATE
155+
DesiredCount: 1
156+
NetworkConfiguration:
157+
AwsvpcConfiguration:
158+
AssignPublicIp: ENABLED
159+
Subnets:
160+
- !Ref Subnet1
161+
- !Ref Subnet2
162+
SecurityGroups:
163+
- !Ref ECSSecurityGroup
164+
TaskDefinition: !Ref ECSTaskDefinition
165+
166+
Outputs:
167+
ECSClusterName:
168+
Value: !Ref ECSCluster
169+
170+
TaskDefinitionArn:
171+
Value: !Ref ECSTaskDefinition

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ EXPOSE 8080
2828
# Run FastAPI with uvicorn
2929
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8080", "--reload"]
3030

31+
# Replace last CMD in prod
32+
#CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "4"]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ docx2txt==0.9
1616
ipykernel==6.30.0
1717
streamlit==1.47.1
1818
pytest==8.4.1
19+
pypdf=5.8.0
1920

2021
-e .

versions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"fastapi",
1717
"uvicorn",
1818
"python-multipart",
19-
"docx2txt"
19+
"docx2txt",
20+
"pypdf"
2021
]
2122
for pkg in packages:
2223
try:

0 commit comments

Comments
 (0)