Skip to content

Commit 817faeb

Browse files
Properly separate 1.x/2.x/default opensearch docker entrypoint like in opensearch-dashboards (#4452)
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
1 parent a193bbd commit 817faeb

7 files changed

+249
-5
lines changed

docker/release/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ Here are three example scenarios of using above variables:
103103
#### Scenario 2: No demo certs/configs + disable security on both OpenSearch and OpenSearch-Dashboards:
104104
* OpenSearch:
105105
```
106-
docker run -it -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "DISABLE_INSTALL_DEMO_CONFIG=true" -e "DISABLE_SECURITY_PLUGIN=true" opensearchproject/opensearch:1.1.0
106+
$ docker run -it -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "DISABLE_INSTALL_DEMO_CONFIG=true" -e "DISABLE_SECURITY_PLUGIN=true" opensearchproject/opensearch:1.1.0
107107
```
108-
Note: For OpenSearch > 2.11.1 and > 1.3.14, `DISABLE_SECURITY_PLUGIN` when set to true will automatically disable the security demo configuration setup and will no longer require `DISABLE_INSTALL_DEMO_CONFIG` to be explicitly set.
108+
Note: For OpenSearch 2.12 and later, `DISABLE_SECURITY_PLUGIN` when set to true will automatically disable the security demo configuration setup and will no longer require `DISABLE_INSTALL_DEMO_CONFIG` to be explicitly set.
109109
```
110-
docker run -it -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "DISABLE_SECURITY_PLUGIN=true" opensearchproject/opensearch:2.12.0
110+
$ docker run -it -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "DISABLE_SECURITY_PLUGIN=true" opensearchproject/opensearch:2.12.0
111111
```
112112
* OpenSearch-Dashboards:
113113
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
3+
# Copyright OpenSearch Contributors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# This script specify the entrypoint startup actions for opensearch
7+
# It will start both opensearch and performance analyzer plugin cli
8+
# If either process failed, the entire docker container will be removed
9+
# in favor of a newly started container
10+
11+
# Export OpenSearch Home
12+
export OPENSEARCH_HOME=/usr/share/opensearch
13+
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
14+
15+
# The virtual file /proc/self/cgroup should list the current cgroup
16+
# membership. For each hierarchy, you can follow the cgroup path from
17+
# this file to the cgroup filesystem (usually /sys/fs/cgroup/) and
18+
# introspect the statistics for the cgroup for the given
19+
# hierarchy. Alas, Docker breaks this by mounting the container
20+
# statistics at the root while leaving the cgroup paths as the actual
21+
# paths. Therefore, OpenSearch provides a mechanism to override
22+
# reading the cgroup path from /proc/self/cgroup and instead uses the
23+
# cgroup path defined the JVM system property
24+
# opensearch.cgroups.hierarchy.override. Therefore, we set this value here so
25+
# that cgroup statistics are available for the container this process
26+
# will run in.
27+
export OPENSEARCH_JAVA_OPTS="-Dopensearch.cgroups.hierarchy.override=/ $OPENSEARCH_JAVA_OPTS"
28+
29+
# Security Plugin
30+
function setupSecurityPlugin {
31+
SECURITY_PLUGIN="opensearch-security"
32+
33+
if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then
34+
if [ "$DISABLE_INSTALL_DEMO_CONFIG" = "true" ]; then
35+
echo "Disabling execution of install_demo_configuration.sh for OpenSearch Security Plugin"
36+
else
37+
echo "Enabling execution of install_demo_configuration.sh for OpenSearch Security Plugin"
38+
bash $OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN/tools/install_demo_configuration.sh -y -i -s
39+
fi
40+
41+
if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then
42+
echo "Disabling OpenSearch Security Plugin"
43+
opensearch_opt="-Eplugins.security.disabled=true"
44+
opensearch_opts+=("${opensearch_opt}")
45+
else
46+
echo "Enabling OpenSearch Security Plugin"
47+
fi
48+
else
49+
echo "OpenSearch Security Plugin does not exist, disable by default"
50+
fi
51+
}
52+
53+
# Performance Analyzer Plugin
54+
function setupPerformanceAnalyzerPlugin {
55+
PERFORMANCE_ANALYZER_PLUGIN="opensearch-performance-analyzer"
56+
if [ -d "$OPENSEARCH_HOME/plugins/$PERFORMANCE_ANALYZER_PLUGIN" ]; then
57+
if [ "$DISABLE_PERFORMANCE_ANALYZER_AGENT_CLI" = "true" ]; then
58+
echo "Disabling execution of $OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
59+
else
60+
echo "Enabling execution of OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
61+
$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli > $OPENSEARCH_HOME/logs/PerformanceAnalyzer.log 2>&1 & disown
62+
fi
63+
else
64+
echo "OpenSearch Performance Analyzer Plugin does not exist, disable by default"
65+
fi
66+
}
67+
68+
# Start up the opensearch and performance analyzer agent processes.
69+
# When either of them halts, this script exits, or we receive a SIGTERM or SIGINT signal then we want to kill both these processes.
70+
function runOpensearch {
71+
# Files created by OpenSearch should always be group writable too
72+
umask 0002
73+
74+
if [[ "$(id -u)" == "0" ]]; then
75+
echo "OpenSearch cannot run as root. Please start your container as another user."
76+
exit 1
77+
fi
78+
79+
# Parse Docker env vars to customize OpenSearch
80+
#
81+
# e.g. Setting the env var cluster.name=testcluster
82+
# will cause OpenSearch to be invoked with -Ecluster.name=testcluster
83+
opensearch_opts=()
84+
while IFS='=' read -r envvar_key envvar_value
85+
do
86+
# OpenSearch settings need to have at least two dot separated lowercase
87+
# words, e.g. `cluster.name`, except for `processors` which we handle
88+
# specially
89+
if [[ "$envvar_key" =~ ^[a-z0-9_]+\.[a-z0-9_]+ || "$envvar_key" == "processors" ]]; then
90+
if [[ ! -z $envvar_value ]]; then
91+
opensearch_opt="-E${envvar_key}=${envvar_value}"
92+
opensearch_opts+=("${opensearch_opt}")
93+
fi
94+
fi
95+
done < <(env)
96+
97+
setupSecurityPlugin
98+
setupPerformanceAnalyzerPlugin
99+
100+
# Start opensearch
101+
"$@" "${opensearch_opts[@]}"
102+
103+
}
104+
105+
# Prepend "opensearch" command if no argument was provided or if the first
106+
# argument looks like a flag (i.e. starts with a dash).
107+
if [ $# -eq 0 ] || [ "${1:0:1}" = '-' ]; then
108+
set -- opensearch "$@"
109+
fi
110+
111+
if [ "$1" = "opensearch" ]; then
112+
# If the first argument is opensearch, then run the setup script.
113+
runOpensearch "$@"
114+
else
115+
# Otherwise, just exec the command.
116+
exec "$@"
117+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
3+
# Copyright OpenSearch Contributors
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# This script specify the entrypoint startup actions for opensearch
7+
# It will start both opensearch and performance analyzer plugin cli
8+
# If either process failed, the entire docker container will be removed
9+
# in favor of a newly started container
10+
11+
# Export OpenSearch Home
12+
export OPENSEARCH_HOME=/usr/share/opensearch
13+
export OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
14+
15+
# The virtual file /proc/self/cgroup should list the current cgroup
16+
# membership. For each hierarchy, you can follow the cgroup path from
17+
# this file to the cgroup filesystem (usually /sys/fs/cgroup/) and
18+
# introspect the statistics for the cgroup for the given
19+
# hierarchy. Alas, Docker breaks this by mounting the container
20+
# statistics at the root while leaving the cgroup paths as the actual
21+
# paths. Therefore, OpenSearch provides a mechanism to override
22+
# reading the cgroup path from /proc/self/cgroup and instead uses the
23+
# cgroup path defined the JVM system property
24+
# opensearch.cgroups.hierarchy.override. Therefore, we set this value here so
25+
# that cgroup statistics are available for the container this process
26+
# will run in.
27+
export OPENSEARCH_JAVA_OPTS="-Dopensearch.cgroups.hierarchy.override=/ $OPENSEARCH_JAVA_OPTS"
28+
29+
# Security Plugin
30+
function setupSecurityPlugin {
31+
SECURITY_PLUGIN="opensearch-security"
32+
33+
if [ -d "$OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN" ]; then
34+
if [ "$DISABLE_SECURITY_PLUGIN" = "true" ]; then
35+
echo "Disabling OpenSearch Security Plugin"
36+
opensearch_opt="-Eplugins.security.disabled=true"
37+
opensearch_opts+=("${opensearch_opt}")
38+
else
39+
echo "Enabling OpenSearch Security Plugin"
40+
if [ "$DISABLE_INSTALL_DEMO_CONFIG" = "true" ]; then
41+
echo "Disabling execution of install_demo_configuration.sh for OpenSearch Security Plugin"
42+
else
43+
echo -e "Enabling execution of install_demo_configuration.sh for OpenSearch Security Plugin \nOpenSearch 2.12.0 onwards, the OpenSearch Security Plugin a change that requires an initial password for 'admin' user. \nPlease define an environment variable 'OPENSEARCH_INITIAL_ADMIN_PASSWORD' with a strong password string. \nIf a password is not provided, the setup will quit. \n For more details, please visit: https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/"
44+
bash $OPENSEARCH_HOME/plugins/$SECURITY_PLUGIN/tools/install_demo_configuration.sh -y -i -s || exit 1
45+
fi
46+
fi
47+
else
48+
echo "OpenSearch Security Plugin does not exist, disable by default"
49+
fi
50+
}
51+
52+
# Performance Analyzer Plugin
53+
function setupPerformanceAnalyzerPlugin {
54+
PERFORMANCE_ANALYZER_PLUGIN="opensearch-performance-analyzer"
55+
if [ -d "$OPENSEARCH_HOME/plugins/$PERFORMANCE_ANALYZER_PLUGIN" ]; then
56+
if [ "$DISABLE_PERFORMANCE_ANALYZER_AGENT_CLI" = "true" ]; then
57+
echo "Disabling execution of $OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
58+
else
59+
echo "Enabling execution of OPENSEARCH_HOME/bin/$PERFORMANCE_ANALYZER_PLUGIN/performance-analyzer-agent-cli for OpenSearch Performance Analyzer Plugin"
60+
$OPENSEARCH_HOME/bin/opensearch-performance-analyzer/performance-analyzer-agent-cli > $OPENSEARCH_HOME/logs/PerformanceAnalyzer.log 2>&1 & disown
61+
fi
62+
else
63+
echo "OpenSearch Performance Analyzer Plugin does not exist, disable by default"
64+
fi
65+
}
66+
67+
# Start up the opensearch and performance analyzer agent processes.
68+
# When either of them halts, this script exits, or we receive a SIGTERM or SIGINT signal then we want to kill both these processes.
69+
function runOpensearch {
70+
# Files created by OpenSearch should always be group writable too
71+
umask 0002
72+
73+
if [[ "$(id -u)" == "0" ]]; then
74+
echo "OpenSearch cannot run as root. Please start your container as another user."
75+
exit 1
76+
fi
77+
78+
# Parse Docker env vars to customize OpenSearch
79+
#
80+
# e.g. Setting the env var cluster.name=testcluster
81+
# will cause OpenSearch to be invoked with -Ecluster.name=testcluster
82+
opensearch_opts=()
83+
while IFS='=' read -r envvar_key envvar_value
84+
do
85+
# OpenSearch settings need to have at least two dot separated lowercase
86+
# words, e.g. `cluster.name`, except for `processors` which we handle
87+
# specially
88+
if [[ "$envvar_key" =~ ^[a-z0-9_]+\.[a-z0-9_]+ || "$envvar_key" == "processors" ]]; then
89+
if [[ ! -z $envvar_value ]]; then
90+
opensearch_opt="-E${envvar_key}=${envvar_value}"
91+
opensearch_opts+=("${opensearch_opt}")
92+
fi
93+
fi
94+
done < <(env)
95+
96+
setupSecurityPlugin
97+
setupPerformanceAnalyzerPlugin
98+
99+
# Start opensearch
100+
"$@" "${opensearch_opts[@]}"
101+
102+
}
103+
104+
# Prepend "opensearch" command if no argument was provided or if the first
105+
# argument looks like a flag (i.e. starts with a dash).
106+
if [ $# -eq 0 ] || [ "${1:0:1}" = '-' ]; then
107+
set -- opensearch "$@"
108+
fi
109+
110+
if [ "$1" = "opensearch" ]; then
111+
# If the first argument is opensearch, then run the setup script.
112+
runOpensearch "$@"
113+
else
114+
# Otherwise, just exec the command.
115+
exec "$@"
116+
fi

docker/release/dockerfiles/opensearch-dashboards.al2.dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ COPY * $TEMP_DIR/
3636
RUN tar -xzpf $TEMP_DIR/opensearch-dashboards-`uname -p`.tgz -C $OPENSEARCH_DASHBOARDS_HOME --strip-components=1 && \
3737
MAJOR_VERSION_ENTRYPOINT=`echo $VERSION | cut -d. -f1` && \
3838
MAJOR_VERSION_YML=`echo $VERSION | cut -d. -f1` && \
39+
echo $MAJOR_VERSION_ENTRYPOINT && echo $MAJOR_VERSION_YML && \
3940
if ! (ls $TEMP_DIR | grep -E "opensearch-dashboards-docker-entrypoint-.*.x.sh" | grep $MAJOR_VERSION_ENTRYPOINT); then MAJOR_VERSION_ENTRYPOINT="default"; fi && \
4041
if ! (ls $TEMP_DIR | grep -E "opensearch_dashboards-.*.x.yml" | grep $MAJOR_VERSION_YML); then MAJOR_VERSION_YML="default"; fi && \
4142
cp -v $TEMP_DIR/opensearch-dashboards-docker-entrypoint-$MAJOR_VERSION_ENTRYPOINT.x.sh $OPENSEARCH_DASHBOARDS_HOME/opensearch-dashboards-docker-entrypoint.sh && \

docker/release/dockerfiles/opensearch.al2.dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ FROM public.ecr.aws/amazonlinux/amazonlinux:2 AS linux_stage_0
1818

1919
ARG UID=1000
2020
ARG GID=1000
21+
ARG VERSION
2122
ARG TEMP_DIR=/tmp/opensearch
2223
ARG OPENSEARCH_HOME=/usr/share/opensearch
2324
ARG OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
@@ -39,10 +40,14 @@ RUN groupadd -g $GID opensearch && \
3940
COPY * $TEMP_DIR/
4041
RUN ls -l $TEMP_DIR && \
4142
tar -xzpf /tmp/opensearch/opensearch-`uname -p`.tgz -C $OPENSEARCH_HOME --strip-components=1 && \
43+
MAJOR_VERSION_ENTRYPOINT=`echo $VERSION | cut -d. -f1` && \
44+
echo $MAJOR_VERSION_ENTRYPOINT && \
45+
if ! (ls $TEMP_DIR | grep -E "opensearch-docker-entrypoint-.*.x.sh" | grep $MAJOR_VERSION_ENTRYPOINT); then MAJOR_VERSION_ENTRYPOINT="default"; fi && \
4246
mkdir -p $OPENSEARCH_HOME/data && chown -Rv $UID:$GID $OPENSEARCH_HOME/data && \
4347
if [[ -d $SECURITY_PLUGIN_DIR ]] ; then chmod -v 750 $SECURITY_PLUGIN_DIR/tools/* ; fi && \
4448
if [[ -d $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR ]] ; then cp -v $TEMP_DIR/performance-analyzer.properties $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR; fi && \
45-
cp -v $TEMP_DIR/opensearch-docker-entrypoint.sh $TEMP_DIR/opensearch-onetime-setup.sh $OPENSEARCH_HOME/ && \
49+
cp -v $TEMP_DIR/opensearch-docker-entrypoint-$MAJOR_VERSION_ENTRYPOINT.x.sh $OPENSEARCH_HOME/opensearch-docker-entrypoint.sh && \
50+
cp -v $TEMP_DIR/opensearch-onetime-setup.sh $OPENSEARCH_HOME/ && \
4651
cp -v $TEMP_DIR/log4j2.properties $TEMP_DIR/opensearch.yml $OPENSEARCH_PATH_CONF/ && \
4752
ls -l $OPENSEARCH_HOME && \
4853
rm -rf $TEMP_DIR

docker/release/dockerfiles/opensearch.al2023.dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS linux_stage_0
1818

1919
ARG UID=1000
2020
ARG GID=1000
21+
ARG VERSION
2122
ARG TEMP_DIR=/tmp/opensearch
2223
ARG OPENSEARCH_HOME=/usr/share/opensearch
2324
ARG OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
@@ -39,10 +40,14 @@ RUN groupadd -g $GID opensearch && \
3940
COPY * $TEMP_DIR/
4041
RUN ls -l $TEMP_DIR && \
4142
tar -xzpf /tmp/opensearch/opensearch-`uname -p`.tgz -C $OPENSEARCH_HOME --strip-components=1 && \
43+
MAJOR_VERSION_ENTRYPOINT=`echo $VERSION | cut -d. -f1` && \
44+
echo $MAJOR_VERSION_ENTRYPOINT && \
45+
if ! (ls $TEMP_DIR | grep -E "opensearch-docker-entrypoint-.*.x.sh" | grep $MAJOR_VERSION_ENTRYPOINT); then MAJOR_VERSION_ENTRYPOINT="default"; fi && \
4246
mkdir -p $OPENSEARCH_HOME/data && chown -Rv $UID:$GID $OPENSEARCH_HOME/data && \
4347
if [[ -d $SECURITY_PLUGIN_DIR ]] ; then chmod -v 750 $SECURITY_PLUGIN_DIR/tools/* ; fi && \
4448
if [[ -d $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR ]] ; then cp -v $TEMP_DIR/performance-analyzer.properties $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR; fi && \
45-
cp -v $TEMP_DIR/opensearch-docker-entrypoint.sh $TEMP_DIR/opensearch-onetime-setup.sh $OPENSEARCH_HOME/ && \
49+
cp -v $TEMP_DIR/opensearch-docker-entrypoint-$MAJOR_VERSION_ENTRYPOINT.x.sh $OPENSEARCH_HOME/opensearch-docker-entrypoint.sh && \
50+
cp -v $TEMP_DIR/opensearch-onetime-setup.sh $OPENSEARCH_HOME/ && \
4651
cp -v $TEMP_DIR/log4j2.properties $TEMP_DIR/opensearch.yml $OPENSEARCH_PATH_CONF/ && \
4752
ls -l $OPENSEARCH_HOME && \
4853
rm -rf $TEMP_DIR

0 commit comments

Comments
 (0)