-
Notifications
You must be signed in to change notification settings - Fork 1
80 lines (69 loc) · 2.57 KB
/
Copy pathdeploy.yml
File metadata and controls
80 lines (69 loc) · 2.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
on:
push:
branches:
- main
name: Deploy to AWS Staging
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
AWS_REGION: us-east-2
ECR_REPO_NAME: ethtx
SERVICE_NAME: ethtx-ce-staging
CLUSTER_NAME: ethtx-ce-staging
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Extract commit hash
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build, tag, test and push image to Amazon ECR
id: build-image
env:
SHA_TAG: ${{ steps.vars.outputs.sha_short }}
LATEST_TAG: latest
ENVIRONMENT_TAG: staging
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
echo "-----------------------"
echo "Build step 1/3: Building docker image"
echo "-----------------------"
docker build -t $ECR_REGISTRY/$ECR_REPO_NAME:$SHA_TAG \
-t $ECR_REGISTRY/$ECR_REPO_NAME:$LATEST_TAG \
-t $ECR_REGISTRY/$ECR_REPO_NAME:$ENVIRONMENT_TAG \
.
echo "-----------------------"
echo "Build step 2/3: Testing builded image"
echo "-----------------------"
docker run $ECR_REGISTRY/$ECR_REPO_NAME:$SHA_TAG make test
echo "-----------------------"
echo "Build step 3/3: Pushing builded image to $ECR_REPO_NAME"
echo "-----------------------"
docker push $ECR_REGISTRY/$ECR_REPO_NAME --all-tags
echo "-----------------------"
- name: Update ECS service with latest Docker image
id: service-update
run: |
aws ecs update-service --cluster $CLUSTER_NAME --service ${{ env.SERVICE_NAME }} --force-new-deployment --region $AWS_REGION
- name: Wait for all services to become stable
uses: oryanmoshe/ecs-wait-action@v1.3
with:
ecs-cluster: ${{ env.CLUSTER_NAME }}
ecs-services: '["${{ env.SERVICE_NAME }}"]'
- name: Invalidate CloudFront
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.STAGING_AWS_CF_ID }} --paths "/*"