-
Notifications
You must be signed in to change notification settings - Fork 1
145 lines (133 loc) · 10.3 KB
/
deploy.yaml
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
143
144
145
name: Deploy
## workflow will need manual trigger from actions page
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
name: Build
uses: ./.github/workflows/build.yaml
permissions:
contents: read
id-token: write
packages: write
deploy:
name: Deploy Railway
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Railway CLI
run: |
bash <(curl -fsSL cli.new)
- name: Install Redis-CLI
uses: shogo82148/actions-setup-redis@v1
with:
redis-version: 7
auto-start: "false"
- name: Install Postgresql client-only
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-client
- name: Get Last Commit Short SHA
id: commit_data
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Cardinal - Shutdown Previous Deployment
working-directory: world-engine/cardinal
run: |
## Get Cardinal Latest Deployment ID
DEPLOYMENT_ID=$(curl --location 'https://backboard.railway.app/graphql/v2' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"query deployments($projectId: String!, $environmentId: String!, $serviceId: String!) {\n deployments(\n first: 1\n input: {\n projectId: $projectId\n environmentId: $environmentId\n serviceId: $serviceId\n }\n ) {\n edges {\n node {\n id\n staticUrl\n }\n }\n }\n}",
"variables":{"projectId":"${{ vars.RAILWAY_PROJECT_ID }}","environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","serviceId":"${{ vars.RAILWAY_CARDINAL_SERVICE_ID }}"}}' | jq -r '.data.deployments.edges[].node.id')
## Remove Deployment
curl --location 'https://backboard.railway.app/graphql/v2' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation deploymentRemove($id: String!) {\n deploymentRemove(id: $id)\n}","variables":{"id":"'${DEPLOYMENT_ID}'"}}'
- name: Clear Up Redis
run: |
sleep 10
redis-cli -h ${{ secrets.PROD_REDIS_HOST }} -p ${{ secrets.PROD_REDIS_PORT }} <<EOF
AUTH ${{ secrets.PROD_REDIS_PASSWORD }}
FLUSHALL
keys *
EOF
- name: Cardinal - Up New Deployment
env:
RAILWAY_TOKEN: ${{ secrets.PROD_RAILWAY_TOKEN }}
run: |
## remove prev docker image
curl --location 'https://backboard.railway.app/graphql/internal?q=stageEnvironmentChanges' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation stageEnvironmentChanges($environmentId: String!, $payload: EnvironmentConfig!) {\n environmentStageChanges(environmentId: $environmentId, input: $payload) {\n id\n }\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","payload":{"services":{"${{ vars.RAILWAY_CARDINAL_SERVICE_ID }}":{"source":{"image":null}}}}}}'
sleep 5
## commit changes
curl --location 'https://backboard.railway.app/graphql/internal?q=environmentPatchCommitStaged' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation environmentPatchCommitStaged($environmentId: String!, $message: String, $skipDeploys: Boolean) {\n environmentPatchCommitStaged(\n environmentId: $environmentId\n commitMessage: $message\n skipDeploys: $skipDeploys\n )\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","skipDeploys":false}}'
sleep 5
## change new docker image
curl --location 'https://backboard.railway.app/graphql/internal?q=stageEnvironmentChanges' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation stageEnvironmentChanges($environmentId: String!, $payload: EnvironmentConfig!) {\n environmentStageChanges(environmentId: $environmentId, input: $payload) {\n id\n }\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","payload":{"services":{"${{ vars.RAILWAY_CARDINAL_SERVICE_ID }}":{"source":{"image":"ghcr.io/franklindao-dev-team/arcanereveal/cardinal:sha-${{ steps.commit_data.outputs.sha_short }}","repo":null,"branch":null,"upstreamUrl":null},"deploy":{"registryCredentials":{"username":"USERNAME","password":"${{ secrets.RAILWAY_GITHUB_REGISTRY_TOKEN }}"}}}}}}}'
sleep 5
## commit changes
curl --location 'https://backboard.railway.app/graphql/internal?q=environmentPatchCommitStaged' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation environmentPatchCommitStaged($environmentId: String!, $message: String, $skipDeploys: Boolean) {\n environmentPatchCommitStaged(\n environmentId: $environmentId\n commitMessage: $message\n skipDeploys: $skipDeploys\n )\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","skipDeploys":false}}'
- name: Godot Client - Up New Deployment
env:
RAILWAY_TOKEN: ${{ secrets.PROD_RAILWAY_TOKEN }}
run: |
## remove prev docker image
curl --location 'https://backboard.railway.app/graphql/internal?q=stageEnvironmentChanges' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation stageEnvironmentChanges($environmentId: String!, $payload: EnvironmentConfig!) {\n environmentStageChanges(environmentId: $environmentId, input: $payload) {\n id\n }\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","payload":{"services":{"${{ vars.RAILWAY_GODOT_SERVICE_ID }}":{"source":{"image":null}}}}}}'
sleep 5
## commit changes
curl --location 'https://backboard.railway.app/graphql/internal?q=environmentPatchCommitStaged' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation environmentPatchCommitStaged($environmentId: String!, $message: String, $skipDeploys: Boolean) {\n environmentPatchCommitStaged(\n environmentId: $environmentId\n commitMessage: $message\n skipDeploys: $skipDeploys\n )\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","skipDeploys":false}}'
sleep 5
## change new docker image
curl --location 'https://backboard.railway.app/graphql/internal?q=stageEnvironmentChanges' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation stageEnvironmentChanges($environmentId: String!, $payload: EnvironmentConfig!) {\n environmentStageChanges(environmentId: $environmentId, input: $payload) {\n id\n }\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","payload":{"services":{"${{ vars.RAILWAY_GODOT_SERVICE_ID }}":{"source":{"image":"ghcr.io/franklindao-dev-team/arcanereveal/godotexport:sha-${{ steps.commit_data.outputs.sha_short }}","repo":null,"branch":null,"upstreamUrl":null},"deploy":{"registryCredentials":{"username":"USERNAME","password":"${{ secrets.RAILWAY_GITHUB_REGISTRY_TOKEN }}"}}}}}}}'
sleep 5
## commit changes
curl --location 'https://backboard.railway.app/graphql/internal?q=environmentPatchCommitStaged' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation environmentPatchCommitStaged($environmentId: String!, $message: String, $skipDeploys: Boolean) {\n environmentPatchCommitStaged(\n environmentId: $environmentId\n commitMessage: $message\n skipDeploys: $skipDeploys\n )\n}","variables":{"environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","skipDeploys":false}}'
- name: Cardinal Healthcheck
run: |
curl -X POST --max-time 10 --retry 20 --retry-delay 5 --retry-max-time 300 ${{ vars.PROD_CARDINAL_HEALTHCHECK }} -d "{}"
- name: Remove Nakama Database (Railway)
run: |
PGPASSWORD=${{ secrets.PROD_RAILWAY_POSTGRES_PASSWORD }} psql -h ${{ secrets.PROD_RAILWAY_POSTGRES_HOST }} -U ${{ secrets.PROD_RAILWAY_POSTGRES_USER }} -p ${{ secrets.PROD_RAILWAY_POSTGRES_PORT }} -d railway -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
- name: Restart Nakama Services (Railway)
run: |
## Get NAKAMA Latest Deployment ID
DEPLOYMENT_ID=$(curl --location 'https://backboard.railway.app/graphql/v2' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"query deployments($projectId: String!, $environmentId: String!, $serviceId: String!) {\n deployments(\n first: 1\n input: {\n projectId: $projectId\n environmentId: $environmentId\n serviceId: $serviceId\n }\n ) {\n edges {\n node {\n id\n staticUrl\n }\n }\n }\n}",
"variables":{"projectId":"${{ vars.RAILWAY_PROJECT_ID }}","environmentId":"${{ vars.PROD_RAILWAY_ENVIRONMENT_ID }}","serviceId":"${{ vars.RAILWAY_NAKAMA_SERVICE_ID }}"}}' | jq -r '.data.deployments.edges[].node.id')
## RESTART Deployment
curl --location 'https://backboard.railway.app/graphql/v2' \
--header 'Authorization: Bearer ${{ secrets.RAILWAY_API_TOKEN }}' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation deploymentRestart($id: String!) {\n deploymentRestart(id: $id)\n}","variables":{"id":"'${DEPLOYMENT_ID}'"}}'