Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# Dockerfile for building an OpenSearch image using UBI9 instead of amazonlinux.
# It assumes that the working directory contains these files: an OpenSearch tarball (opensearch.tgz), log4j2.properties, opensearch.yml, opensearch-docker-entrypoint.sh, opensearch-onetime-setup.sh, opensearch-build.patch‎ and the snapshots of the plugins required .
# Build arguments:
# VERSION: Required. Used to label the image.
# BUILD_DATE: Required. Used to label the image. Should be in the form 'yyyy-mm-ddThh:mm:ssZ', i.e. a date-time from https://tools.ietf.org/html/rfc3339. The timestamp must be in UTC.
# UID: Optional. Specify the opensearch userid. Defaults to 1000.
# GID: Optional. Specify the opensearch groupid. Defaults to 1000.
# OPENSEARCH_HOME: Optional. Specify the opensearch root directory. Defaults to /usr/share/opensearch.
#

########################### Stage 0 ########################
FROM registry.access.redhat.com/ubi9:latest AS linux_stage_0

ARG UID=1000
ARG GID=1000
ARG VERSION
ARG TEMP_DIR=/tmp/opensearch
ARG OPENSEARCH_HOME=/usr/share/opensearch
ARG OPENSEARCH_PATH_CONF=$OPENSEARCH_HOME/config
ARG SECURITY_PLUGIN_DIR=$OPENSEARCH_HOME/plugins/opensearch-security
ARG PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR=$OPENSEARCH_PATH_CONF/opensearch-performance-analyzer

# Update packages
# Install the tools we need: tar and gzip to unpack the OpenSearch tarball, and shadow-utils to give us `groupadd` and `useradd`.
# Install which to allow running of securityadmin.sh
RUN dnf update -y && dnf install -y tar gzip shadow-utils which && dnf clean all

# Create an opensearch user, group
# OpenShift compatibility: Add user to root group (GID 0) for random UID support
RUN groupadd -g $GID opensearch && \
adduser -u $UID -g $GID -G 0 -d $OPENSEARCH_HOME opensearch && \
mkdir $TEMP_DIR

# Prepare working directory
# Copy artifacts and configurations to corresponding directories
COPY * $TEMP_DIR/
RUN ls -l $TEMP_DIR && \
tar -xzpf /tmp/opensearch/opensearch-ppc64le.tgz -C $OPENSEARCH_HOME --strip-components=1 && \
MAJOR_VERSION_ENTRYPOINT=`echo $VERSION | cut -d. -f1` && \
echo $MAJOR_VERSION_ENTRYPOINT && \
if ! (ls $TEMP_DIR | grep -E "opensearch-docker-entrypoint-.*.x.sh" | grep $MAJOR_VERSION_ENTRYPOINT); then MAJOR_VERSION_ENTRYPOINT="default"; fi && \
mkdir -p $OPENSEARCH_HOME/data && chown -Rv $UID:$GID $OPENSEARCH_HOME/data && \
if [[ -d $SECURITY_PLUGIN_DIR ]] ; then chmod -v 750 $SECURITY_PLUGIN_DIR/tools/* ; fi && \
if [[ -d $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR ]] ; then cp -v $TEMP_DIR/performance-analyzer.properties $PERFORMANCE_ANALYZER_PLUGIN_CONFIG_DIR; fi && \
cp -v $TEMP_DIR/opensearch-docker-entrypoint-$MAJOR_VERSION_ENTRYPOINT.x.sh $OPENSEARCH_HOME/opensearch-docker-entrypoint.sh && \
cp -v $TEMP_DIR/opensearch-onetime-setup.sh $OPENSEARCH_HOME/ && \
cp -v $TEMP_DIR/log4j2.properties $TEMP_DIR/opensearch.yml $OPENSEARCH_PATH_CONF/ && \
ls -l $OPENSEARCH_HOME && \
rm -rf $TEMP_DIR


########################### Stage 1 ########################
# Copy working directory to the actual release docker images
FROM registry.access.redhat.com/ubi9:latest

ARG UID=1000
ARG GID=1000
ARG OPENSEARCH_HOME=/usr/share/opensearch

# Update packages
# Install the tools we need: tar and gzip to unpack the OpenSearch tarball, and shadow-utils to give us `groupadd` and `useradd`.
# Install which to allow running of securityadmin.sh
RUN dnf update -y && dnf install -y tar gzip shadow-utils which && dnf clean all

# Create an opensearch user, group
RUN groupadd -g $GID opensearch && \
adduser -u $UID -g $GID -d $OPENSEARCH_HOME opensearch

# Copy from Stage0
COPY --from=linux_stage_0 --chown=$UID:$GID $OPENSEARCH_HOME $OPENSEARCH_HOME
WORKDIR $OPENSEARCH_HOME

# Set $JAVA_HOME
RUN echo "export JAVA_HOME=$OPENSEARCH_HOME/jdk" >> /etc/profile.d/java_home.sh && \
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile.d/java_home.sh && \
ls -l $OPENSEARCH_HOME

ENV JAVA_HOME=$OPENSEARCH_HOME/jdk
ENV PATH=$PATH:$JAVA_HOME/bin:$OPENSEARCH_HOME/bin

# Add k-NN lib directory to library loading path variable
ENV LD_LIBRARY_PATH="$OPENSEARCH_HOME/plugins/opensearch-knn/lib"

# Disable FIPS approved-only mode to allow standard passwords
ENV OPENSEARCH_JAVA_OPTS="-Dorg.bouncycastle.fips.approved_only=false"

# OpenShift restricted-v2 compatibility: Fix ownership and permissions for random UID
# COPY --chown may not work correctly, so explicitly set ownership and permissions
RUN chown -R $UID:0 $OPENSEARCH_HOME && \
chmod -R g=u $OPENSEARCH_HOME && \
find $OPENSEARCH_HOME -type d -exec chmod g+x {} \; && \
chmod g+x $OPENSEARCH_HOME/opensearch-docker-entrypoint.sh && \
chmod g+x $OPENSEARCH_HOME/opensearch-onetime-setup.sh

# Change user
USER $UID

# Setup OpenSearch
# Disable security demo installation during image build, and allow user to disable during startup of the container
# Enable security plugin during image build, and allow user to disable during startup of the container
ARG DISABLE_INSTALL_DEMO_CONFIG=true
ARG DISABLE_SECURITY_PLUGIN=false
RUN ./opensearch-onetime-setup.sh

# Expose ports for the opensearch service (9200 for HTTP and 9300 for internal transport) and performance analyzer (9600 for the agent and 9650 for the root cause analysis component)
EXPOSE 9200 9300 9600 9650

ARG VERSION
ARG BUILD_DATE
ARG NOTES

# Label
LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="opensearch" \
org.label-schema.version="$VERSION" \
org.label-schema.url="https://opensearch.org" \
org.label-schema.vcs-url="https://github.com/opensearch-project/OpenSearch" \
org.label-schema.license="Apache-2.0" \
org.label-schema.vendor="OpenSearch" \
org.label-schema.description="$NOTES" \
org.label-schema.build-date="$BUILD_DATE"

# CMD to run
ENTRYPOINT ["./opensearch-docker-entrypoint.sh"]
CMD ["opensearch"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
FROM registry.access.redhat.com/ubi9/ubi

# Set working directory
WORKDIR /opensearch-build

# Install system dependencies
RUN yum install -y --allowerasing \
git \
gcc \
gcc-c++ \
gcc-gfortran \
make \
patch \
tar \
unzip \
zip \
which \
curl \
jq \
python3 \
python3-devel \
python3-pip \
bzip2-devel \
zlib-devel \
openssl-devel \
libffi-devel \
xz-devel \
rpm-build \
&& yum clean all

# Install yq v4 (required by assemble scripts)
RUN curl -fsSL "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_ppc64le" \
-o /usr/local/bin/yq && chmod +x /usr/local/bin/yq

# Install JDK 25.0.4 (Red_Hat-25.0.4.0.7-1) pinned so the bundled JDK in the
# final OpenSearch image matches the expected runtime version.
RUN yum install -y \
java-25-openjdk-devel && \
yum clean all

# Set Java environment
ENV JAVA_HOME=/usr/lib/jvm/java-25-openjdk
ENV PATH=$JAVA_HOME/bin:$PATH
ENV GRADLE_USER_HOME=/root/.gradle

# Pre-cache all Gradle distributions used by 3.7.0 components to avoid
# network timeouts during the build (each component's gradlew would otherwise
# download its own distribution at build time).
# Versions needed:
# 9.4.1 - OpenSearch core, ml-commons, neural-search, k-NN, index-management
# 9.5.0 - job-scheduler, security
# 9.2.0 - common-utils
RUN for version in 9.4.1 9.5.0 9.2.0; do \
mkdir -p /root/.gradle/wrapper/dists/gradle-${version}-all && \
curl -fsSL "https://services.gradle.org/distributions/gradle-${version}-all.zip" \
-o /tmp/gradle-${version}-all.zip && \
HASH=$(sha256sum /tmp/gradle-${version}-all.zip | cut -d' ' -f1) && \
DEST="/root/.gradle/wrapper/dists/gradle-${version}-all/${HASH}" && \
mkdir -p "${DEST}" && \
mv /tmp/gradle-${version}-all.zip "${DEST}/gradle-${version}-all.zip" && \
touch "${DEST}/gradle-${version}-all.zip.ok"; \
done

# Install Maven
RUN MAVEN_URL=$(curl -s https://maven.apache.org/download.cgi \
| grep -Eo '["\047].*.bin.tar.gz["\047]' | tr -d "\"'" | uniq | head -n 1) && \
mkdir -p /usr/local/apache-maven && \
curl -s "$MAVEN_URL" | tar xzf - --strip-components=1 -C /usr/local/apache-maven && \
ln -sfn /usr/local/apache-maven/bin/mvn /usr/local/bin/mvn

# Install pipenv (pin setuptools+virtualenv to avoid packaging incompatibility with pipenv 2023.6.12)
RUN python3 -m pip install --upgrade pip && \
python3 -m pip install --ignore-installed \
"setuptools==67.8.0" \
"virtualenv==20.24.5" \
"pipenv==2023.6.12"

# Copy the build repo
COPY . .

# Pre-install Python dependencies
RUN python3 -m pipenv install --deploy --ignore-pipfile

# Set default command
CMD ["/bin/bash"]
Loading
Loading