update opensearch master
This commit is contained in:
@@ -1,105 +1,34 @@
|
|||||||
ARG BUILD_FROM=ghcr.io/hassio-addons/base:18.1.1
|
ARG BUILD_FROM
|
||||||
FROM ${BUILD_FROM}
|
FROM ${BUILD_FROM}
|
||||||
|
|
||||||
# Set environment variables
|
# Set working directory
|
||||||
ENV \
|
WORKDIR /root
|
||||||
LANG=C.UTF-8 \
|
|
||||||
OPENSEARCH_HOME="/usr/share/opensearch" \
|
|
||||||
OPENSEARCH_PATH_CONF="/usr/share/opensearch/config" \
|
|
||||||
OPENSEARCH_DATA_DIR="/usr/share/opensearch/data" \
|
|
||||||
OPENSEARCH_LOGS_DIR="/usr/share/opensearch/logs" \
|
|
||||||
OPENSEARCH_PLUGINS_DIR="/usr/share/opensearch/plugins" \
|
|
||||||
PATH="/usr/share/opensearch/bin:$PATH"
|
|
||||||
|
|
||||||
# Build arguments
|
# Install dependencies
|
||||||
ARG BUILD_ARCH
|
RUN apk add --no-cache \
|
||||||
ARG BUILD_DATE
|
bash \
|
||||||
ARG BUILD_DESCRIPTION
|
curl \
|
||||||
ARG BUILD_NAME
|
openjdk17-jre \
|
||||||
ARG BUILD_REF
|
su-exec
|
||||||
ARG BUILD_REPOSITORY
|
|
||||||
ARG BUILD_VERSION
|
|
||||||
|
|
||||||
# Set OpenSearch version
|
# Create opensearch user
|
||||||
ARG OPENSEARCH_VERSION=3.2.0
|
RUN addgroup -g 1000 opensearch && \
|
||||||
|
adduser -u 1000 -G opensearch -h /usr/share/opensearch -D opensearch
|
||||||
|
|
||||||
# Install required dependencies
|
# Download and install OpenSearch 3.2.0 for ARM64
|
||||||
RUN \
|
RUN curl -L https://artifacts.opensearch.org/releases/bundle/opensearch/3.2.0/opensearch-3.2.0-linux-arm64.tar.gz -o opensearch.tar.gz && \
|
||||||
apk add --no-cache --virtual .build-deps \
|
tar -xzf opensearch.tar.gz && \
|
||||||
curl \
|
mv opensearch-3.2.0 /usr/share/opensearch && \
|
||||||
tar \
|
rm opensearch.tar.gz
|
||||||
gzip \
|
|
||||||
gnupg \
|
|
||||||
&& apk add --no-cache \
|
|
||||||
openjdk17-jre-headless \
|
|
||||||
openjdk17 \
|
|
||||||
jq \
|
|
||||||
gettext \
|
|
||||||
bash \
|
|
||||||
su-exec \
|
|
||||||
tini \
|
|
||||||
&& rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
# Create opensearch user and group
|
|
||||||
RUN \
|
|
||||||
addgroup -S -g 1000 opensearch \
|
|
||||||
&& adduser -S -u 1000 -G opensearch -H -h /usr/share/opensearch opensearch
|
|
||||||
|
|
||||||
# Download and install OpenSearch
|
|
||||||
RUN \
|
|
||||||
mkdir -p /tmp/opensearch \
|
|
||||||
&& cd /tmp/opensearch \
|
|
||||||
&& curl -fsSL "https://artifacts.opensearch.org/releases/bundle/opensearch/${OPENSEARCH_VERSION}/opensearch-${OPENSEARCH_VERSION}-linux-x64.tar.gz" -o opensearch.tar.gz \
|
|
||||||
&& tar -xzf opensearch.tar.gz --strip-components=1 \
|
|
||||||
&& mv opensearch-${OPENSEARCH_VERSION}/* /usr/share/opensearch/ \
|
|
||||||
&& rm -rf /tmp/opensearch \
|
|
||||||
&& chown -R opensearch:opensearch /usr/share/opensearch
|
|
||||||
|
|
||||||
# Create directories and set permissions
|
# Create directories and set permissions
|
||||||
RUN \
|
RUN mkdir -p /var/lib/opensearch /var/log/opensearch /usr/share/opensearch/plugins && \
|
||||||
mkdir -p \
|
chown -R opensearch:opensearch /usr/share/opensearch /var/lib/opensearch /var/log/opensearch
|
||||||
"${OPENSEARCH_DATA_DIR}" \
|
|
||||||
"${OPENSEARCH_LOGS_DIR}" \
|
|
||||||
"${OPENSEARCH_PATH_CONF}" \
|
|
||||||
"${OPENSEARCH_PLUGINS_DIR}" \
|
|
||||||
&& chown -R opensearch:opensearch /usr/share/opensearch
|
|
||||||
|
|
||||||
# Copy root filesystem
|
# Copy configuration and script
|
||||||
COPY rootfs /
|
COPY rootfs /
|
||||||
|
|
||||||
# Set permissions
|
# Set permissions
|
||||||
RUN \
|
RUN chmod +x /etc/cont-init.d/* /etc/services.d/*/*
|
||||||
chmod a+x \
|
|
||||||
/usr/bin/configure-opensearch \
|
|
||||||
/usr/share/opensearch/bin/* \
|
|
||||||
&& chown -R opensearch:opensearch /usr/share/opensearch
|
|
||||||
|
|
||||||
# Clean up build dependencies
|
WORKDIR /usr/share/opensearch
|
||||||
RUN apk del .build-deps
|
|
||||||
|
|
||||||
# Expose ports
|
|
||||||
EXPOSE 9200 9300
|
|
||||||
|
|
||||||
# Health check
|
|
||||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=300s --retries=3 \
|
|
||||||
CMD curl -f http://localhost:9200/_cluster/health || exit 1
|
|
||||||
|
|
||||||
# Labels
|
|
||||||
LABEL \
|
|
||||||
io.hass.name="OpenSearch Master" \
|
|
||||||
io.hass.description="OpenSearch master node for Home Assistant" \
|
|
||||||
io.hass.arch="${BUILD_ARCH}" \
|
|
||||||
io.hass.type="addon" \
|
|
||||||
io.hass.version="${BUILD_VERSION}" \
|
|
||||||
maintainer="Your Name" \
|
|
||||||
org.opencontainers.image.title="OpenSearch Master" \
|
|
||||||
org.opencontainers.image.description="OpenSearch master node for Home Assistant" \
|
|
||||||
org.opencontainers.image.vendor="Home Assistant Local Add-ons" \
|
|
||||||
org.opencontainers.image.authors="Your Name" \
|
|
||||||
org.opencontainers.image.licenses="Apache-2.0" \
|
|
||||||
org.opencontainers.image.url="https://github.com/your-username/your-repo" \
|
|
||||||
org.opencontainers.image.source="https://github.com/your-username/your-repo/opensearch-master" \
|
|
||||||
org.opencontainers.image.documentation="https://github.com/your-username/your-repo/blob/main/opensearch-master/README.md"
|
|
||||||
|
|
||||||
# Set entrypoint
|
|
||||||
ENTRYPOINT ["/usr/bin/configure-opensearch"]
|
|
@@ -1,50 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "OpenSearch Master",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"slug": "opensearch-master",
|
|
||||||
"description": "OpenSearch master node for Home Assistant",
|
|
||||||
"arch": ["amd64", "aarch64", "armv7"],
|
|
||||||
"startup": "services",
|
|
||||||
"boot": "auto",
|
|
||||||
"host_network": true,
|
|
||||||
"init": false,
|
|
||||||
"privileged": ["SYS_ADMIN"],
|
|
||||||
"map": [
|
|
||||||
["config", "/usr/share/opensearch/config", "rw"],
|
|
||||||
["data", "/usr/share/opensearch/data", "rw"],
|
|
||||||
["logs", "/usr/share/opensearch/logs", "rw"]
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"node_role": ["master"],
|
|
||||||
"cluster_name": "hass-opensearch-cluster",
|
|
||||||
"node_name": "os-master",
|
|
||||||
"heap_size": "2g",
|
|
||||||
"http_port": 9200,
|
|
||||||
"transport_port": 9300,
|
|
||||||
"discovery_seed_hosts": ["os-master:9300"],
|
|
||||||
"initial_master_nodes": ["os-master"],
|
|
||||||
"security_enabled": false,
|
|
||||||
"admin_password": "SecurePass123!",
|
|
||||||
"plugins": []
|
|
||||||
},
|
|
||||||
"schema": {
|
|
||||||
"node_role": ["str"],
|
|
||||||
"cluster_name": "str",
|
|
||||||
"node_name": "str",
|
|
||||||
"heap_size": "str",
|
|
||||||
"http_port": "int",
|
|
||||||
"transport_port": "int",
|
|
||||||
"discovery_seed_hosts": ["str"],
|
|
||||||
"initial_master_nodes": ["str"],
|
|
||||||
"security_enabled": "bool",
|
|
||||||
"admin_password": "password",
|
|
||||||
"plugins": ["str"]
|
|
||||||
},
|
|
||||||
"ports": {
|
|
||||||
"9200/tcp": 9200,
|
|
||||||
"9300/tcp": 9300
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"OPENSEARCH_HEAP_SIZE": "2g"
|
|
||||||
}
|
|
||||||
}
|
|
34
opensearch-master/config.yaml
Normal file
34
opensearch-master/config.yaml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: "OpenSearch Master"
|
||||||
|
version: "3.2.0"
|
||||||
|
slug: "opensearch_master"
|
||||||
|
description: "OpenSearch Master Node for HA Cluster"
|
||||||
|
url: "https://github.com/alexbelgium/hassio-addons"
|
||||||
|
arch:
|
||||||
|
- aarch64
|
||||||
|
- armv7
|
||||||
|
init: false
|
||||||
|
ports:
|
||||||
|
9200/tcp: 9200
|
||||||
|
9300/tcp: 9300
|
||||||
|
ports_description:
|
||||||
|
9200/tcp: "REST API"
|
||||||
|
9300/tcp: "Node communication"
|
||||||
|
map:
|
||||||
|
- config:rw
|
||||||
|
- ssl:rw
|
||||||
|
options:
|
||||||
|
cluster_name: "home-assistant-cluster"
|
||||||
|
node_name: "opensearch-master"
|
||||||
|
discovery_seed_hosts: "opensearch-master,opensearch-coordinator,192.168.10.10,192.168.10.11"
|
||||||
|
initial_master_nodes: "opensearch-master,opensearch-coordinator"
|
||||||
|
heap_size: "2g"
|
||||||
|
plugins: ""
|
||||||
|
env_var:
|
||||||
|
CLUSTER_NAME: home-assistant-cluster
|
||||||
|
schema:
|
||||||
|
cluster_name: str
|
||||||
|
node_name: str
|
||||||
|
discovery_seed_hosts: str
|
||||||
|
initial_master_nodes: str
|
||||||
|
heap_size: str
|
||||||
|
plugins: str
|
30
opensearch-master/rootfs/etc/cont-init.d/opensearch.sh
Normal file
30
opensearch-master/rootfs/etc/cont-init.d/opensearch.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/with-contenv bash
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
export OPENSEARCH_HOME="/usr/share/opensearch"
|
||||||
|
export OPENSEARCH_PATH_CONF="/etc/opensearch"
|
||||||
|
export OPENSEARCH_JAVA_OPTS="-Xms${HEAP_SIZE:-2g} -Xmx${HEAP_SIZE:-2g}"
|
||||||
|
|
||||||
|
# Create config directory
|
||||||
|
mkdir -p /etc/opensearch
|
||||||
|
|
||||||
|
# Generate opensearch.yml
|
||||||
|
cat > /etc/opensearch/opensearch.yml << EOF
|
||||||
|
cluster.name: ${CLUSTER_NAME:-home-assistant-cluster}
|
||||||
|
node.name: ${NODE_NAME:-opensearch-master}
|
||||||
|
node.roles: [master]
|
||||||
|
|
||||||
|
path.data: /var/lib/opensearch
|
||||||
|
path.logs: /var/log/opensearch
|
||||||
|
|
||||||
|
network.host: 0.0.0.0
|
||||||
|
http.port: 9200
|
||||||
|
|
||||||
|
discovery.seed_hosts: [${DISCOVERY_SEED_HOSTS:-opensearch-master,opensearch-coordinator}]
|
||||||
|
cluster.initial_master_nodes: [${INITIAL_MASTER_NODES:-opensearch-master,opensearch-coordinator}]
|
||||||
|
|
||||||
|
plugins.security.disabled: true
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Set permissions
|
||||||
|
chown -R opensearch:opensearch /etc/opensearch /var/lib/opensearch /var/log/opensearch
|
@@ -1,17 +0,0 @@
|
|||||||
cluster.name: "${CLUSTER_NAME}"
|
|
||||||
node.name: "${NODE_NAME}"
|
|
||||||
node.roles: [${NODE_ROLE}]
|
|
||||||
|
|
||||||
path.data: /usr/share/opensearch/data
|
|
||||||
path.logs: /usr/share/opensearch/logs
|
|
||||||
|
|
||||||
network.host: 0.0.0.0
|
|
||||||
http.port: ${HTTP_PORT}
|
|
||||||
transport.port: ${TRANSPORT_PORT}
|
|
||||||
|
|
||||||
discovery.seed_hosts: [${DISCOVERY_SEEDS}]
|
|
||||||
cluster.initial_master_nodes: [${INITIAL_MASTERS}]
|
|
||||||
|
|
||||||
plugins.security.disabled: ${SECURITY_ENABLED}
|
|
||||||
|
|
||||||
action.auto_create_index: true
|
|
2
opensearch-master/rootfs/etc/services.d/opensearch/run
Normal file
2
opensearch-master/rootfs/etc/services.d/opensearch/run
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/with-contenv bash
|
||||||
|
exec s6-setuidgid opensearch /usr/share/opensearch/bin/opensearch
|
@@ -1,74 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Function to read configuration using bashio
|
|
||||||
read_config() {
|
|
||||||
if command -v bashio >/dev/null 2>&1; then
|
|
||||||
bashio::config "$1"
|
|
||||||
else
|
|
||||||
# Fallback for testing
|
|
||||||
case "$1" in
|
|
||||||
"node_role") echo "master" ;;
|
|
||||||
"cluster_name") echo "hass-opensearch-cluster" ;;
|
|
||||||
"node_name") echo "os-master" ;;
|
|
||||||
"heap_size") echo "1g" ;;
|
|
||||||
"http_port") echo "9200" ;;
|
|
||||||
"transport_port") echo "9300" ;;
|
|
||||||
"discovery_seed_hosts") echo '["os-master:9300"]' ;;
|
|
||||||
"initial_master_nodes") echo '["os-master"]' ;;
|
|
||||||
"security_enabled") echo "false" ;;
|
|
||||||
"admin_password") echo "SecurePass123!" ;;
|
|
||||||
"plugins") echo "[]" ;;
|
|
||||||
*) echo "" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read configuration
|
|
||||||
NODE_ROLE=$(read_config 'node_role' | tr -d '[]"' | tr ',' ' ')
|
|
||||||
CLUSTER_NAME=$(read_config 'cluster_name')
|
|
||||||
NODE_NAME=$(read_config 'node_name')
|
|
||||||
HEAP_SIZE=$(read_config 'heap_size')
|
|
||||||
HTTP_PORT=$(read_config 'http_port')
|
|
||||||
TRANSPORT_PORT=$(read_config 'transport_port')
|
|
||||||
DISCOVERY_SEEDS=$(read_config 'discovery_seed_hosts' | tr -d '[]"' | tr ',' ' ')
|
|
||||||
INITIAL_MASTERS=$(read_config 'initial_master_nodes' | tr -d '[]"' | tr ',' ' ')
|
|
||||||
SECURITY_ENABLED=$(read_config 'security_enabled')
|
|
||||||
ADMIN_PASSWORD=$(read_config 'admin_password')
|
|
||||||
|
|
||||||
# Set heap size
|
|
||||||
export OPENSEARCH_JAVA_OPTS="-Xms${HEAP_SIZE} -Xmx${HEAP_SIZE}"
|
|
||||||
export OPENSEARCH_HEAP_SIZE="${HEAP_SIZE}"
|
|
||||||
|
|
||||||
# Set admin password
|
|
||||||
export OPENSEARCH_INITIAL_ADMIN_PASSWORD="${ADMIN_PASSWORD}"
|
|
||||||
|
|
||||||
# Export variables for envsubst
|
|
||||||
export CLUSTER_NAME="${CLUSTER_NAME:-hass-opensearch-cluster}"
|
|
||||||
export NODE_NAME="${NODE_NAME:-os-master}"
|
|
||||||
export NODE_ROLE="${NODE_ROLE:-master}"
|
|
||||||
export HTTP_PORT="${HTTP_PORT:-9200}"
|
|
||||||
export TRANSPORT_PORT="${TRANSPORT_PORT:-9300}"
|
|
||||||
export DISCOVERY_SEEDS="${DISCOVERY_SEEDS:-os-master:9300}"
|
|
||||||
export INITIAL_MASTERS="${INITIAL_MASTERS:-os-master}"
|
|
||||||
export SECURITY_ENABLED="${SECURITY_ENABLED:-false}"
|
|
||||||
|
|
||||||
# Generate configuration from template
|
|
||||||
envsubst < /etc/opensearch/opensearch.yml.template > /usr/share/opensearch/config/opensearch.yml
|
|
||||||
|
|
||||||
# Install plugins if specified
|
|
||||||
PLUGINS_JSON=$(read_config 'plugins')
|
|
||||||
if [ -n "$PLUGINS_JSON" ] && [ "$PLUGINS_JSON" != "[]" ]; then
|
|
||||||
PLUGINS=$(echo "$PLUGINS_JSON" | jq -r '.[]' 2>/dev/null || echo "")
|
|
||||||
for plugin in $PLUGINS; do
|
|
||||||
echo "Installing plugin: $plugin"
|
|
||||||
/usr/share/opensearch/bin/opensearch-plugin install --batch "$plugin" || true
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set vm.max_map_count if possible
|
|
||||||
if [ -w /proc/sys/vm/max_map_count ]; then
|
|
||||||
echo 262144 > /proc/sys/vm/max_map_count
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Start OpenSearch as opensearch user
|
|
||||||
exec su-exec opensearch /usr/share/opensearch/bin/opensearch
|
|
Reference in New Issue
Block a user