Repository navigation
109 lines (91 loc) · 3.57 KB
/
Copy pathdeploy-staging.yml
File metadata and controls
109 lines (91 loc) · 3.57 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
name: Deploy Staging
on:
push:
branches:
- staging
workflow_dispatch: {}
jobs:
Publish:
runs-on: ubuntu-latest
steps:
- name: Configure
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.STAGING_AWS_REGION }}
- name: Authenticate
id: authenticate
uses: aws-actions/amazon-ecr-login@v1
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Publish
id: publish
env:
ECR_REPOSITORY: ${{ secrets.STAGING_AWS_ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--build-arg VCS_REF=$IMAGE_TAG \
--build-arg VERSION=$IMAGE_TAG \
--tag $ECR_REPOSITORY:$IMAGE_TAG \
.
docker push $ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REPOSITORY:latest
docker push $ECR_REPOSITORY:latest
echo "::set-output name=image::$ECR_REPOSITORY:$IMAGE_TAG"
- name: Grab
run: |
aws ecs describe-task-definition \
--task-definition ${{ secrets.STAGING_AWS_TASK_DEFINITION }} \
--query taskDefinition > /tmp/task.json
- name: Template
id: template
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: /tmp/task.json
container-name: app
image: ${{ steps.publish.outputs.image }}
- name: Deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
timeout-minutes: 15
with:
task-definition: ${{ steps.template.outputs.task-definition }}
service: staging-genesis76-recognizer
cluster: genesis76-us-east-2
wait-for-service-stability: false
- name: Check ECS Service Status
run: |
echo "Checking ECS service status..."
aws ecs describe-services \
--cluster genesis76-us-east-2 \
--services staging-genesis76-recognizer \
--query 'services[0].{Status:status,RunningCount:runningCount,PendingCount:pendingCount,DesiredCount:desiredCount}'
echo "Getting recent ECS events..."
aws ecs describe-services \
--cluster genesis76-us-east-2 \
--services staging-genesis76-recognizer \
--query 'services[0].events[:10]'
echo "Getting task details..."
TASK_ARN=$(aws ecs list-tasks \
--cluster genesis76-us-east-2 \
--service-name staging-genesis76-recognizer \
--query 'taskArns[0]' --output text)
if [ "$TASK_ARN" != "None" ]; then
echo "Task ARN: $TASK_ARN"
aws ecs describe-tasks \
--cluster genesis76-us-east-2 \
--tasks $TASK_ARN \
--query 'tasks[0].{LastStatus:lastStatus,HealthStatus:healthStatus,CreatedAt:createdAt,StoppedReason:stoppedReason}'
echo "Getting container details..."
aws ecs describe-tasks \
--cluster genesis76-us-east-2 \
--tasks $TASK_ARN \
--query 'tasks[0].containers[?name==`app`].{Name:name,LastStatus:lastStatus,ExitCode:exitCode,Reason:reason}'
else
echo "No tasks found"
fi