Skip to content

Commit 316713c

Browse files
committed
opensearch
1 parent 063448a commit 316713c

File tree

3 files changed

+264
-0
lines changed

3 files changed

+264
-0
lines changed

.github/workflows/opensearch.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: opensearch
2+
3+
on:
4+
schedule:
5+
- cron: "0 10 * * *"
6+
push:
7+
branches:
8+
- "**"
9+
tags:
10+
- "v*.*.*"
11+
pull_request:
12+
branches:
13+
- "main"
14+
15+
jobs:
16+
opensearch:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set variables useful for later
20+
id: useful_vars
21+
run: |-
22+
echo "::set-output name=timestamp::$(date +%s)"
23+
echo "::set-output name=short_sha::${GITHUB_SHA::8}"
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
- name: Docker meta
27+
id: docker_meta
28+
uses: docker/metadata-action@v4
29+
with:
30+
images: ghcr.io/${{ github.repository }}/opensearch
31+
tags: |
32+
type=schedule
33+
type=ref,event=branch
34+
type=ref,event=pr
35+
type=semver,pattern={{version}}
36+
type=semver,pattern={{major}}.{{minor}}
37+
type=semver,pattern={{major}}
38+
type=sha,prefix=,format=long,event=tag
39+
type=sha
40+
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
41+
type=raw,value=${{ github.ref_name }}-${{ steps.useful_vars.outputs.short_sha }}-${{ steps.useful_vars.outputs.timestamp }},enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
42+
- name: Set up QEMU
43+
uses: docker/setup-qemu-action@v2
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v2
46+
- name: Login to GHCR
47+
if: github.event_name != 'pull_request'
48+
uses: docker/login-action@v2
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.repository_owner }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
- name: Cache Docker layers
54+
uses: actions/cache@v3
55+
with:
56+
path: /tmp/.buildx-cache
57+
key: ${{ runner.os }}-opensearch-buildx-${{ github.sha }}
58+
restore-keys: |
59+
${{ runner.os }}-opensearch-buildx-
60+
- name: Build and push
61+
uses: docker/build-push-action@v4
62+
with:
63+
context: opensearch
64+
push: ${{ github.event_name != 'pull_request' }}
65+
tags: ${{ steps.docker_meta.outputs.tags }}
66+
labels: ${{ steps.docker_meta.outputs.labels }}
67+
platforms: linux/amd64,linux/arm64
68+
cache-from: type=local,src=/tmp/.buildx-cache
69+
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max

opensearch/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG OPENSEARCH_VERSION=2.19.0
2+
3+
FROM ibm-semeru-runtimes:open-21-jdk-jammy AS semeru
4+
5+
FROM opensearchproject/opensearch:${OPENSEARCH_VERSION}
6+
7+
USER root
8+
9+
RUN rm -rf /usr/share/opensearch/jdk
10+
COPY --from=semeru /opt/java/openjdk /usr/share/opensearch/jdk
11+
RUN chown -R opensearch:opensearch /usr/share/opensearch/jdk
12+
13+
ENV OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk
14+
ENV JAVA_HOME=/usr/share/opensearch/jdk
15+
ENV PATH="/usr/share/opensearch/jdk/bin:${PATH}"
16+
17+
COPY entrypoint.sh /usr/share/opensearch/entrypoint.sh
18+
RUN chmod +x /usr/share/opensearch/entrypoint.sh
19+
20+
# Per-deployment, set OPENSEARCH_JAVA_OPTS in your k8s manifest:
21+
# -Xms256m -Xmx512m -Xsoftmx256m -XX:MaxDirectMemorySize=128m
22+
23+
USER opensearch
24+
25+
RUN java -version 2>&1 | grep -i "openj9" || exit 1
26+
27+
CMD ["/usr/share/opensearch/entrypoint.sh"]

opensearch/entrypoint.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export OPENSEARCH_HOME=/usr/share/opensearch
5+
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
6+
7+
# ---- openj9 jvm options (replaces jvm.options + JvmOptionsParser) ----
8+
# we build the jvm flags ourselves instead of using JvmOptionsParser which
9+
# hardcodes hotspot flags and fights openj9. we read jvm.options for the
10+
# non-gc, non-logging lines (heap size, system properties, etc.) and
11+
# append our openj9-specific flags.
12+
13+
build_jvm_opts() {
14+
local opts=""
15+
16+
# read jvm.options, skip comments, blanks, and hotspot-specific lines
17+
if [ -f "$OPENSEARCH_PATH_CONF/jvm.options" ]; then
18+
while IFS= read -r line; do
19+
# skip comments and blanks
20+
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue
21+
# skip version-gated lines (e.g. 8-10:, 11-:, 9-:)
22+
[[ "$line" =~ ^[0-9]+-?[0-9]*:- ]] && {
23+
# strip the version prefix to get the actual flag
24+
local flag="${line#*:-}"
25+
# skip all hotspot gc, gc tuning, and gc logging flags
26+
[[ "$flag" =~ UseG1GC|UseConcMarkSweepGC|UseSerialGC ]] && continue
27+
[[ "$flag" =~ G1ReservePercent|InitiatingHeapOccupancyPercent ]] && continue
28+
[[ "$flag" =~ CMSInitiatingOccupancyFraction|UseCMSInitiatingOccupancyOnly ]] && continue
29+
[[ "$flag" =~ CICompilerCount|TieredCompilation ]] && continue
30+
[[ "$flag" =~ InitialCodeCacheSize|InitialBootClassLoaderMetaspaceSize ]] && continue
31+
[[ "$flag" =~ Xlog: ]] && continue
32+
opts="$opts $flag"
33+
continue
34+
}
35+
# skip non-version-gated hotspot flags too
36+
[[ "$line" =~ UseG1GC|UseConcMarkSweepGC|UseSerialGC ]] && continue
37+
[[ "$line" =~ G1ReservePercent|InitiatingHeapOccupancyPercent ]] && continue
38+
[[ "$line" =~ CMSInitiatingOccupancyFraction|UseCMSInitiatingOccupancyOnly ]] && continue
39+
[[ "$line" =~ CICompilerCount|TieredCompilation ]] && continue
40+
[[ "$line" =~ InitialCodeCacheSize|InitialBootClassLoaderMetaspaceSize ]] && continue
41+
[[ "$line" =~ Xlog: ]] && continue
42+
# skip template variables that jvm.options uses (resolved by JvmOptionsParser normally)
43+
[[ "$line" =~ ^\$\{ ]] && continue
44+
opts="$opts $line"
45+
continue
46+
done < "$OPENSEARCH_PATH_CONF/jvm.options"
47+
fi
48+
49+
# also read jvm.options.d/*.options if present
50+
if [ -d "$OPENSEARCH_PATH_CONF/jvm.options.d" ]; then
51+
for f in "$OPENSEARCH_PATH_CONF/jvm.options.d"/*.options; do
52+
[ -f "$f" ] || continue
53+
while IFS= read -r line; do
54+
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue
55+
[[ "$line" =~ UseG1GC|UseConcMarkSweepGC|UseSerialGC ]] && continue
56+
[[ "$line" =~ Xlog: ]] && continue
57+
[[ "$line" =~ ^\$\{ ]] && continue
58+
opts="$opts $line"
59+
done < "$f"
60+
done
61+
fi
62+
63+
# openj9 flags
64+
opts="$opts -XX:+IdleTuningGcOnIdle"
65+
opts="$opts -XX:IdleTuningMinIdleWaitTime=240"
66+
opts="$opts -Xshareclasses:none"
67+
opts="$opts -Xquickstart"
68+
opts="$opts -Xmns8m"
69+
opts="$opts -Xmnx64m"
70+
opts="$opts -Xsoftrefthreshold1"
71+
opts="$opts -XX:+ExitOnOutOfMemoryError"
72+
73+
# resolve heap dump path and error file (normally done by JvmOptionsParser)
74+
opts="$opts -XX:+HeapDumpOnOutOfMemoryError"
75+
opts="$opts -XX:HeapDumpPath=data"
76+
opts="$opts -XX:ErrorFile=logs/hs_err_pid%p.log"
77+
78+
# tmpdir
79+
export OPENSEARCH_TMPDIR=$(mktemp -d -t opensearch.XXXXXXXX)
80+
opts="$opts -Djava.io.tmpdir=$OPENSEARCH_TMPDIR"
81+
82+
# user-provided opts (from k8s env) go last so they override
83+
opts="$opts ${OPENSEARCH_JAVA_OPTS:-}"
84+
85+
echo "$opts"
86+
}
87+
88+
# ---- security plugin setup ----
89+
setup_security() {
90+
local SECURITY_PLUGIN="opensearch-security"
91+
if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then
92+
if [ "$DISABLE_INSTALL_DEMO_CONFIG" = "true" ]; then
93+
echo "Disabling execution of install_demo_configuration.sh for OpenSearch Security Plugin"
94+
else
95+
echo "Enabling execution of install_demo_configuration.sh for OpenSearch Security Plugin"
96+
bash "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN/tools/install_demo_configuration.sh" -y -i -s
97+
fi
98+
99+
if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then
100+
echo "Disabling OpenSearch Security Plugin"
101+
opensearch_opts+=("-Eplugins.security.disabled=true")
102+
fi
103+
fi
104+
}
105+
106+
# ---- performance analyzer setup ----
107+
setup_performance_analyzer() {
108+
local PA_PLUGIN="opensearch-performance-analyzer"
109+
if [ -d "$OPENSEARCH_HOME/plugins/$PA_PLUGIN" ]; then
110+
if [ "$DISABLE_PERFORMANCE_ANALYZER_AGENT_CLI" = "true" ]; then
111+
echo "Disabling execution of performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
112+
else
113+
echo "Enabling execution of performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
114+
"$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli" \
115+
> "$OPENSEARCH_HOME/logs/performance-analyzer.log" 2>&1 &
116+
disown
117+
fi
118+
fi
119+
}
120+
121+
# ---- main ----
122+
run_opensearch() {
123+
local opensearch_opts=()
124+
125+
# collect -E flags from environment variables
126+
while IFS='=' read -r envvar_key envvar_value; do
127+
if [[ "$envvar_key" =~ ^[a-z0-9_]+\.[a-z0-9_]+\.?[a-z0-9_]*$ ]]; then
128+
opensearch_opts+=("-E${envvar_key}=${envvar_value}")
129+
fi
130+
done < <(env)
131+
132+
# save user's OPENSEARCH_JAVA_OPTS before cli tools clobber it
133+
local user_java_opts="${OPENSEARCH_JAVA_OPTS:-}"
134+
135+
# cli tools (keystore, security setup) need a clean OPENSEARCH_JAVA_OPTS
136+
# without our openj9 flags — they use opensearch-cli which prepends its own flags
137+
export OPENSEARCH_JAVA_OPTS=""
138+
139+
setup_security
140+
setup_performance_analyzer
141+
142+
# now build the real jvm opts for the main opensearch process
143+
export OPENSEARCH_JAVA_OPTS="$user_java_opts"
144+
local jvm_opts
145+
jvm_opts=$(build_jvm_opts)
146+
147+
# start opensearch directly with our jvm opts, bypassing JvmOptionsParser
148+
cd "$OPENSEARCH_HOME"
149+
exec "$OPENSEARCH_HOME/jdk/bin/java" \
150+
$jvm_opts \
151+
-Dopensearch.path.home="$OPENSEARCH_HOME" \
152+
-Dopensearch.path.conf="$OPENSEARCH_PATH_CONF" \
153+
-Dopensearch.distribution.type=docker \
154+
-cp "$OPENSEARCH_HOME/lib/*:$OPENSEARCH_HOME/lib/tools/launchers/*" \
155+
org.opensearch.bootstrap.OpenSearch \
156+
"${opensearch_opts[@]}"
157+
}
158+
159+
if [ $# -eq 0 ] || [ "${1:0:1}" = '-' ]; then
160+
set -- opensearch "$@"
161+
fi
162+
163+
if [ "$1" = "opensearch" ]; then
164+
shift
165+
run_opensearch "$@"
166+
else
167+
exec "$@"
168+
fi

0 commit comments

Comments
 (0)