-
Notifications
You must be signed in to change notification settings - Fork 15
274 lines (235 loc) · 8.34 KB
/
ci.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
---
# This workflow will build a golang project and runs CI tests
name: CI
on:
workflow_dispatch:
inputs:
preview-enabled:
description: 'check whether to enable preview by setting up tunnel and keep environment up. Default `true`'
required: false
default: true
type: choice
options:
- true
- false
preview-timeout:
description: 'preview environment timeout. This setting is how long the environment would be available for. Set it less than Github Action timeout of 360 minutes. This value is passed into `sleep` command, so follow the sleep command syntax. Default `360m`'
required: false
type: string
default: "360m"
push:
branches:
- "main"
- "staging"
paths-ignore:
- 'docs/**'
- 'infrastructure/**'
pull_request:
branches:
- "main"
- "staging"
paths-ignore:
- 'docs/**'
- 'infrastructure/**'
# Only run one at a time
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
# Download Bacalhau CLI for troubleshooting
ci-setup-bacalhau:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
# - macos-13
bacalhau_version:
- 1.2.0
runs-on: ${{ matrix.os }}
environment: ci
steps:
- name: Download bacalhau
run: |
# Download bacalhau plugin
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
curl -sSL https://github.com/bacalhau-project/bacalhau/releases/download/v${{ matrix.bacalhau_version }}/bacalhau_v${{ matrix.bacalhau_version }}_linux_amd64.tar.gz -o bacalhau.tgz
elif [[ "$OSTYPE" == "darwin"* ]]; then
curl -sSL https://github.com/bacalhau-project/bacalhau/releases/download/v${{ matrix.bacalhau_version }}/bacalhau_v${{ matrix.bacalhau_version }}_darwin_arm64.tar.gz -o bacalhau.tgz
fi
tar -zxvf bacalhau.tgz
- name: upload bacalhau plugin to be used later
uses: actions/upload-artifact@v3
with:
name: bacalhau-binary-${{ matrix.os }}-${{ matrix.bacalhau_version }}
path: ./bacalhau
ci:
needs:
# - ci-setup-compose
- ci-setup-bacalhau
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
# - macos-13
bacalhau_version:
- 1.2.0
network_mode:
- public
- private
runs-on: ${{ matrix.os }}
environment: ci
env:
BACALHAU_VERSION: ${{ matrix.bacalhau_version }}
# Setting it at workflow level to be used by all the steps
BACALHAU_API_HOST: "127.0.0.1"
LOG_LEVEL: trace
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.3
cache-dependency-path: go.sum
- name: Install dependencies
run: go mod download
- name: Build
run: go build
- name: Upload plex binary
uses: actions/upload-artifact@v3
with:
name: plex-binary-${{ matrix.network_mode }}-${{ matrix.os }}-${{ matrix.bacalhau_version }}
path: ./plex
- name: download bacalhau binary
uses: actions/download-artifact@v3
with:
name: bacalhau-binary-${{ matrix.os }}-${{ matrix.bacalhau_version }}
- name: Setup docker (missing on MacOS)
if: runner.os == 'macos'
run: |
brew install colima docker docker-compose
colima start
# For testcontainers to find the Colima socket
# https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
mkdir -p ~/.docker/cli-plugins
ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
docker version
docker compose version
- name: Setup docker compose plugin
if: runner.os != 'macos'
run: |
# Output version info
docker version
docker compose version
- name: Bring tunnel for previewing environment
if: inputs.preview-enabled == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
#
set -x
# Create empty file to avoid issues
touch ./docker/.env.tunnel
# Setup docker compose tunnel
docker compose -f docker-compose.tunnel.yml up -d --wait
# copy tunnel info to .env
cat docker/.env.tunnel >> .env
- name: docker compose build
run: |
# Build compose
docker compose build --parallel
- name: Bring up the public stack
if: matrix.network_mode == 'public'
env:
STRIPE_WEBHOOK_SECRET_KEY: ${{ secrets.STRIPE_WEBHOOK_SECRET_KEY }}
run: |
# Compose up
docker compose -f docker-compose.yml up -d --wait
- name: Bring up the private stack
if: matrix.network_mode == 'private'
env:
STRIPE_WEBHOOK_SECRET_KEY: ${{ secrets.STRIPE_WEBHOOK_SECRET_KEY }}
run: |
# Compose up
docker compose -f docker-compose.yml -f docker-compose.private.yml up -d --wait
- name: Run docker compose ps
run: |
# Inspect number of running containers
docker compose ps
- name: fix permissions
if: always()
run: |
set -x
# Execute permission
chmod +x ./bacalhau ./plex
- name: Go Test
run: go test ./... -v
- name: Run Gateway Integration Tests
uses: ./.github/actions/gateway-tests
- name: Test log streaming
# run always even when
if: always()
run: |
./bacalhau docker run -f ubuntu -- /bin/bash -c 'for i in {1..5}; do echo Hello World; sleep 1; done' | tee /tmp/output.log
cat /tmp/output.log
- name: Run docker compose logs
# run always even when
if: always()
run: |
docker compose logs
- name: Run docker logs to get additional logs
# run always even when
if: always()
run: |
docker ps -a
for container in $(docker ps -qa); do echo ${container};docker logs ${container};done
- name: upload outputs
# run always even when
if: always()
uses: actions/upload-artifact@v3
with:
name: ci-${{ matrix.network_mode }}-output-${{ matrix.os }}-${{ matrix.bacalhau_version }}
path: |
plex_run_output.log
job-*
jobs/
- name: Tunnel URLs
if: inputs.preview-enabled == 'true'
run: |
cat ./docker/.env.tunnel
- name: Post tunnel URLs to PR
if: inputs.preview-enabled == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
#
set -x
# Comment output
source ./docker/.env.tunnel
# Adding comment
echo '---' >> comment.md
echo >> comment.md
echo ':information_source: NOTE' >> comment.md
echo >> comment.md
echo 'The URLs will only be available for 6 hours' >> comment.md
echo '---' >> comment.md
echo '## Preview URLs' >> comment.md
echo 'Bacalhau Version: ${{ matrix.bacalhau_version }}' >> comment.md
echo 'OS: ${{ matrix.os }}' >> comment.md
echo 'Network Mode: ${{ matrix.network_mode }}' >> comment.md
echo "| Endpoint | URL |" >> comment.md
echo "|---|---|" >> comment.md
echo "| FRONTEND_URL | ${FRONTEND_URL} |" >> comment.md
echo "| BACKEND_URL | ${NEXT_PUBLIC_BACKEND_URL} |" >> comment.md
echo "| IPFS_GATEWAY_URL | ${NEXT_PUBLIC_IPFS_GATEWAY_ENDPOINT} |" >> comment.md
# Comment on PR with URLs
PR_NUMBER=$(gh pr view --json number | jq -r '.number')
if [[ ! -z "${PR_NUMBER}" ]]; then
gh pr comment "${PR_NUMBER}" --body-file comment.md
fi
- name: Sleep for preview-timeout
if: inputs.preview-enabled == 'true'
run: sleep ${{ inputs.preview-timeout }}