-
Notifications
You must be signed in to change notification settings - Fork 17
88 lines (74 loc) · 3.24 KB
/
release.yml
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
# This workflow, upon a published release:
# - validates tag version matches package.json
# - deploys to ECS
# ECS publish sourced from:
# - https://docs.github.com/en/actions/use-cases-and-examples/deploying/deploying-to-amazon-elastic-container-service
name: Deploy
on:
release:
types: [published]
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: hackillinois/adonix
ECS_CLUSTER: adonix-cluster
ECS_SERVICE: adonix-service
CONTAINER_NAME: adonix
TASK_FAMILY_NAME: adonix
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate package.json version matches git tag
run: |
PACKAGE_VERSION=$(jq -r .version package.json)
# Remove 'v' prefix from git tag if present
GIT_TAG_VERSION=${GITHUB_REF#refs/tags/}
GIT_TAG_VERSION=${GIT_TAG_VERSION#v}
if [ "$PACKAGE_VERSION" != "$GIT_TAG_VERSION" ]; then
echo "Version mismatch! package.json version ($PACKAGE_VERSION) does not match git tag version ($GIT_TAG_VERSION)"
exit 1
fi
echo "Versions match! ($PACKAGE_VERSION)"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
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
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Caching through args is from: https://aws.amazon.com/blogs/containers/announcing-remote-cache-support-in-amazon-ecr-for-buildkit-clients/
- name: Build, tag, and push to ECR
id: build-image
uses: docker/build-push-action@v6
env:
ECR_URI: ${{ steps.login.outputs.registry }}/${{ env.ECR_REPOSITORY }}
with:
push: true
tags: ${{ env.ECR_URI }}:${{ github.sha }}
cache-from: type=registry,ref=${{ env.ECR_URI }}:cache
cache-to: type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${{ env.ECR_URI }}:cache
- name: Download current task definition
run: |
aws ecs describe-task-definition --task-definition $TASK_FAMILY_NAME --query taskDefinition > 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@c804dfbdd57f713b6c079302a4c01db7017a36fc
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.login.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
cluster: ${{ env.ECS_CLUSTER }}
service: ${{ env.ECS_SERVICE }}
wait-for-service-stability: true