Skip to content

Commit b4d8ade

Browse files
authored
Create aws-deploy-live.yml
1 parent 4348554 commit b4d8ade

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Deploy to Amazon ECS LIVE
11+
12+
on: 'workflow_dispatch'
13+
14+
env:
15+
AWS_REGION: us-east-2 # set this to your preferred AWS region, e.g. us-west-1
16+
ECS_CLUSTER: arc-live-cluster # set this to your Amazon ECS cluster name
17+
CONTAINER_NAME: unity
18+
ECS_SERVICE: unity-live-service
19+
ECS_TD: .github/workflows/td.json
20+
21+
jobs:
22+
deploy:
23+
name: Deploy
24+
runs-on: ubuntu-latest
25+
environment: LIVE
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Configure AWS credentials
32+
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
33+
with:
34+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
35+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36+
aws-region: ${{ env.AWS_REGION }}
37+
38+
- name: Login to Amazon ECR
39+
id: login-ecr
40+
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a
41+
42+
- name: Build, tag, and push image to Amazon ECR
43+
id: build-image
44+
env:
45+
ECR_REGISTRY: "140023379914.dkr.ecr.us-east-2.amazonaws.com"
46+
ECR_REPOSITORY: "arc-api-repo"
47+
IMAGE_TAG: ${{ github.sha }}
48+
PORT: ${{ secrets.PORT }}
49+
UNITY_DEBUG: ${{ secrets.UNITY_DEBUG }}
50+
UNITY_BASE_URI: ${{ secrets.UNITY_BASE_URI }}
51+
UNITY_API_BASE_URI: ${{ secrets.UNITY_API_BASE_URI }}
52+
USE_HTTPS: ${{ secrets.USE_HTTPS }}
53+
run: |
54+
touch .env
55+
56+
echo PORT=${{ secrets.PORT }} >> .env
57+
echo UNITY_DEBUG=${{ secrets.UNITY_DEBUG }} >> .env
58+
echo UNITY_BASE_URI=${{ secrets.UNITY_BASE_URI }} >> .env
59+
echo UNITY_API_BASE_URI=${{ secrets.UNITY_API_BASE_URI}} >> .env
60+
echo USE_HTTPS=${{ secrets.USE_HTTPS }} >> .env
61+
62+
cat .env
63+
64+
# Build a docker container and
65+
# push it to ECR so that it can
66+
# be deployed to ECS.
67+
68+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
69+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
70+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
71+
72+
- name: Fill in the new image ID in the Amazon ECS task definition
73+
id: task-def
74+
uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc
75+
with:
76+
task-definition: ${{ env.ECS_TD }}
77+
container-name: ${{ env.CONTAINER_NAME }}
78+
image: ${{ steps.build-image.outputs.image }}
79+
80+
81+
- name: Inject environment in the Amazon ECS task definition
82+
id: add-env-var
83+
uses: cvmaker-bv/amazon-ecs-task-environment@v1
84+
with:
85+
task-definition: ${{ steps.task-def.outputs.task-definition }}
86+
container-name: "unity"
87+
env-variables: "${{ toJson(env) }}"
88+
env:
89+
PORT: ${{ secrets.PORT }}
90+
UNITY_DEBUG: ${{ secrets.UNITY_DEBUG }}
91+
UNITY_BASE_URI: ${{ secrets.UNITY_BASE_URI }}
92+
UNITY_API_BASE_URI: ${{ secrets.UNITY_API_BASE_URI }}
93+
USE_HTTPS: ${{ secrets.USE_HTTPS }}
94+
95+
- name: Deploy Amazon ECS task definition
96+
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
97+
with:
98+
task-definition: ${{ steps.add-env-var.outputs.task-definition }}
99+
service: ${{ env.ECS_SERVICE }}
100+
cluster: ${{ env.ECS_CLUSTER }}
101+
wait-for-service-stability: true

0 commit comments

Comments
 (0)