ourteam commited on
Commit
21eebbf
·
1 Parent(s): 2851b1f

set env staging

Browse files
.aws/task-definition-production.json ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "taskDefinitionArn": "arn:aws:ecs:ap-southeast-1:537124935427:task-definition/production-ourcoach-backend:1",
3
+ "containerDefinitions": [
4
+ {
5
+ "name": "ourcoach-backend",
6
+ "image": "537124935427.dkr.ecr.ap-southeast-1.amazonaws.com/production/ourcoach-backend:a3bc1e9d281202be3aef692f06fecfeb768eb280",
7
+ "cpu": 256,
8
+ "memory": 512,
9
+ "portMappings": [
10
+ {
11
+ "name": "8100",
12
+ "containerPort": 8100,
13
+ "hostPort": 8100,
14
+ "protocol": "tcp",
15
+ "appProtocol": "http"
16
+ }
17
+ ],
18
+ "essential": true,
19
+ "environment": [],
20
+ "environmentFiles": [],
21
+ "mountPoints": [],
22
+ "volumesFrom": [],
23
+ "ulimits": [],
24
+ "logConfiguration": {
25
+ "logDriver": "awslogs",
26
+ "options": {
27
+ "awslogs-group": "/ecs/production-ourcoach-backend",
28
+ "mode": "non-blocking",
29
+ "awslogs-create-group": "true",
30
+ "max-buffer-size": "25m",
31
+ "awslogs-region": "ap-southeast-1",
32
+ "awslogs-stream-prefix": "ecs"
33
+ },
34
+ "secretOptions": []
35
+ },
36
+ "systemControls": []
37
+ }
38
+ ],
39
+ "family": "production-ourcoach-backend",
40
+ "taskRoleArn": "arn:aws:iam::537124935427:role/ecsTaskExecutionRole",
41
+ "executionRoleArn": "arn:aws:iam::537124935427:role/ecsTaskExecutionRole",
42
+ "networkMode": "awsvpc",
43
+ "revision": 1,
44
+ "volumes": [],
45
+ "status": "ACTIVE",
46
+ "requiresAttributes": [
47
+ {
48
+ "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
49
+ },
50
+ {
51
+ "name": "ecs.capability.execution-role-awslogs"
52
+ },
53
+ {
54
+ "name": "com.amazonaws.ecs.capability.ecr-auth"
55
+ },
56
+ {
57
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
58
+ },
59
+ {
60
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28"
61
+ },
62
+ {
63
+ "name": "com.amazonaws.ecs.capability.task-iam-role"
64
+ },
65
+ {
66
+ "name": "ecs.capability.execution-role-ecr-pull"
67
+ },
68
+ {
69
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
70
+ },
71
+ {
72
+ "name": "ecs.capability.task-eni"
73
+ },
74
+ {
75
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
76
+ }
77
+ ],
78
+ "placementConstraints": [],
79
+ "compatibilities": ["EC2", "FARGATE"],
80
+ "requiresCompatibilities": ["FARGATE"],
81
+ "cpu": "256",
82
+ "memory": "512",
83
+ "runtimePlatform": {
84
+ "cpuArchitecture": "X86_64",
85
+ "operatingSystemFamily": "LINUX"
86
+ },
87
+ "registeredAt": "2024-10-16T15:49:35.603Z",
88
+ "registeredBy": "arn:aws:iam::537124935427:user/besher",
89
+ "tags": []
90
+ }
.aws/task-definition-staging.json ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "taskDefinitionArn": "arn:aws:ecs:ap-southeast-1:537124935427:task-definition/staging-ourcoach-ai-core:1",
3
+ "containerDefinitions": [
4
+ {
5
+ "name": "ourcoach-ai-core",
6
+ "image": "537124935427.dkr.ecr.ap-southeast-1.amazonaws.com/staging/ourcoach-ai-core",
7
+ "cpu": 256,
8
+ "memory": 512,
9
+ "portMappings": [
10
+ {
11
+ "name": "7860",
12
+ "containerPort": 7860,
13
+ "hostPort": 7860,
14
+ "protocol": "tcp",
15
+ "appProtocol": "http"
16
+ }
17
+ ],
18
+ "essential": true,
19
+ "environment": [],
20
+ "environmentFiles": [],
21
+ "mountPoints": [],
22
+ "volumesFrom": [],
23
+ "ulimits": [],
24
+ "logConfiguration": {
25
+ "logDriver": "awslogs",
26
+ "options": {
27
+ "awslogs-group": "/ecs/staging-ourcoach-ai-core",
28
+ "mode": "non-blocking",
29
+ "awslogs-create-group": "true",
30
+ "max-buffer-size": "25m",
31
+ "awslogs-region": "ap-southeast-1",
32
+ "awslogs-stream-prefix": "ecs"
33
+ },
34
+ "secretOptions": []
35
+ },
36
+ "systemControls": []
37
+ }
38
+ ],
39
+ "family": "staging-ourcoach-ai-core",
40
+ "taskRoleArn": "arn:aws:iam::537124935427:role/ecsTaskExecutionRole",
41
+ "executionRoleArn": "arn:aws:iam::537124935427:role/ecsTaskExecutionRole",
42
+ "networkMode": "awsvpc",
43
+ "revision": 1,
44
+ "volumes": [],
45
+ "status": "ACTIVE",
46
+ "requiresAttributes": [
47
+ {
48
+ "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
49
+ },
50
+ {
51
+ "name": "ecs.capability.execution-role-awslogs"
52
+ },
53
+ {
54
+ "name": "com.amazonaws.ecs.capability.ecr-auth"
55
+ },
56
+ {
57
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
58
+ },
59
+ {
60
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28"
61
+ },
62
+ {
63
+ "name": "com.amazonaws.ecs.capability.task-iam-role"
64
+ },
65
+ {
66
+ "name": "ecs.capability.execution-role-ecr-pull"
67
+ },
68
+ {
69
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
70
+ },
71
+ {
72
+ "name": "ecs.capability.task-eni"
73
+ },
74
+ {
75
+ "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
76
+ }
77
+ ],
78
+ "placementConstraints": [],
79
+ "compatibilities": [
80
+ "EC2",
81
+ "FARGATE"
82
+ ],
83
+ "requiresCompatibilities": [
84
+ "FARGATE"
85
+ ],
86
+ "cpu": "256",
87
+ "memory": "512",
88
+ "runtimePlatform": {
89
+ "cpuArchitecture": "X86_64",
90
+ "operatingSystemFamily": "LINUX"
91
+ },
92
+ "registeredAt": "2024-10-25T11:56:36.943Z",
93
+ "registeredBy": "arn:aws:iam::537124935427:user/besher",
94
+ "enableFaultInjection": false,
95
+ "tags": []
96
+ }
.github/workflows/deploy-production.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deployment Pipeline (Production)
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ id-token: write # This is required for requesting the JWT
10
+ contents: read # This is required for actions/checkout
11
+
12
+ jobs:
13
+ deploy:
14
+ name: Using Deployment Workflow
15
+ uses: ./.github/workflows/deployment.yml
16
+ with:
17
+ active_env: production
18
+ ecr_url: 537124935427.dkr.ecr.ap-southeast-1.amazonaws.com/production/ourcoach-backend
19
+ ecs_service: ourcoach-backend
20
+ ecs_cluster: ProductionECSCluster
21
+ ecs_task_definition: .aws/task-definition-production.json
22
+ container_name: ourcoach-backend
23
+ secrets: inherit
.github/workflows/deploy-staging.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deployment Pipeline (Staging)
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - staging
7
+
8
+ permissions:
9
+ id-token: write # This is required for requesting the JWT
10
+ contents: read # This is required for actions/checkout
11
+
12
+ jobs:
13
+ deploy:
14
+ name: Using Deployment Workflow
15
+ uses: ./.github/workflows/deployment.yml
16
+ with:
17
+ active_env: staging
18
+ ecr_url: 537124935427.dkr.ecr.ap-southeast-1.amazonaws.com/staging/ourcoach-ai-core
19
+ ecs_service: ourcoach-ai-core
20
+ ecs_cluster: StagingECSCluster
21
+ ecs_task_definition: .aws/task-definition-staging.json
22
+ container_name: ourcoach-ai-core
23
+ secrets: inherit
.github/workflows/deployment.yml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Reusable Deployment Workflow
2
+
3
+ on:
4
+ workflow_call:
5
+ inputs:
6
+ active_env:
7
+ required: true
8
+ type: string
9
+ ecr_url:
10
+ required: true
11
+ type: string
12
+ ecs_service:
13
+ required: true
14
+ type: string
15
+ ecs_cluster:
16
+ required: true
17
+ type: string
18
+ ecs_task_definition:
19
+ required: true
20
+ type: string
21
+ container_name:
22
+ required: true
23
+ type: string
24
+
25
+ env:
26
+ AWS_REGION: ap-southeast-1
27
+
28
+ permissions:
29
+ contents: read
30
+ id-token: write
31
+
32
+ jobs:
33
+ deploy:
34
+ name: Deploy
35
+ runs-on: ubuntu-latest
36
+ environment:
37
+ name: ${{ inputs.active_env }}
38
+ steps:
39
+ - name: Checkout
40
+ uses: actions/checkout@v3
41
+
42
+ - name: Configure AWS credentials
43
+ uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
44
+ with:
45
+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
46
+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
47
+ aws-region: ${{ env.AWS_REGION }}
48
+
49
+ - name: Login to Amazon ECR
50
+ id: login-ecr
51
+ uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a
52
+
53
+ - name: Build, tag, and push image to Amazon ECR
54
+ id: build-image
55
+ env:
56
+ IMAGE_TAG: ${{ github.sha }}
57
+ run: |
58
+ docker build --build-arg FASTAPI_KEY=${{secrets.FASTAPI_KEY}} --build-arg OPENAI_KEY=${{secrets.OPENAI_KEY}} -t ${{inputs.ecr_url}}:$IMAGE_TAG .
59
+ docker push ${{inputs.ecr_url}}:$IMAGE_TAG
60
+ echo "image=${{inputs.ecr_url}}:$IMAGE_TAG" >> $GITHUB_OUTPUT
61
+
62
+ - name: Fill in the new image ID in the Amazon ECS task definition
63
+ id: task-def
64
+ uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc
65
+ with:
66
+ task-definition: ${{ inputs.ecs_task_definition }}
67
+ container-name: ${{ inputs.container_name }}
68
+ image: ${{ steps.build-image.outputs.image }}
69
+
70
+ - name: Deploy Amazon ECS task definition
71
+ uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
72
+ with:
73
+ task-definition: ${{ steps.task-def.outputs.task-definition }}
74
+ service: ${{ inputs.ecs_service }}
75
+ cluster: ${{ inputs.ecs_cluster }}
76
+ wait-for-service-stability: true
Dockerfile CHANGED
@@ -1,6 +1,14 @@
1
  # Use the official Python 3.10.9 image
2
  FROM python:3.10.9
3
 
 
 
 
 
 
 
 
 
4
  # Copy the current directory contents into the container at .
5
  COPY . .
6
 
 
1
  # Use the official Python 3.10.9 image
2
  FROM python:3.10.9
3
 
4
+
5
+ ARG FASTAPI_KEY
6
+ ARG OPENAI_KEY
7
+
8
+ ENV FASTAPI_KEY=$FASTAPI_KEY
9
+ ENV OPENAI_KEY=$OPENAI_KEY
10
+
11
+
12
  # Copy the current directory contents into the container at .
13
  COPY . .
14