forked from donalffons/opencascade.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runAction.sh
executable file
·64 lines (52 loc) · 2.95 KB
/
runAction.sh
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
#!/bin/bash
export RUNNER_ALLOW_RUNASROOT="1"
# Install jq
snap install jq
# Install Docker
apt update -y
apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update -y
apt install -y docker-ce docker-ce-cli containerd.io
# Install Git LFS
apt install -y git-lfs
# Install GCP Disk Space Monitoring
curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh && sudo bash add-monitoring-agent-repo.sh && sudo apt-get update -y && sudo apt-get install -y stackdriver-agent && sudo service stackdriver-agent start
# Install Node and NPM
apt install -y nodejs npm
# # Add swap space
# SWAPSPACE=$(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/SWAPSPACE -H "Metadata-Flavor: Google")
# fallocate -l $SWAPSPACE /swapfile
# chmod 600 /swapfile
# mkswap /swapfile
# swapon /swapfile
# swapon --show
# Prepare Actinon Execution
echo $(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/SA_KEY -H "Metadata-Flavor: Google") > /saKey.json
GH_API_TOKEN=$(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/GH_API_TOKEN -H "Metadata-Flavor: Google")
UUID=$(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/UUID -H "Metadata-Flavor: Google")
LABELS=$(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/LABELS -H "Metadata-Flavor: Google")
PROJECT_NAME=$(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/PROJECT_NAME -H "Metadata-Flavor: Google")
gcloud auth activate-service-account --key-file /saKey.json
GH_ACTION_TOKEN_RESPONSE=$(curl -u opencascade.js-build:$GH_API_TOKEN -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$PROJECT_NAME/actions/runners/registration-token)
GH_ACTION_TOKEN=$(echo $GH_ACTION_TOKEN_RESPONSE | jq -r ".token")
mkdir actions-runner && cd actions-runner
RUNNERURL=$(curl -s https://api.github.com/repos/actions/runner/releases/latest \
| grep -E "browser_download_url\": \".*download.*linux-x64-[^-]+.tar.gz" \
| cut -d : -f 2,3 \
| tr -d \")
curl -o actions-runner-linux.tar.gz -L $RUNNERURL
tar xzf ./actions-runner-linux.tar.gz
./config.sh --unattended --url https://github.com/$PROJECT_NAME --token $GH_ACTION_TOKEN --replace --name opencascade-js-build-$UUID --labels $LABELS
./run.sh --once || true
sleep 60
curl -u opencascade.js-build:$GH_API_TOKEN -X DELETE -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$PROJECT_NAME/actions/runners/opencascade-js-build-$UUID
gcloud compute instances delete opencascade-js-build-$UUID --zone us-central1-a -q