-
Notifications
You must be signed in to change notification settings - Fork 1
259 lines (232 loc) · 8.46 KB
/
Copy pathbuild.yaml
File metadata and controls
259 lines (232 loc) · 8.46 KB
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
name: Build
on:
push:
branches:
# do not run on main, the create-release workflow will to this by adding action:create-release to the commit message
- '140-*'
- 'PH-120/*'
- 'PH-99/*'
- 'PH-131/*'
- 'PH-133/*'
- 'PH-101/*'
- 'PH-196/*'
- 'PH-198/*'
- 'PH-201/*'
- 'PH-205/*'
pull_request:
branches:
- main
workflow_dispatch:
inputs:
run_integration_tests:
description: 'Run integration tests?'
default: 'false'
required: false
permissions:
contents: read
packages: write
jobs:
go-test:
uses: ./.github/workflows/go-test.yaml
secrets: inherit
ko-build:
# Run this job on push events and pull requests
if: github.event_name == 'push'
needs: [go-test]
uses: metraction/github-actions/.github/workflows/ko-build.yaml@main
secrets: inherit
push-helm-chart:
uses: metraction/github-actions/.github/workflows/helm-push.yaml@main
needs: [ko-build]
with:
chart_dir: helm/pharos
chart_name: pharos
destination: .
registry: oci://ghcr.io/metraction/charts
secrets: inherit
get-version:
if: github.event.inputs.run_integration_tests == 'true' || contains(github.event.head_commit.message, 'testit') || contains(github.event.head_commit.message, 'testbe') || contains(github.ref, 'integration-test')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version from semver.sh
id: version
run: |
VERSION=$(curl -sSL "https://raw.githubusercontent.com/metraction/github-actions/refs/heads/main/scripts/semver.sh" | bash)
VERSION=$(echo "$VERSION" | sed 's/+/_/g')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Using version: $VERSION"
integration-test:
if: github.event.inputs.run_integration_tests == 'true' || contains(github.event.head_commit.message, 'testit') || contains(github.ref, 'integration-test')
needs: [get-version, ko-build]
runs-on: ubuntu-latest
permissions:
contents: read # Required for checkout
packages: read # Required to pull images from GHCR
services:
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres:15-alpine
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_DB: pharos
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
scanner:
# The image is tagged with the version from semver.sh
image: ghcr.io/metraction/pharos/pharos:${{ needs.get-version.outputs.version }}
env:
PHAROS_REDIS_DSN: redis:6379
PHAROS_SCANNER_CACHEENDPOINT: redis://redis:6379
publisher:
# The image is tagged with the version from semver.sh
image: ghcr.io/metraction/pharos/pharos:${{ needs.get-version.outputs.version }}
ports:
- 8080:8080
env:
PHAROS_REDIS_DSN: redis:6379
PHAROS_SCANNER_CACHEENDPOINT: redis://redis:6379
PHAROS_DATABASE_DSN: postgres://postgres:postgres@postgres:5432/pharos?sslmode=disable
PHAROS_COMMAND: http
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Wait for services to be healthy
run: |
echo "Waiting for services to initialize..."
sleep 15 # Adjust as needed, or implement a more robust health check for the scanner
- name: Run http integration tests
run: |
# # Wait for HTTP service to be ready
echo "Waiting for HTTP service to be available..."
timeout 15 bash -c 'until curl -s http://localhost:8080/api/docs; do sleep 1; done'
# Send request and capture response
echo "Sending test request to API..."
response=$(curl -s -w "\n%{http_code}" -X POST http://localhost:8080/api/pharosscantask/syncscan \
-H "Content-Type: application/json" \
-d '{
"jobId": "2",
"status": "",
"engine": "",
"error": "",
"authdsn": "registry:///?tlscheck=false",
"imagespec": "rancher/nginx-ingress-controller:nginx-1.11.3-rancher1",
"platform": "linux/amd64",
"context": {
"namespace": "ingress-nginx"
},
"contextRootKey": "namespace=ingress-nginx,",
"rxdigest": "",
"rxplatform": "",
"cachettl": 0,
"scanttl": 60000000000,
"created": "2025-07-02T10:20:35.784021+02:00",
"updated": "2025-07-02T10:20:35.784021+02:00"
}')
# Extract status code
status_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | sed '$d')
# Check if request was successful
echo "Response body: $response_body"
echo "Status code: $status_code"
if [[ "$status_code" -ge 200 && "$status_code" -lt 300 ]]; then
echo "HTTP request successful"
else
echo "HTTP request failed with status $status_code"
exit 1
fi
- name: Run controller integration tests
env:
DATABASE_DSN: "postgres://postgres:postgres@localhost:5432?sslmode=disable"
DATABASE_DRIVER: "postgres"
run: |
go test ./internal/controllers -timeout=5m -v
benchmark-test:
if: github.event.inputs.run_benchmark_tests == 'true' || contains(github.event.head_commit.message, 'testbe')
needs: [get-version, ko-build]
runs-on: ubuntu-latest
permissions:
contents: read # Required for checkout
packages: read # Required to pull images from GHCR
services:
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres:15-alpine
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_HOST_AUTH_METHOD: trust
scanner:
# The image is tagged with the version from semver.sh
image: ghcr.io/metraction/pharos/pharos:${{ needs.get-version.outputs.version }}
env:
PHAROS_REDIS_DSN: redis:6379
PHAROS_SCANNER_CACHEENDPOINT: redis://redis:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23' # Or your project's Go version
- name: Wait for services to be healthy
run: |
echo "Waiting for services to initialize..."
sleep 15 # Adjust as needed, or implement a more robust health check for the scanner
- name: Run benchmark tests
env:
DOCKER_REGISTRIES_AUTH: "registry://spastai\\@gmail.com:${{ secrets.GITHUB_TOKEN }}@ghcr.io/metraction"
run: |
# These tests should publish to Redis, and the scanner service should consume.
# The benchmark test (routing/publish_test.go) is configured to use localhost:6379 for Redis.
go test ./internal/routing -bench=. -benchmem -timeout=5m
- name: Show scanner service logs
run: |
echo "Scanner service logs:"
docker logs ${{ job.services.scanner.id }}
- name: Check scanner service logs on failure
if: failure()
run: |
echo "Tests failed. Scanner logs are available in the 'scanner' service logs in the GitHub Actions UI."
# The logs for services are automatically collected by the runner and displayed in the UI.
# This step is just a pointer for easier debugging.