-
Notifications
You must be signed in to change notification settings - Fork 16
178 lines (151 loc) · 7.25 KB
/
superchat-tunnel-client-deploy.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
name: Run superchat-tunnel-client on SuperProtocol
on: workflow_dispatch
env:
ORDER_ID: ''
SOLUTION_DATA_FILE: ''
LAST_ORDER_FILENAME: last-orders.txt
BASE_IMAGE_OFFER: ''
TUNNEL_CLIENT_OFFER: ''
STORAGE_OFFER: ''
SOLUTION_SERVER_TOKEN: ''
SOLUTION_SSL_KEY_FILE: ''
SOLUTION_SSL_CERT_FILE: ''
SOLUTION_BUILD_SCRIPT: ''
SOLUTION_NAME: superchat-tunnel-client
jobs:
start-tunnel-client:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
repository-projects: read
steps:
- name: Check secrets and variables
run: |
if [ -z "${{ secrets.CHAT_ENV }}" ]; then
echo "Error: CHAT_ENV secret is missing. Workflow will fail."
exit 1
elif [ -z "${{ secrets.GH_TOKEN }}" ]; then
echo "Error: GH_TOKEN secret is missing. Workflow will fail."
exit 1
elif [ -z "${{ secrets.SUPERCHAT_SOLUTION_SERVER_TOKEN }}" ]; then
echo "Error: SUPERCHAT_SOLUTION_SERVER_TOKEN secret is missing. Workflow will fail."
exit 1
elif [ -z "${{ secrets.SPCTL_CONFIG_BASE64 }}" ]; then
echo "Error: SPCTL_CONFIG_BASE64 secret is missing. Workflow will fail."
exit 1
elif [ -z "${{ secrets.SUPERCHAT_SOLUTION_SSL_CERTIFICATE_BASE64 }}" ]; then
echo "Error: SUPERCHAT_SOLUTION_SSL_CERTIFICATE_BASE64 secret is missing. Workflow will fail."
exit 1
elif [ -z "${{ secrets.SUPERCHAT_SOLUTION_SSL_KEY_BASE64 }}" ]; then
echo "Error: SUPERCHAT_SOLUTION_SSL_KEY_BASE64 secret is missing. Workflow will fail."
exit 1
elif [ -z "${{ vars.TUNNEL_SERVER_MRSIGNER }}" ]; then
echo "Error: TUNNEL_SERVER_MRSIGNER variable is missing. Workflow will fail."
exit 1
elif [ -z "${{ vars.TUNNEL_SERVER_MRENCLAVE }}" ]; then
echo "Error: TUNNEL_SERVER_MRENCLAVE variable is missing. Workflow will fail."
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v3
- name: Get previous build for solution
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_ACTION_REPOSITORY: ${{ github.repository }}
GH_WORKFLOW_NAME: ${{ github.workflow }}
run: |
LAST_RUN_ID=$(gh run --repo ${{ env.GH_ACTION_REPOSITORY }} list --workflow "${{ env.GH_WORKFLOW_NAME }}" -s success --json databaseId --jq .[0].databaseId)
gh run --repo ${{ env.GH_ACTION_REPOSITORY }} download $LAST_RUN_ID -n last-orders
echo "Artifact downloaded"
ls -la
- name: Download SPCTL
run: |
latest_tag=$(curl -sL -o /dev/null -w %{url_effective} https://github.com/Super-Protocol/ctl/releases/latest | rev | cut -d'/' -f1 | rev)
echo "Latest SPCTL tag" $latest_tag
curl -L https://github.com/Super-Protocol/ctl/releases/download/$latest_tag/spctl-linux-x64 -o ./spctl
chmod +x ./spctl
SPCTL_CONFIG=$(echo "${{ secrets.SPCTL_CONFIG_BASE64 }}" | base64 --decode)
BASE_IMAGE_OFFER=6,2
STORAGE_OFFER=23,27
TUNNEL_CLIENT_OFFER=13,15
echo "$SPCTL_CONFIG" > ./config.json
echo "Spctl" version
./spctl --version
echo "BASE_IMAGE_OFFER=$BASE_IMAGE_OFFER" >> $GITHUB_ENV
echo "TUNNEL_CLIENT_OFFER=$TUNNEL_CLIENT_OFFER" >> $GITHUB_ENV
echo "STORAGE_OFFER=$STORAGE_OFFER" >> $GITHUB_ENV
- name: Prepare tunnel client data
if: env.SOLUTION_NAME == 'superchat-tunnel-client'
run: |
mkdir solution-build
cp -R Tunnel\ Client/chat/* solution-build/
echo "SOLUTION_BUILD_SCRIPT=solution-build/scripts/prepare-solution.sh" >> $GITHUB_ENV
echo "SOLUTION_SERVER_TOKEN=${{ secrets.SUPERCHAT_SOLUTION_SERVER_TOKEN }}" >> $GITHUB_ENV
echo "${{ secrets.SUPERCHAT_SOLUTION_SSL_KEY_BASE64 }}" | base64 --decode > private.pem
echo "SOLUTION_SSL_KEY_FILE=private.pem" >> $GITHUB_ENV
echo "${{ secrets.SUPERCHAT_SOLUTION_SSL_CERTIFICATE_BASE64 }}" | base64 --decode > certificate.crt
echo "SOLUTION_SSL_CERT_FILE=certificate.crt" >> $GITHUB_ENV
echo "${{ secrets.CHAT_ENV }}" | base64 --decode > solution-build/.env
- name: Build solution
run: |
mkdir -p solution-data/content
chmod +x ${{ env.SOLUTION_BUILD_SCRIPT }}
${{ env.SOLUTION_BUILD_SCRIPT }} $(realpath solution-data/content) ${{ env.SOLUTION_NAME }}
cp ${{ env.SOLUTION_SSL_KEY_FILE }} solution-data/
cp ${{ env.SOLUTION_SSL_CERT_FILE }} solution-data/
CONFIG=$(cat << EOF
{
"tunnels": [
{
"sgxMrSigner": "${{ vars.TUNNEL_SERVER_MRSIGNER }}",
"sgxMrEnclave": "${{ vars.TUNNEL_SERVER_MRENCLAVE }}"
}
],
"authToken": "${{ env.SOLUTION_SERVER_TOKEN }}",
"site": {
"domain": "${{ vars.SUPERCHAT_DOMAIN }}",
"cert": "./${{ env.SOLUTION_SSL_CERT_FILE }}",
"key": "./${{ env.SOLUTION_SSL_KEY_FILE }}"
}
}
EOF
)
echo "$CONFIG" > solution-data/config.json
SOLUTION_DATA_FILE=${{ env.SOLUTION_NAME }}-client-data-b${{ github.run_id }}.tar.gz
tar -czf $SOLUTION_DATA_FILE.tar.gz -C solution-data/ .
./spctl files upload $SOLUTION_DATA_FILE.tar.gz --output $SOLUTION_DATA_FILE.json --filename $SOLUTION_DATA_FILE.tar.gz
echo "SOLUTION_DATA_FILE=$SOLUTION_DATA_FILE.json" >> $GITHUB_ENV
- name: Run tunnel client for ${{ env.SOLUTION_NAME }}
run: |
if [ -f ${{ env.LAST_ORDER_FILENAME }} ]; then
echo "${{ env.LAST_ORDER_FILENAME }} file found"
PREVOIUS_ORDER=$(grep "^${{ env.SOLUTION_NAME }}=" ${{ env.LAST_ORDER_FILENAME }} | cut -d'=' -f2)
if [[ -n "$PREVOIUS_ORDER" ]]; then
echo "Cancelling order $PREVOIUS_ORDER"
./spctl orders cancel $PREVOIUS_ORDER || true
fi
fi
./spctl workflows create --tee 1 --solution ${{ env.BASE_IMAGE_OFFER }} --solution ${{ env.TUNNEL_CLIENT_OFFER }} --data ${{ env.SOLUTION_DATA_FILE }} --storage ${{ env.STORAGE_OFFER }} --orders-limit 10000 --min-rent-minutes 60 > workflow_result.txt
cat workflow_result.txt
ORDER_ID=$(cat workflow_result.txt | grep -oP '\["\K\d+(?="\])')
echo "ORDER_ID=$ORDER_ID" >> $GITHUB_ENV
if grep ${{ env.SOLUTION_NAME }}= ${{ env.LAST_ORDER_FILENAME }}; then
sed -i "s/^${{ env.SOLUTION_NAME }}=.*$/${{ env.SOLUTION_NAME }}=$(echo $ORDER_ID)/" ${{ env.LAST_ORDER_FILENAME }}
else
echo "${{ env.SOLUTION_NAME }}=$ORDER_ID" >> ${{ env.LAST_ORDER_FILENAME }}
fi
- name: Archive created order
uses: actions/upload-artifact@v3
with:
name: last-orders
path: ${{ env.LAST_ORDER_FILENAME }}
- name: Result
run: |
if [ -n "${{ env.ORDER_ID }}" ]; then
echo "Order succesfully created. Order id: ${{ env.ORDER_ID }}"
else
echo "Failed to create order"
exit 1
fi