Skip to content

Commit

Permalink
Adds container name parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Oct 21, 2024
1 parent 57e7504 commit e9a59ec
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,29 @@ jobs:
- name: Elasticsearch is reachable
run: |
curl --verbose --show-error http://localhost:9200
run-with-custom-container-name:
name: Start Elasticsearch with custom container name
runs-on: ubuntu-latest
strategy:
matrix:
elasticsearch: ["9.0.0-SNAPSHOT"]
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Start Elasticsearch
uses: ./elasticsearch
with:
security-enabled: false
stack-version: ${{ matrix.elasticsearch }}
container-name: 'elasticsearch'

- name: Elasticsearch is reachable
run: |
curl --verbose --show-error http://localhost:9200
3 changes: 2 additions & 1 deletion elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ___
| `elasticsearch_password` | No | changeme | The password for the user elastic in your cluster |
| `wait` | No | 10 | Number of seconds to wait after launch. |
| `plugins` | No | | Any plugins you want to include |
| `network` | No | elastic | Custom name for the network created by Docker |
| `network-name` | No | elastic | Custom name for the network created by Docker |
| `container-name` | No | es | Custom name for the container created by Docker |

## Usage

Expand Down
5 changes: 5 additions & 0 deletions elasticsearch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ inputs:
description: 'Name of the network to create with docker'
required: false
default: elastic
container-name:
description: 'Name for the container'
required: false
default: es

runs:
using: 'docker'
Expand All @@ -50,3 +54,4 @@ runs:
ELASTICSEARCH_PASSWORD: ${{ inputs.elasticsearch_password }}
WAIT: ${{ inputs.wait }}
NETWORK_NAME: ${{ inputs.network-name }}
CONTAINER_NAME: ${{ inputs.container-name }}
21 changes: 11 additions & 10 deletions elasticsearch/run-elasticsearch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fi

MAJOR_VERSION=`echo ${STACK_VERSION} | cut -c 1`
NETWORK_NAME=${NETWORK_NAME:-elastic}
CONTAINER_NAME=${CONTAINER_NAME:-es}

docker network inspect $NETWORK_NAME >/dev/null 2>&1 || docker network create $NETWORK_NAME

Expand Down Expand Up @@ -38,7 +39,7 @@ do
if [ "x${MAJOR_VERSION}" == 'x6' ]; then
docker run \
--rm \
--env "node.name=es${node}" \
--env "node.name=${CONTAINER_NAME}${node}" \
--env "cluster.name=docker-elasticsearch" \
--env "cluster.routing.allocation.disk.threshold_enabled=false" \
--env "bootstrap.memory_lock=true" \
Expand All @@ -54,13 +55,13 @@ do
--publish "${port_com}:${port_com}" \
--detach \
--network=$NETWORK_NAME \
--name="es${node}" \
--name="${CONTAINER_NAME}${node}" \
-v /es/plugins/:/usr/share/elasticsearch/plugins/ \
docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
elif [ "x${MAJOR_VERSION}" == 'x7' ]; then
docker run \
--rm \
--env "node.name=es${node}" \
--env "node.name=${CONTAINER_NAME}${node}" \
--env "cluster.name=docker-elasticsearch" \
--env "cluster.initial_master_nodes=es1" \
--env "discovery.seed_hosts=es1" \
Expand All @@ -76,7 +77,7 @@ do
--publish "${port}:${port}" \
--detach \
--network=$NETWORK_NAME \
--name="es${node}" \
--name="${CONTAINER_NAME}${node}" \
-v /es/plugins/:/usr/share/elasticsearch/plugins/ \
docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
elif [ "x${MAJOR_VERSION}" == 'x8' ] || [ "x${MAJOR_VERSION}" == 'x9' ]; then
Expand All @@ -86,7 +87,7 @@ do
--rm \
--env "ELASTIC_PASSWORD=${elasticsearch_password}" \
--env "xpack.license.self_generated.type=basic" \
--env "node.name=es${node}" \
--env "node.name=${CONTAINER_NAME}${node}" \
--env "cluster.name=docker-elasticsearch" \
--env "cluster.initial_master_nodes=es1" \
--env "discovery.seed_hosts=es1" \
Expand All @@ -99,15 +100,15 @@ do
--ulimit memlock=-1:-1 \
--publish "${port}:${port}" \
--network=$NETWORK_NAME \
--name="es${node}" \
--name="${CONTAINER_NAME}${node}" \
--detach \
-v /es/plugins/:/usr/share/elasticsearch/plugins/ \
docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
else
docker run \
--rm \
--env "xpack.security.enabled=false" \
--env "node.name=es${node}" \
--env "node.name=${CONTAINER_NAME}${node}" \
--env "cluster.name=docker-elasticsearch" \
--env "cluster.initial_master_nodes=es1" \
--env "discovery.seed_hosts=es1" \
Expand All @@ -121,7 +122,7 @@ do
--ulimit memlock=-1:-1 \
--publish "${port}:${port}" \
--network=$NETWORK_NAME \
--name="es${node}" \
--name="${CONTAINER_NAME}${node}" \
--detach \
-v /es/plugins/:/usr/share/elasticsearch/plugins/ \
docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
Expand All @@ -142,7 +143,7 @@ if [ "x${MAJOR_VERSION}" == 'x8' ] && [ "${SECURITY_ENABLED}" == 'true' ]; then
--silent \
-k \
-u elastic:${ELASTICSEARCH_PASSWORD-'changeme'} \
https://es1:$PORT
https://${CONTAINER_NAME}1:$PORT
else
docker run \
--network $NETWORK_NAME \
Expand All @@ -154,7 +155,7 @@ else
--retry-connrefused \
--show-error \
--silent \
http://es1:$PORT
http://${CONTAINER_NAME}1:$PORT
fi

sleep $WAIT
Expand Down

0 comments on commit e9a59ec

Please sign in to comment.