Skip to content

Commit 537f992

Browse files
committed
Add AWS deployment configuration and ECS setup
1 parent cf17f34 commit 537f992

9 files changed

Lines changed: 117 additions & 14 deletions

File tree

.github/workflows/aws-deploy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy to AWS ECS
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
14+
- name: Configure AWS credentials
15+
uses: aws-actions/configure-aws-credentials@v2
16+
with:
17+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
18+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
19+
aws-region: ca-central-1
20+
21+
- name: Build Docker images
22+
run: |
23+
docker build -t dotnet-app ./docker/dotnet
24+
docker build -t mlapi-app ./docker/mlapi
25+
26+
- name: Push to ECR (manual tagging required)
27+
run: echo "Push commands to ECR should be added here"

backend/MLWrapper.API/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# .NET 8 SDK image
12
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
23
WORKDIR /app
3-
EXPOSE 5000
4+
EXPOSE 80
45

56
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
67
WORKDIR /src
@@ -11,4 +12,4 @@ RUN dotnet publish -c Release -o /app/publish
1112
FROM base AS final
1213
WORKDIR /app
1314
COPY --from=build /app/publish .
14-
ENTRYPOINT ["dotnet", "MLWrapper.API.dll"]
15+
ENTRYPOINT ["dotnet", "MLWrapper.API.dll"]

backend/MLWrapper.API/obj/MLWrapper.API.csproj.nuget.dgspec.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"format": 1,
33
"restore": {
4-
"c:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj": {}
4+
"C:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj": {}
55
},
66
"projects": {
7-
"c:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj": {
7+
"C:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj": {
88
"version": "1.0.0",
99
"restore": {
10-
"projectUniqueName": "c:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj",
10+
"projectUniqueName": "C:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj",
1111
"projectName": "MLWrapper.API",
12-
"projectPath": "c:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj",
12+
"projectPath": "C:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj",
1313
"packagesPath": "C:\\Users\\e-nis\\.nuget\\packages\\",
14-
"outputPath": "c:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\obj\\",
14+
"outputPath": "C:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\obj\\",
1515
"projectStyle": "PackageReference",
1616
"fallbackFolders": [
1717
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"

backend/MLWrapper.API/obj/project.nuget.cache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"version": 2,
3-
"dgSpecHash": "l3HaTW2vqpI=",
3+
"dgSpecHash": "d8l8/xwF2wY=",
44
"success": true,
5-
"projectFilePath": "c:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj",
5+
"projectFilePath": "C:\\Projects\\FullStackMLWrapper\\backend\\MLWrapper.API\\MLWrapper.API.csproj",
66
"expectedPackageFiles": [
77
"C:\\Users\\e-nis\\.nuget\\packages\\microsoft.aspnetcore.openapi\\8.0.6\\microsoft.aspnetcore.openapi.8.0.6.nupkg.sha512",
88
"C:\\Users\\e-nis\\.nuget\\packages\\microsoft.openapi\\1.4.3\\microsoft.openapi.1.4.3.nupkg.sha512"

python-ml/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM python:3.11-slim
1+
FROM python:3.10-slim
2+
23
WORKDIR /app
3-
COPY requirements.txt .
4+
COPY . /app
5+
46
RUN pip install --no-cache-dir -r requirements.txt
5-
COPY . .
6-
EXPOSE 8000
7-
CMD ["python", "app.py"]
7+
8+
EXPOSE 5000
9+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]

terraform/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "aws" {
2+
region = "ca-central-1"
3+
}
4+
5+
module "ecr" {
6+
source = "./modules/ecr"
7+
}
8+
9+
module "ecs" {
10+
source = "./modules/ecs"
11+
}

terraform/modules/ecr/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_ecr_repository" "dotnet" {
2+
name = "${var.app_name}-dotnet"
3+
}
4+
5+
resource "aws_ecr_repository" "mlapi" {
6+
name = "${var.app_name}-mlapi"
7+
}

terraform/modules/ecs/main.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
resource "aws_ecs_cluster" "this" {
2+
name = "${var.app_name}-cluster"
3+
}
4+
5+
resource "aws_ecs_task_definition" "dotnet" {
6+
family = "${var.app_name}-dotnet-task"
7+
requires_compatibilities = ["FARGATE"]
8+
network_mode = "awsvpc"
9+
cpu = "256"
10+
memory = "512"
11+
execution_role_arn = "arn:aws:iam::YOUR_ACCOUNT_ID:role/ecsTaskExecutionRole"
12+
container_definitions = <<DEFINITION
13+
[
14+
{
15+
"name": "dotnet-container",
16+
"image": "YOUR_ECR_IMAGE_URL_DOTNET",
17+
"essential": true,
18+
"portMappings": [
19+
{
20+
"containerPort": 80,
21+
"hostPort": 80
22+
}
23+
]
24+
}
25+
]
26+
DEFINITION
27+
}
28+
29+
resource "aws_ecs_task_definition" "mlapi" {
30+
family = "${var.app_name}-mlapi-task"
31+
requires_compatibilities = ["FARGATE"]
32+
network_mode = "awsvpc"
33+
cpu = "256"
34+
memory = "512"
35+
execution_role_arn = "arn:aws:iam::YOUR_ACCOUNT_ID:role/ecsTaskExecutionRole"
36+
container_definitions = <<DEFINITION
37+
[
38+
{
39+
"name": "mlapi-container",
40+
"image": "YOUR_ECR_IMAGE_URL_MLAPI",
41+
"essential": true,
42+
"portMappings": [
43+
{
44+
"containerPort": 5000,
45+
"hostPort": 5000
46+
}
47+
]
48+
}
49+
]
50+
DEFINITION
51+
}

terraform/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "app_name" {
2+
description = "Name of the application"
3+
default = "fullstackmlwrapper"
4+
}

0 commit comments

Comments
 (0)