-
Notifications
You must be signed in to change notification settings - Fork 2
196 lines (165 loc) · 6.7 KB
/
node.js.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Node.js CI
on:
push:
branches:
- dev
pull_request:
branches:
- dev
jobs:
build:
runs-on: ${{ matrix.os }}
env:
NETWORK: optimism_goerli
MNEMONIC: ${{ secrets.OPTIMISM_GOERLI_MNEMONIC }}
RPC_URL: ${{ secrets.OPTIMISM_GOERLI_RPC_URL }}
WSS_URL: ${{ secrets.OPTIMISM_GOERLI_WSS_URL }}
VALIDATORS: '0x7CE0Df86148326Bb6C417D7Bbf54fcEBcaD90821'
GAS_PRICE: 10
GAS_LIMIT: 2800000
DAPP_NAME: chessAppNew
BLOCK_CONFIRMATIONS: 1
BLOCK_CONFIRMATIONS_TX: 2
CHAIN_ID: 420
strategy:
fail-fast: false
matrix:
include:
- os: self-hosted
node-version: 14
steps:
- name: Build environment information
run: 'echo "Matrix OS: ${{ matrix.os }} on $HOSTNAME with $(getconf _NPROCESSORS_ONLN) cores"'
- name: Checkout main repo
uses: actions/checkout@v3
with:
fetch-depth: 0
# Check for changes in /front, /deployments, and other files
- name: Check for changes in /front, /deployments, and other files
id: check-changes
run: |
FRONT_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^front/') || true
DEPLOYMENTS_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^deployments/') || true
OTHER_CHANGES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -v '^front/' | grep -v '^deployments/' | grep -v '^\.workflow/' | grep -v '^nginx.conf' | grep -v '^\.gitignore') || true
echo "front-changed=$(if [ -z "$FRONT_CHANGED" ]; then echo false; else echo true; fi)" >> $GITHUB_ENV
echo "deployments-changed=$(if [ -z "$DEPLOYMENTS_CHANGED" ]; then echo false; else echo true; fi)" >> $GITHUB_ENV
echo "app-changed=$(if [ -z "$OTHER_CHANGES" ]; then echo false; else echo true; fi)" >> $GITHUB_ENV
# Prepare node
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# # Install Docker
# - name: Install Docker
# run: |
# curl -fsSL https://get.docker.com -o get-docker.sh
# sudo sh get-docker.sh
# sudo usermod -aG docker $USER
# newgrp docker
# Restore node modules
- name: Restore node modules
id: restore-node
uses: actions/cache@v3
with:
path: |
front/node_modules
key: node-install-${{ matrix.node-version }}-${{ hashFiles('front/package.json', 'front/package-lock.json') }}
# Restore dapp artifacts
- name: Restore dapp artifacts
id: restore-artifacts
uses: actions/cache@v3
with:
path: |
deployments/localhost
export
key: restore-artifacts-${{ hashFiles('docker-compose-deploy.yml', 'docker-compose.override.yml') }}
# Install dependencies
- name: Install Yarn
run: npm install -g yarn
# # Prepare Nginx
# - name: Reset Nginx configurations and install Nginx
# run: |
# sudo rm -rf /etc/nginx/sites-available/default
# sudo rm -rf /etc/nginx/sites-enabled/default
# sudo apt-get update
# sudo apt-get install --reinstall -y nginx
# # Create a minimal nginx.conf
# echo 'events {
# worker_connections 1024;
# }
# http {
# include /etc/nginx/mime.types;
# default_type application/octet-stream;
# sendfile on;
# access_log /var/log/nginx/access.log;
# error_log /var/log/nginx/error.log debug;
# keepalive_timeout 65;
# include /etc/nginx/sites-enabled/*;
# }' | sudo tee /etc/nginx/nginx.conf > /dev/null
# - name: yarn install
# if: steps.restore-node.outputs.cache-hit != 'true'
# working-directory: front
# run: yarn install
# # Build machine
# - name: Build dapp
# if: steps.check-changes.outputs.app-changed
# run: docker buildx bake -f docker-bake.hcl -f docker-bake.override.hcl --load
# # Build machine
# - name: Build machine
# if: steps.check-changes.outputs.app-changed
# run: docker buildx bake -f docker-bake.hcl -f docker-bake.override.hcl machine --load
# #Deploy contract
# - name: Deploy contract
# if: steps.check-changes.outputs.app-changed
# run: DAPP_NAME=chessAppNew docker compose -f ./deploy-testnet.yml up
# - name: Close the deployment container
# if: steps.check-changes.outputs.app-changed
# run: DAPP_NAME=chessAppNew docker compose -f ./deploy-testnet.yml down -v || true
# Deploy node
- name: Clear node
run: |
docker compose down -v
DAPP_NAME=chessAppNew docker compose -f ./docker-compose-testnet.yml -f ./docker-compose.override.yml -f ./docker-compose-host-testnet.yml down -v || true
- name: Deploy node
run: |
DAPP_NAME=chessAppNew nohup docker compose -f ./docker-compose-testnet.yml -f ./docker-compose.override.yml -f ./docker-compose-host-testnet.yml up > deployment.log 2>&1 &
echo "PID=$!" >> $GITHUB_ENV
sleep 120
#ls contents of /deployments
- name:
working-directory: deployments
run: ls -la
# Build front end
- name: yarn run build
working-directory: front
run: |
npm install -g typescript
yarn
yarn install
yarn run build
# Check if the /front/dist folder exists and remove it if it does
- name: Check and remove /front/dist folder if it exists
run: |
if [ -d "/front/dist" ]; then
sudo rm -rf /front/dist
fi
# Serve front end
- name: Copy nginx configuration and frontend files
run: |
sudo cp nginx.conf /etc/nginx/sites-available/default
sudo ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
sudo mkdir -p /front
sudo cp -R $GITHUB_WORKSPACE/front/dist /front/
# Set Nginx file permissions
- name: Set Nginx file permissions
run: |
sudo chown -R www-data:www-data /front/dist
sudo find /front/dist -type d -exec chmod 755 {} \;
sudo find /front/dist -type f -exec chmod 644 {} \;
# Restart Nginx
- name: Restart Nginx
run: sudo systemctl restart nginx || echo "Nginx restart failed"
# - name: Display deployment logs
# run: |
# echo "=== Deployment Log ==="
# cat deployment.log