@@ -10,82 +10,49 @@ inputs:
1010 elasticsearch_version :
1111 description : Version of Elasticsearch to install
1212 required : true
13- # Version must match production and be published on Docker Hub .
13+ # 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- # Cache the Elasticsearch image to prevent Docker Hub rate limits.
20- - name : Cache Docker layers
21- id : cache-docker-layers
22- uses : actions/cache@v4
23- with :
24- path : /tmp/docker-cache
25- key : ${{ runner.os }}-elasticsearch-${{ inputs.elasticsearch_version }}
26- restore-keys : |
27- ${{ runner.os }}-elasticsearch-
28-
29- - name : Load cached Docker image
30- shell : bash
31- if : steps.cache-docker-layers.outputs.cache-hit == 'true'
32- run : docker load -i /tmp/docker-cache/elasticsearch.tar || echo "No cache found for elasticsearch, pulling image"
33-
34- - name : Pull Docker image
26+ - name : Start Elasticsearch
27+ if : ${{ inputs.mode == 'both' }}
3528 shell : bash
36- if : steps.cache-docker-layers.outputs.cache-hit != 'true'
3729 env :
3830 ES_VERSION : ${{ inputs.elasticsearch_version }}
39- run : docker pull elasticsearch:${ES_VERSION}
31+ run : bash "$GITHUB_ACTION_PATH/start.sh"
4032
41- - name : Save Docker image to cache
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' }}
4236 shell : bash
43- if : steps.cache-docker-layers.outputs.cache-hit != 'true'
4437 env :
4538 ES_VERSION : ${{ inputs.elasticsearch_version }}
39+ ES_STATUS_FILE : ${{ runner.temp }}/elasticsearch-start.status
40+ ES_LOG_FILE : ${{ runner.temp }}/elasticsearch-start.log
4641 run : |
47- mkdir -p /tmp/docker-cache
48- docker save -o /tmp/docker-cache/elasticsearch.tar elasticsearch:${ES_VERSION}
49-
50- # Run a single-node container with settings copied from getong/elasticsearch-action.
51- - name : Run Docker container
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."
50+
51+ - name : Wait for Elasticsearch
52+ if : ${{ inputs.mode != 'start' }}
5253 shell : bash
5354 env :
54- INPUT_ELASTICSEARCH_VERSION : ${{ inputs.elasticsearch_version }}
55- INPUT_HOST_PORT : 9200
56- INPUT_CONTAINER_PORT : 9200
57- INPUT_HOST_NODE_PORT : 9300
58- INPUT_NODE_PORT : 9300
59- INPUT_DISCOVERY_TYPE : ' single-node'
60- run : |
61- docker network create elastic
62-
63- docker run --network elastic \
64- -e 'node.name=es1' \
65- -e 'cluster.name=docker-elasticsearch' \
66- -e 'cluster.initial_master_nodes=es1' \
67- -e 'discovery.seed_hosts=es1' \
68- -e 'cluster.routing.allocation.disk.threshold_enabled=false' \
69- -e 'bootstrap.memory_lock=true' \
70- -e 'ES_JAVA_OPTS=-Xms1g -Xmx1g' \
71- -e 'xpack.security.enabled=false' \
72- -e 'xpack.license.self_generated.type=basic' \
73- --ulimit nofile=65536:65536 \
74- --ulimit memlock=-1:-1 \
75- --name='es1' \
76- -d \
77- -p $INPUT_HOST_PORT:$INPUT_CONTAINER_PORT \
78- -p $INPUT_HOST_NODE_PORT:$INPUT_NODE_PORT \
79- -e discovery_type=$INPUT_DISCOVERY_TYPE \
80- elasticsearch:$INPUT_ELASTICSEARCH_VERSION
81-
82- for i in {1..120}; do
83- if curl --silent --fail http://localhost:9200; then
84- echo "Elasticsearch is up and running"
85- exit 0
86- fi
87- echo "Waiting for Elasticsearch to be ready..."
88- sleep 1
89- done
90- echo "Elasticsearch did not become ready in time"
91- exit 1
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