Start Elasticsearch in the background in test.yml (#63750) · mogya/github_docs@2066232 · GitHub
Skip to content

Commit 2066232

Browse files
heiskrCopilotCopilot
authored
Start Elasticsearch in the background in test.yml (#63750)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: heiskr <1221423+heiskr@users.noreply.github.com> Copilot-Session: 796e2742-a386-4cab-8cc3-be8fe189e974
1 parent c129a69 commit 2066232

5 files changed

Lines changed: 125 additions & 50 deletions

File tree

‎.github/actions/setup-elasticsearch/action.yml‎

Lines changed: 33 additions & 49 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Pull the Elasticsearch image and start the es1 container. wait.sh checks readiness.
4+
5+
set -euo pipefail
6+
7+
image="docker.elastic.co/elasticsearch/elasticsearch:$ES_VERSION"
8+
9+
# Pull from Elastic's registry to avoid Docker Hub rate limits.
10+
# A pull is faster than restoring and loading a cached image tarball.
11+
pulled=false
12+
for attempt in 1 2 3; do
13+
if docker pull "$image"; then
14+
pulled=true
15+
break
16+
fi
17+
echo "Pull attempt $attempt failed"
18+
sleep $((attempt * 10))
19+
done
20+
if [ "$pulled" != true ]; then
21+
echo "Could not pull $image"
22+
exit 1
23+
fi
24+
25+
# Run a single-node container with settings copied from getong/elasticsearch-action.
26+
docker network create elastic
27+
28+
docker run --network elastic \
29+
-e 'node.name=es1' \
30+
-e 'cluster.name=docker-elasticsearch' \
31+
-e 'cluster.initial_master_nodes=es1' \
32+
-e 'discovery.seed_hosts=es1' \
33+
-e 'cluster.routing.allocation.disk.threshold_enabled=false' \
34+
-e 'bootstrap.memory_lock=true' \
35+
-e 'ES_JAVA_OPTS=-Xms1g -Xmx1g' \
36+
-e 'xpack.security.enabled=false' \
37+
-e 'xpack.license.self_generated.type=basic' \
38+
--ulimit nofile=65536:65536 \
39+
--ulimit memlock=-1:-1 \
40+
--name='es1' \
41+
-d \
42+
-p 9200:9200 \
43+
-p 9300:9300 \
44+
-e discovery_type=single-node \
45+
"$image"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Wait until Elasticsearch answers on localhost:9200.
4+
# With ES_BACKGROUND=true, first wait for the background start.sh to finish.
5+
6+
set -euo pipefail
7+
8+
if [ "${ES_BACKGROUND:-false}" = true ]; then
9+
for _ in {1..300}; do
10+
[ -f "$ES_STATUS_FILE" ] && break
11+
sleep 1
12+
done
13+
echo "::group::Background start log"
14+
cat "$ES_LOG_FILE" || true
15+
echo "::endgroup::"
16+
if [ ! -f "$ES_STATUS_FILE" ]; then
17+
echo "::error::Elasticsearch start did not finish in time. Did a mode: start step run first?"
18+
exit 1
19+
fi
20+
status=$(cat "$ES_STATUS_FILE")
21+
if [ "$status" != 0 ]; then
22+
echo "::error::Elasticsearch start failed with exit code $status"
23+
exit 1
24+
fi
25+
fi
26+
27+
for _ in {1..120}; do
28+
if curl --silent --fail http://localhost:9200; then
29+
echo
30+
echo "Elasticsearch is up and running"
31+
exit 0
32+
fi
33+
echo "Waiting for Elasticsearch to be ready..."
34+
sleep 1
35+
done
36+
echo "::error::Elasticsearch did not become ready in time"
37+
docker logs --tail 100 es1 || true
38+
exit 1

‎.github/workflows/index-general-search-pr.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
# Debugging changes to this workflow need the same PR index test.
1313
- .github/workflows/index-general-search-pr.yml
1414
# Setup changes can break the local Elasticsearch path this workflow tests.
15-
- .github/actions/setup-elasticsearch/action.yml
15+
- '.github/actions/setup-elasticsearch/**'
1616

1717
permissions:
1818
contents: read

‎.github/workflows/test.yml‎

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)