-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
80 lines (75 loc) · 2.71 KB
/
action.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
name: "Deploy Player"
description: "Deploys Sagat Player Proxy to Adapt"
author: "Adapt"
inputs:
aws-region:
description: "AWS region where servers reside"
required: false
default: "eu-west-1"
deploy-package:
description: "Name of the deployment package"
required: true
role-to-assume:
description: "Role to assume to get access to AWS resources"
required: true
artefact-bucket:
description: "Name of the S3 bucket where artefacts are stored"
required: true
runs:
using: "composite"
steps:
- name: Configure AWS OIDC credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.role-to-assume }}
aws-region: ${{ inputs.aws-region }}
role-session-name: DeployCD
- name: Get Player Servers
id: player_servers
shell: bash
run: |
INSTANCE_IDS=$(aws ec2 describe-instances \
--region $AWS_REGION \
--filters "Name=instance-state-name,Values=running" \
"Name=tag:Name,Values=$SERVER_NAME" \
--query "Reservations[].Instances[].InstanceId" \
--output text)
echo "instance_ids=$INSTANCE_IDS" >> $GITHUB_OUTPUT
env:
SERVER_NAME: player-server
AWS_REGION: ${{ inputs.aws-region }}
- name: Upload artefact
shell: bash
run: |
aws s3 cp $DEPLOY_PACKAGE s3://$S3_BUCKET_NAME/player/$DEPLOY_PACKAGE
env:
DEPLOY_PACKAGE: ${{ inputs.deploy-package }}
S3_BUCKET_NAME: ${{ inputs.artefact-bucket }}
- name: Deploy to Player Servers
shell: bash
run: |
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--instance-ids $INSTANCE_IDS \
--parameters commands=["aws s3 cp s3://$S3_BUCKET_NAME/player/$DEPLOY_PACKAGE ./$DEPLOY_PACKAGE","unzip -o $DEPLOY_PACKAGE -d $DEPLOY_DIR","rm $DEPLOY_PACKAGE"] \
--region $AWS_REGION \
--output text
env:
DEPLOY_PACKAGE: ${{ inputs.deploy-package }}
S3_BUCKET_NAME: ${{ inputs.artefact-bucket }}
INSTANCE_IDS: ${{ steps.player_servers.outputs.instance_ids }}
DEPLOY_DIR: /opt/app
AWS_REGION: ${{ inputs.aws-region }}
- name: Restart servers
shell: bash
run: |
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--instance-ids $INSTANCE_IDS \
--parameters commands=["cd $DEPLOY_DIR && sudo pm2 restart sagat || sudo pm2 start npm --name sagat -- run start"] \
--region $AWS_REGION \
--output text
env:
INSTANCE_IDS: ${{ steps.player_servers.outputs.instance_ids }}
DEPLOY_DIR: /opt/app
AWS_REGION: ${{ inputs.aws-region }}