-
Notifications
You must be signed in to change notification settings - Fork 7
142 lines (114 loc) · 8.28 KB
/
deployment.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Deployment (all)
on:
push:
branches:
- PROD
- STAGING
env:
EC2_PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }}
PROD_IP: ${{ secrets.PROD_IP }}
STAGING_IP: ${{ secrets.STAGING_IP }}
GAME_CLIENT_PORT: ${{ secrets.GAME_CLIENT_PORT }}
CONNECTION_STRING_PROD: ${{ secrets.CONNECTION_STRING_PROD }}
REST_SERVICE_IP_PROD: ${{ secrets.REST_SERVICE_IP_PROD }}
REST_SERVICE_PORT_PROD: ${{ secrets.REST_SERVICE_PORT_PROD }}
ATLAS_CHART_EMBED_DASHBOARD_URL_PROD: ${{ secrets.ATLAS_CHART_EMBED_DASHBOARD_URL_PROD }}
ATLAS_CHART_ID_EVENT_PROD: ${{ secrets.ATLAS_CHART_ID_EVENT_PROD }}
ATLAS_CHART_ID_PLAYER_PROD: ${{ secrets.ATLAS_CHART_ID_PLAYER_PROD }}
ATLAS_CHART_ID_HOME_PROD: ${{ secrets.ATLAS_CHART_ID_HOME_PROD }}
ATLAS_CHART_ID_SIMILAR_PROD: ${{ secrets.ATLAS_CHART_ID_SIMILAR_PROD }}
CONNECTION_STRING_STAGING: ${{ secrets.CONNECTION_STRING_STAGING }}
REST_SERVICE_IP_STAGING: ${{ secrets.REST_SERVICE_IP_STAGING }}
REST_SERVICE_PORT_STAGING: ${{ secrets.REST_SERVICE_PORT_STAGING }}
ATLAS_CHART_EMBED_DASHBOARD_URL_STAGING: ${{ secrets.ATLAS_CHART_EMBED_DASHBOARD_URL_STAGING }}
ATLAS_CHART_ID_EVENT_STAGING: ${{ secrets.ATLAS_CHART_ID_EVENT_STAGING }}
ATLAS_CHART_ID_PLAYER_STAGING: ${{ secrets.ATLAS_CHART_ID_PLAYER_STAGING}}
ATLAS_CHART_ID_HOME_STAGING: ${{ secrets.ATLAS_CHART_ID_HOME_STAGING }}
ATLAS_CHART_ID_SIMILAR_STAGING: ${{ secrets.ATLAS_CHART_ID_SIMILAR_STAGING }}
jobs:
deployment:
runs-on: ubuntu-latest
steps:
# Environment
- name: Set Environment Variables For PROD And STAGING
run: |
if [ "${{ github.ref }}" == "refs/heads/STAGING" ]; then
echo "ENVIRONMENT_IP=${STAGING_IP}" >> $GITHUB_ENV
echo "DATABASE_NAME=Leafsteroids_stage" >> $GITHUB_ENV
echo "CONNECTION_STRING=${CONNECTION_STRING_STAGING}" >> $GITHUB_ENV
echo "REST_SERVICE_IP=${REST_SERVICE_IP_STAGING}" >> $GITHUB_ENV
echo "REST_SERVICE_PORT=${REST_SERVICE_PORT_STAGING}" >> $GITHUB_ENV
echo "ATLAS_CHART_EMBED_DASHBOARD_URL=${ATLAS_CHART_EMBED_DASHBOARD_URL_STAGING}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_EVENT=${ATLAS_CHART_ID_EVENT_STAGING}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_PLAYER=${ATLAS_CHART_ID_PLAYER_STAGING}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_HOME=${ATLAS_CHART_ID_HOME_STAGING}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_SIMILAR=${ATLAS_CHART_ID_SIMILAR_STAGING}" >> $GITHUB_ENV
echo "GAME_CLIENT_PORT=${GAME_CLIENT_PORT}" >> $GITHUB_ENV
else
echo "ENVIRONMENT_IP=${PROD_IP}" >> $GITHUB_ENV
echo "DATABASE_NAME=Leafsteroids" >> $GITHUB_ENV
echo "CONNECTION_STRING=${CONNECTION_STRING_PROD}" >> $GITHUB_ENV
echo "REST_SERVICE_IP=${REST_SERVICE_IP_PROD}" >> $GITHUB_ENV
echo "REST_SERVICE_PORT=${REST_SERVICE_PORT_PROD}" >> $GITHUB_ENV
echo "ATLAS_CHART_EMBED_DASHBOARD_URL=${ATLAS_CHART_EMBED_DASHBOARD_URL_PROD}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_EVENT=${ATLAS_CHART_ID_EVENT_PROD}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_PLAYER=${ATLAS_CHART_ID_PLAYER_PROD}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_HOME=${ATLAS_CHART_ID_HOME_PROD}" >> $GITHUB_ENV
echo "ATLAS_CHART_ID_SIMILAR=${ATLAS_CHART_ID_SIMILAR_PROD}" >> $GITHUB_ENV
echo "GAME_CLIENT_PORT=${GAME_CLIENT_PORT}" >> $GITHUB_ENV
fi
- name: Checkout Code
uses: actions/checkout@v3
- name: Create SSH Key File
run: |
echo "${EC2_PRIVATE_KEY}" > ec2_private_key.pem
chmod 400 ec2_private_key.pem
- name: Install .NET SDK 7 On The AWS EC2 Instance
run: |
echo ${{ env.ENVIRONMENT_IP }}
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0'
# REST service
- name: Create The .env File Inside The `rest_service` Directory
run: |
echo "CONNECTION_STRING=${{ env.CONNECTION_STRING }}" > ./rest_service/.env
echo "DATABASE_NAME=${{ env.DATABASE_NAME }}" >> ./rest_service/.env
- name: Copy The rest_service Directory To The AWS EC2 Instance
run: |
ssh -o StrictHostKeyChecking=no -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} "rm -rf /home/ubuntu/rest_service && mkdir /home/ubuntu/rest_service"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem -r ./rest_service ubuntu@${{ env.ENVIRONMENT_IP }}:/home/ubuntu/
- name: Copy The Systemd Service To The AWS EC2 Instance
run: |
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem deployment/rest_service.service ubuntu@${{ env.ENVIRONMENT_IP }}:/home/ubuntu/rest_service.service
- name: Enable And Start The Systemd Service On The AWS EC2 Instance
run: |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo mv /home/ubuntu/rest_service.service /etc/systemd/system/rest_service.service'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl enable rest_service.service'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl daemon-reload'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl start rest_service.service'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl restart rest_service.service'
# Website
- name: Create The .env File Inside website Directory
run: |
echo "REST_SERVICE_IP=${{ env.REST_SERVICE_IP }}" > ./website/.env
echo "REST_SERVICE_PORT=${{ env.REST_SERVICE_PORT }}" >> ./website/.env
echo "ATLAS_CHART_EMBED_DASHBOARD_URL=${{ env.ATLAS_CHART_EMBED_DASHBOARD_URL }}" >> ./website/.env
echo "ATLAS_CHART_ID_EVENT=${{ env.ATLAS_CHART_ID_EVENT }}" >> ./website/.env
echo "ATLAS_CHART_ID_PLAYER=${{ env.ATLAS_CHART_ID_PLAYER }}" >> ./website/.env
echo "ATLAS_CHART_ID_HOME=${{ env.ATLAS_CHART_ID_HOME }}" >> ./website/.env
echo "ATLAS_CHART_ID_HOME=${{ env.ATLAS_CHART_ID_HOME }}" >> ./website/.env
echo "ATLAS_CHART_ID_SIMILAR=${{ env.ATLAS_CHART_ID_SIMILAR }}" >> ./website/.env
echo "GAME_CLIENT_PORT=${{ env.GAME_CLIENT_PORT }}" >> ./website/.env
- name: Copy The website Directory To The AWS EC2 Instance
run: |
ssh -o StrictHostKeyChecking=no -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} "rm -rf /home/ubuntu/website && mkdir /home/ubuntu/website"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem -r ./website ubuntu@${{ env.ENVIRONMENT_IP }}:/home/ubuntu/
- name: Copy The Systemd Service To The AWS EC2 Instance
run: |
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem deployment/website.service ubuntu@${{ env.ENVIRONMENT_IP }}:/home/ubuntu/website.service
- name: Enable And Start The Systemd Service On The AWS EC2 Instance
run: |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo mv /home/ubuntu/website.service /etc/systemd/system/website.service'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl enable website.service'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl daemon-reload'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl start website.service'
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ec2_private_key.pem ubuntu@${{ env.ENVIRONMENT_IP }} 'sudo systemctl restart website.service'