Skip to content

Instantly share code, notes, and snippets.

@rluvaton
Created August 21, 2022 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rluvaton/3d7e698314f5b9204ff5be94d93fb2f6 to your computer and use it in GitHub Desktop.
Save rluvaton/3d7e698314f5b9204ff5be94d93fb2f6 to your computer and use it in GitHub Desktop.
Elastic Search Testing

ElasticSearch Optimized for tests

The Dockerfile here is an ElasticSearch with support for ARM processors.

Also, it's optimized for testing by disabling a lot of features and lowering the memory that is needed

Took most of the configuration out of Sanne/elasticsearch-light-testing

# If in AMD than use the regular image
FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.23 as AMD
COPY elasticsearch.yml /usr/share/elasticsearch/config/
COPY jvm.options /usr/share/elasticsearch/config/
RUN mkdir -p /usr/share/elasticsearch-data-and-logs/data /usr/share/elasticsearch-data-and-logs/logs
RUN chmod 777 /usr/share/elasticsearch-data-and-logs/data /usr/share/elasticsearch-data-and-logs/logs
# If on ARM we build it ourselves
FROM ubuntu:bionic-20220531 as ARM
# Must be root to install the packages
USER root
RUN apt update
RUN apt -y install gnupg wget apt-transport-https coreutils java-common
# Install ARM Amazon JDK
RUN wget https://corretto.aws/downloads/latest/amazon-corretto-8-aarch64-linux-jdk.deb -O amazon-jdk.deb
RUN dpkg --skip-same-version -i amazon-jdk.deb
RUN rm amazon-jdk.deb
# Import Elasticsearch GPG Key
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
# Add Elasticsearch 6.x APT repository
# setting CPU architecture to be amd64 explicity as in case this is being built from ARM (which it should) it would find the elasticsearch package (elasticsearch 6.x doesn't have ARM binary)
RUN #echo "deb [arch=amd64] https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
RUN echo "deb [arch=amd64] https://artifacts.elastic.co/packages/oss-6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
# update after elastic-search repo added
RUN apt-get update
# Install Elasticsearch 6.x
RUN apt-get -y install elasticsearch-oss
RUN mkdir -p /usr/share/elasticsearch-data-and-logs/data /usr/share/elasticsearch-data-and-logs/logs
RUN chmod 777 /usr/share/elasticsearch-data-and-logs/data /usr/share/elasticsearch-data-and-logs/logs
# the user was created when installed the elasticsearch
# Must not be root:
# org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
USER elasticsearch
WORKDIR /usr/share/elasticsearch
COPY elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
COPY jvm.options /etc/elasticsearch/
ENTRYPOINT [ "./bin/elasticsearch" ]
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 1
discovery.type: single-node
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
action.destructive_requires_name: true
path.data: /usr/share/elasticsearch-data-and-logs/data
path.logs: /usr/share/elasticsearch-data-and-logs/logs
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms200M
-Xmx300M
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
## GC configuration: disabled to sto allow self-tuning for small heap
#-XX:+UseConcMarkSweepGC
#-XX:CMSInitiatingOccupancyFraction=75
#-XX:+UseCMSInitiatingOccupancyOnly
## optimizations
# disable calls to System#gc
-XX:+DisableExplicitGC
# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch
## basic
# force the server VM (remove on 32-bit client JVMs)
#-server
# explicitly set the stack size (reduce to 320k on 32-bit client JVMs)
-Xss1m
# set to headless, just in case
-Djava.awt.headless=true
# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8
# use our provided JNA always versus the system one
-Djna.nosys=true
# use old-style file permissions on JDK9
-Djdk.io.permissionsUseCanonicalPath=true
# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Dlog4j.skipJansi=true
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps
# ensure the directory exists and has sufficient space
#-XX:HeapDumpPath=${heap.dump.path}
## GC logging
#-XX:+PrintGCDetails
#-XX:+PrintGCTimeStamps
#-XX:+PrintGCDateStamps
#-XX:+PrintClassHistogram
#-XX:+PrintTenuringDistribution
#-XX:+PrintGCApplicationStoppedTime
# log GC status to a file with time stamps
# ensure the directory exists
#-Xloggc:${loggc}
# By default, the GC log file will not rotate.
# By uncommenting the lines below, the GC log file
# will be rotated every 128MB at most 32 times.
#-XX:+UseGCLogFileRotation
#-XX:NumberOfGCLogFiles=32
#-XX:GCLogFileSize=128M
# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON.
# If documents were already indexed with unquoted fields in a previous version
# of Elasticsearch, some operations may throw errors.
#
# This will be enforced in future versions, prepare for it:
-Des.scripting.exception_for_missing_value=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment