-
Notifications
You must be signed in to change notification settings - Fork 20
207 lines (179 loc) · 8.68 KB
/
external-opensearch-test.yml
File metadata and controls
207 lines (179 loc) · 8.68 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
name: External OpenSearch Test
on:
pull_request:
branches:
- main
- dev
paths:
- "Dockerfile"
- "src/**"
- "docker-compose*.yml"
- ".last_release"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/external-opensearch-test.yml"
jobs:
test-external-opensearch:
runs-on: ubuntu-latest
env:
BASE_URL: "https://r2.koalasec.org/public"
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Read Photon version from .last_release
id: photon_version
run: |
PHOTON_VERSION=$(cat .last_release | tr -d '[:space:]')
if [[ -z "$PHOTON_VERSION" || ! "$PHOTON_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: .last_release is missing, empty, or contains an invalid version: '$PHOTON_VERSION'"
exit 1
fi
echo "PHOTON_VERSION=$PHOTON_VERSION" >> "$GITHUB_ENV"
echo "Photon Version: $PHOTON_VERSION"
- name: Build test image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
build-args: |
PHOTON_VERSION=${{ env.PHOTON_VERSION }}
push: false
load: true
tags: photon-test:ext-os-${{ github.event.pull_request.number }}
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create Docker network
run: docker network create photon-ext-os-test
- name: Download and extract Andorra index
run: |
INDEX_DB_VERSION="1.0"
FILE_NAME="photon-db-andorra-${INDEX_DB_VERSION}-latest.tar.bz2"
DOWNLOAD_URL="${BASE_URL}/europe/andorra/${FILE_NAME}"
echo "Downloading Andorra index from ${DOWNLOAD_URL}..."
mkdir -p /tmp/photon-data
wget -q "${DOWNLOAD_URL}" -O "/tmp/${FILE_NAME}"
tar -xjf "/tmp/${FILE_NAME}" -C /tmp/photon-data
echo "Index extracted to /tmp/photon-data"
ls -la /tmp/photon-data/
- name: Prepare OpenSearch data directory
run: |
# Remap photon's node_1/ to OpenSearch standalone's nodes/0/
mkdir -p /tmp/os-data/nodes/0
cp -r /tmp/photon-data/photon_data/node_1/. /tmp/os-data/nodes/0/
# OpenSearch container runs as uid 1000
chmod -R 777 /tmp/os-data
echo "OpenSearch data directory prepared:"
ls -laR /tmp/os-data/nodes/0/ | head -20
- name: Start OpenSearch
run: |
# OpenSearch 3.0.0 ignores gateway settings from -D JVM properties;
# they must be in opensearch.yml. cluster.name must match the
# OPENSEARCH_CLUSTER value photon will use to connect.
printf '%s\n' \
'cluster.name: photon' \
'network.host: 0.0.0.0' \
'gateway.auto_import_dangling_indices: true' \
> /tmp/opensearch.yml
docker run -d \
--name opensearch-test \
--network photon-ext-os-test \
-p 9200:9200 \
-v /tmp/os-data:/usr/share/opensearch/data \
-v /tmp/opensearch.yml:/usr/share/opensearch/config/opensearch.yml \
-e "discovery.type=single-node" \
-e "DISABLE_SECURITY_PLUGIN=true" \
-e "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" \
opensearchproject/opensearch:3.0.0
- name: Wait for OpenSearch cluster health
run: |
echo "Waiting for OpenSearch cluster to be healthy (timeout: 120s)..."
SECONDS=0
TIMEOUT=120
while [ $SECONDS -lt $TIMEOUT ]; do
if curl -sf "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=5s" > /dev/null 2>&1; then
echo "OpenSearch cluster is healthy after ${SECONDS}s"
curl -s "http://localhost:9200/_cluster/health" | python3 -m json.tool
break
fi
echo "Waiting for OpenSearch... (elapsed: ${SECONDS}s)"
sleep 5
SECONDS=$((SECONDS + 5))
done
if [ $SECONDS -ge $TIMEOUT ]; then
echo "OpenSearch failed to become healthy within ${TIMEOUT}s"
docker logs opensearch-test
exit 1
fi
- name: Wait for photon index
run: |
echo "Waiting for photon index to appear (timeout: 120s)..."
SECONDS=0
TIMEOUT=120
while [ $SECONDS -lt $TIMEOUT ]; do
if curl -sf "http://localhost:9200/photon" > /dev/null 2>&1; then
echo "Photon index found after ${SECONDS}s"
curl -s "http://localhost:9200/_cat/indices?v"
break
fi
echo "Waiting for photon index... (elapsed: ${SECONDS}s)"
sleep 5
SECONDS=$((SECONDS + 5))
done
if [ $SECONDS -ge $TIMEOUT ]; then
echo "Photon index did not appear within ${TIMEOUT}s"
echo "OpenSearch indices:"
curl -s "http://localhost:9200/_cat/indices?v" || true
echo "Dangling indices:"
curl -s "http://localhost:9200/_dangling" || true
docker logs opensearch-test
exit 1
fi
- name: Start photon container
run: |
docker run -d \
--name photon-ext-os-test \
--network photon-ext-os-test \
-e OPENSEARCH_TRANSPORT_ADDRESSES=opensearch-test:9200 \
-e OPENSEARCH_CLUSTER=photon \
photon-test:ext-os-${{ github.event.pull_request.number }}
- name: Wait for photon to be healthy
run: |
echo "Waiting for photon container to become healthy (timeout: 6 minutes)..."
CONTAINER_NAME=photon-ext-os-test
docker logs -f $CONTAINER_NAME &
LOGS_PID=$!
SECONDS=0
TIMEOUT=360
while [ $SECONDS -lt $TIMEOUT ]; do
HEALTH_STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_NAME 2>/dev/null || echo "unknown")
if [ "$HEALTH_STATUS" = "healthy" ]; then
echo "Photon container is healthy after $SECONDS seconds"
kill $LOGS_PID 2>/dev/null || true
exit 0
fi
echo "Health status: $HEALTH_STATUS (elapsed: ${SECONDS}s)"
sleep 10
SECONDS=$((SECONDS + 10))
done
kill $LOGS_PID 2>/dev/null || true
echo "Photon container failed to become healthy within $TIMEOUT seconds"
docker logs $CONTAINER_NAME
exit 1
- name: Cleanup
if: always()
run: |
docker stop photon-ext-os-test opensearch-test 2>/dev/null || true
docker rm photon-ext-os-test opensearch-test 2>/dev/null || true
docker network rm photon-ext-os-test 2>/dev/null || true
docker rmi photon-test:ext-os-${{ github.event.pull_request.number }} 2>/dev/null || true
- name: Output summary
if: always()
run: |
echo "## External OpenSearch Test Summary" >> $GITHUB_STEP_SUMMARY
echo "- **PR Number:** ${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
echo "- **Photon Version:** ${{ env.PHOTON_VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- **OpenSearch Version:** 3.0.0" >> $GITHUB_STEP_SUMMARY
echo "- **Status:** ${{ job.status }}" >> $GITHUB_STEP_SUMMARY