@@ -12,63 +12,47 @@ inputs:
1212 required : true
1313 # Version must match production and be published on docker.elastic.co.
1414 default : ' 8.12.0'
15+ mode :
16+ description : >-
17+ 'both' starts Elasticsearch and waits until it is ready.
18+ 'start' starts it in the background and returns right away.
19+ 'wait' waits for a background start from an earlier 'start' step, then for readiness.
20+ required : false
21+ default : ' both'
1522
1623runs :
1724 using : ' composite'
1825 steps :
19- # Pull from Elastic's registry to avoid Docker Hub rate limits.
20- # A pull is faster than restoring and loading a cached image tarball.
21- - name : Pull Docker image
26+ - name : Start Elasticsearch
27+ if : ${{ inputs.mode == 'both' }}
2228 shell : bash
2329 env :
24- ES_IMAGE : docker.elastic.co/elasticsearch/elasticsearch:${{ inputs.elasticsearch_version }}
25- run : |
26- for attempt in 1 2 3; do
27- docker pull "$ES_IMAGE" && exit 0
28- echo "Pull attempt $attempt failed"
29- sleep $((attempt * 10))
30- done
31- exit 1
30+ ES_VERSION : ${{ inputs.elasticsearch_version }}
31+ run : bash "$GITHUB_ACTION_PATH/start.sh"
3232
33- # Run a single-node container with settings copied from getong/elasticsearch-action.
34- - name : Run Docker container
33+ # Later steps such as npm ci and the build run while the image pulls and Elasticsearch boots.
34+ - name : Start Elasticsearch in the background
35+ if : ${{ inputs.mode == 'start' }}
3536 shell : bash
3637 env :
37- INPUT_ELASTICSEARCH_VERSION : ${{ inputs.elasticsearch_version }}
38- INPUT_HOST_PORT : 9200
39- INPUT_CONTAINER_PORT : 9200
40- INPUT_HOST_NODE_PORT : 9300
41- INPUT_NODE_PORT : 9300
42- INPUT_DISCOVERY_TYPE : ' single-node'
38+ ES_VERSION : ${{ inputs.elasticsearch_version }}
39+ ES_STATUS_FILE : ${{ runner.temp }}/elasticsearch-start.status
40+ ES_LOG_FILE : ${{ runner.temp }}/elasticsearch-start.log
4341 run : |
44- docker network create elastic
45-
46- docker run --network elastic \
47- -e 'node.name=es1' \
48- -e 'cluster.name=docker-elasticsearch' \
49- -e 'cluster.initial_master_nodes=es1' \
50- -e 'discovery.seed_hosts=es1' \
51- -e 'cluster.routing.allocation.disk.threshold_enabled=false' \
52- -e 'bootstrap.memory_lock=true' \
53- -e 'ES_JAVA_OPTS=-Xms1g -Xmx1g' \
54- -e 'xpack.security.enabled=false' \
55- -e 'xpack.license.self_generated.type=basic' \
56- --ulimit nofile=65536:65536 \
57- --ulimit memlock=-1:-1 \
58- --name='es1' \
59- -d \
60- -p $INPUT_HOST_PORT:$INPUT_CONTAINER_PORT \
61- -p $INPUT_HOST_NODE_PORT:$INPUT_NODE_PORT \
62- -e discovery_type=$INPUT_DISCOVERY_TYPE \
63- docker.elastic.co/elasticsearch/elasticsearch:$INPUT_ELASTICSEARCH_VERSION
42+ rm -f "$ES_STATUS_FILE"
43+ (
44+ status=0
45+ bash "$GITHUB_ACTION_PATH/start.sh" || status=$?
46+ echo "$status" > "$ES_STATUS_FILE.tmp"
47+ mv "$ES_STATUS_FILE.tmp" "$ES_STATUS_FILE"
48+ ) > "$ES_LOG_FILE" 2>&1 < /dev/null &
49+ echo "Starting Elasticsearch in the background. A mode: wait step prints the log."
6450
65- for i in {1..120}; do
66- if curl --silent --fail http://localhost:9200; then
67- echo "Elasticsearch is up and running"
68- exit 0
69- fi
70- echo "Waiting for Elasticsearch to be ready..."
71- sleep 1
72- done
73- echo "Elasticsearch did not become ready in time"
74- exit 1
51+ - name : Wait for Elasticsearch
52+ if : ${{ inputs.mode != 'start' }}
53+ shell : bash
54+ env :
55+ ES_BACKGROUND : ${{ inputs.mode == 'wait' }}
56+ ES_STATUS_FILE : ${{ runner.temp }}/elasticsearch-start.status
57+ ES_LOG_FILE : ${{ runner.temp }}/elasticsearch-start.log
58+ run : bash "$GITHUB_ACTION_PATH/wait.sh"
0 commit comments