forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the dockerfile into two files, a Dockerfile and a shell script …
…to make the image lightweight
- Loading branch information
Showing
3 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Use the official Ubuntu Noble image as the base image | ||
FROM ubuntu:noble | ||
|
||
# Set environment variables for non-interactive installation | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# Update the package list and install necessary tools | ||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install curl gnupg2 -y \ | ||
&& curl -o- https://www.aptly.info/pubkey.txt | apt-key add - \ | ||
&& echo "deb http://repo.aptly.info/ squeeze main" | tee -a /etc/apt/sources.list.d/aptly.list \ | ||
&& apt-get install -y \ | ||
wget \ | ||
unzip \ | ||
git \ | ||
build-essential \ | ||
debmake \ | ||
debhelper-compat \ | ||
libxrender1 \ | ||
libxtst6 \ | ||
libxi6 \ | ||
libatk1.0-0 \ | ||
libatk-bridge2.0-0 \ | ||
libcups2 \ | ||
libdrm2 \ | ||
libatspi2.0-dev \ | ||
libxcomposite-dev \ | ||
libxdamage1 \ | ||
libxfixes3 \ | ||
libxfixes-dev \ | ||
libxrandr2 \ | ||
libgbm-dev \ | ||
libxkbcommon-x11-0 \ | ||
libpangocairo-1.0-0 \ | ||
libcairo2 \ | ||
libcairo2-dev \ | ||
libnss3 \ | ||
libnspr4 \ | ||
libnspr4-dev \ | ||
aptly \ | ||
cpio \ | ||
rpm \ | ||
rpm2cpio \ | ||
maven \ | ||
&& dpkg -r lintian \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install OpenJDK 21 | ||
RUN wget -O- https://download.java.net/openjdk/jdk21/ri/openjdk-21+35_linux-x64_bin.tar.gz | tar xz -C /opt/ | ||
|
||
# Set JAVA_HOME environment variable | ||
ENV JAVA_HOME=/opt/jdk-21 | ||
ENV PATH=$JAVA_HOME/bin:$PATH | ||
ENV GRADLE_VERSION=8.10 | ||
ENV GRADLE_OPTS="-Xmx8096m -XX:ReservedCodeCacheSize=440m" | ||
|
||
RUN wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -P /tmp \ | ||
&& unzip -d /opt/gradle /tmp/gradle-${GRADLE_VERSION}-bin.zip \ | ||
&& rm /tmp/gradle-${GRADLE_VERSION}-bin.zip | ||
|
||
# Set GRADLE_HOME environment variable | ||
ENV GRADLE_HOME=/opt/gradle/gradle-${GRADLE_VERSION} | ||
ENV PATH=$GRADLE_HOME/bin/$PATH | ||
|
||
# Clean up APT when done | ||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
# Create volume dir | ||
RUN mkdir -p /artifacts/dist/ | ||
VOLUME /artifacts/dist/ | ||
|
||
# Create a non-root user and set up permissions | ||
RUN useradd -ms /bin/bash indexer && mkdir -p /home/indexer && chown -R indexer:indexer /home/indexer | ||
|
||
# Copy your build scripts into the container as root | ||
ADD build.sh /home/indexer/ | ||
|
||
# Change file permissions as root | ||
RUN chmod +x /home/indexer/build.sh | ||
|
||
# Switch to non-root user | ||
USER indexer | ||
|
||
# Set the working directory | ||
WORKDIR /home/indexer | ||
|
||
# Entry point to the build script | ||
ENTRYPOINT ["./build.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
# Exit immediately if a command exits with a non-zero status. | ||
set -e | ||
|
||
# Print commands and their arguments as they are executed. | ||
set -x | ||
|
||
# Set default values for environment variables | ||
INDEXER_BRANCH=${INDEXER_BRANCH:-master} | ||
INDEXER_PLUGINS_BRANCH=${INDEXER_PLUGINS_BRANCH:-master} | ||
INDEXER_REPORTING_BRANCH=${INDEXER_REPORTING_BRANCH:-master} | ||
REVISION=${REVISION:-0} | ||
IS_STAGE=${IS_STAGE:-false} | ||
DISTRIBUTION=${DISTRIBUTION:-tar} | ||
ARCHITECTURE=${ARCHITECTURE:-x64} | ||
|
||
# Clone the repositories | ||
git clone --branch "$INDEXER_BRANCH" https://github.com/wazuh/wazuh-indexer --depth 1 /home/indexer/wazuh-indexer | ||
git clone --branch "$INDEXER_PLUGINS_BRANCH" https://github.com/wazuh/wazuh-indexer-plugins --depth 1 /home/indexer/wazuh-indexer-plugins | ||
git clone --branch "$INDEXER_REPORTING_BRANCH" https://github.com/wazuh/wazuh-indexer-reporting --depth 1 /home/indexer/wazuh-indexer-reporting | ||
|
||
# Set version env var | ||
VERSION=$(cat /home/indexer/wazuh-indexer/VERSION) | ||
|
||
# Build plugins | ||
cd /home/indexer/wazuh-indexer-plugins/plugins/setup && ./gradlew build -Dversion="$VERSION" -Drevision="$REVISION" --no-daemon | ||
cd /home/indexer/wazuh-indexer-plugins/plugins/command-manager && ./gradlew build -Dversion="$VERSION" -Drevision="$REVISION" --no-daemon | ||
|
||
# Build reporting | ||
cd /home/indexer/wazuh-indexer-reporting && ./gradlew build -Dversion="$VERSION" -Drevision="$REVISION" --no-daemon | ||
|
||
# Copy builds | ||
mkdir -p /home/indexer/wazuh-indexer/artifacts/plugins | ||
cp /home/indexer/wazuh-indexer-plugins/plugins/setup/build/distributions/wazuh-indexer-setup-"$VERSION"."$REVISION".zip /home/indexer/wazuh-indexer/artifacts/plugins | ||
cp /home/indexer/wazuh-indexer-plugins/plugins/command-manager/build/distributions/wazuh-indexer-command-manager-"$VERSION"."$REVISION".zip /home/indexer/wazuh-indexer/artifacts/plugins | ||
cp /home/indexer/wazuh-indexer-reporting/build/distributions/wazuh-indexer-reports-scheduler-"$VERSION"."$REVISION".zip /home/indexer/wazuh-indexer/artifacts/plugins | ||
|
||
# Combined RUN command for packaging | ||
PLUGINS_HASH=$(cd /home/indexer/wazuh-indexer-plugins && git rev-parse --short HEAD) | ||
REPORTING_HASH=$(cd /home/indexer/wazuh-indexer-reporting && git rev-parse --short HEAD) | ||
cd /home/indexer/wazuh-indexer | ||
|
||
PACKAGE_MIN_NAME=$(bash build-scripts/baptizer.sh -m \ | ||
-a "$ARCHITECTURE" \ | ||
-d "$DISTRIBUTION" \ | ||
-r "$REVISION" \ | ||
-l "$PLUGINS_HASH" \ | ||
-e "$REPORTING_HASH" \ | ||
"$(if [ "$IS_STAGE" = "true" ]; then echo "-x"; fi)") | ||
|
||
PACKAGE_NAME=$(bash build-scripts/baptizer.sh \ | ||
-a "$ARCHITECTURE" \ | ||
-d "$DISTRIBUTION" \ | ||
-r "$REVISION" \ | ||
-l "$PLUGINS_HASH" \ | ||
-e "$REPORTING_HASH" \ | ||
"$(if [ "$IS_STAGE" = "true" ]; then echo "-x"; fi)") | ||
|
||
bash build-scripts/build.sh \ | ||
-a "$ARCHITECTURE" \ | ||
-d "$DISTRIBUTION" \ | ||
-n "$PACKAGE_MIN_NAME" | ||
|
||
bash build-scripts/assemble.sh \ | ||
-a "$ARCHITECTURE" \ | ||
-d "$DISTRIBUTION" \ | ||
-r "$REVISION" | ||
|
||
mkdir -p /artifacts/dist/ | ||
ls -ll /home/indexer/wazuh-indexer/artifacts/ | ||
ls -ll /home/indexer/wazuh-indexer/artifacts/dist/ | ||
mv /home/indexer/wazuh-indexer/artifacts/dist/"$PACKAGE_NAME" /artifacts/dist/ | ||
|
||
echo "Build and packaging process completed successfully!" |