-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (77 loc) · 2.98 KB
/
Copy pathdeploy.yml
File metadata and controls
92 lines (77 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Deploy to AWS ECS
on:
push:
branches: [ main, interface ]
paths:
- 'interface/backend/**'
- 'Dockerfile'
- '.github/workflows/**'
# Allow manual triggering
workflow_dispatch:
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: bioinfo/repo
ECS_SERVICE: prism-api-service-0u9t6ggt
ECS_CLUSTER: bioinfo-cluster
ECS_TASK_DEFINITION: prism-api
CONTAINER_NAME: prism-container
jobs:
deploy:
name: Deploy to ECS
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build Docker image for x86_64 (ECS Fargate compatibility)
docker buildx build \
--platform linux/amd64 \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:latest \
--push .
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition \
--task-definition $ECS_TASK_DEFINITION \
--query taskDefinition > task-definition-raw.json
# Clean task definition by removing unsupported fields for GitHub Actions
jq 'del(.enableFaultInjection, .taskDefinitionArn, .revision, .status, .requiresCompatibilities, .placementConstraints, .compatibilities, .registeredAt, .registeredBy)' \
task-definition-raw.json > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
- name: Service deployment summary
run: |
echo "🚀 Deployment successful!"
echo "📦 Image: ${{ steps.build-image.outputs.image }}"
echo "🎯 Service: ${{ env.ECS_SERVICE }}"
echo "🔗 Check your ALB URL for the updated API"