Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ES_VERSION=7.17.28
PLUGIN_VERSION=7.17.28.0
JAVA_COMPILER_VERSION=17
GRADLE_VERSION=8.10.2
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle
run: ./gradlew build
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ Built with Java 17 and Gradle 8.10.2.

The first 3 digits of plugin version is Elasticsearch versioning. The last digit is used for plugin versioning under an elasticsearch version.


Upgrade the plugin
------------

In order to upgrade the plugin, one can simply run for example `./prepare-version.sh 7.17.28`. It will:
- fetch dependencies versions form Elasticsearch internals
- upgrade the configuration files

You can then run `./build.sh` that will build the plugin in a docker container using gradle.
If successful, the plugin will be available in `./build/distributions/` (under the name `pathhierarchy-aggregation-7.17.28.0.zip` in this example).



Development Environment Setup
------------

Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ repositories {
group = 'org.elasticsearch.plugin'
version = "${plugin_version}"

def versions = org.elasticsearch.gradle.VersionProperties.versions

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'elasticsearch.esplugin'
Expand All @@ -35,7 +37,7 @@ esplugin {
dependencies {
implementation "org.elasticsearch:elasticsearch:${es_version}"
yamlRestTestImplementation "org.elasticsearch.test:framework:${es_version}"
yamlRestTestImplementation "org.apache.logging.log4j:log4j-core:2.17.1"
yamlRestTestImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
}

tasks.named("yamlRestTest").configure {
Expand Down
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# helper script that runs the build script inside a gradle based docker container

source .env

echo "GRADLE_VERSION ${GRADLE_VERSION}"

docker run --rm \
-v .:/opt/gen \
-w /opt/gen \
-u gradle \
gradle:${GRADLE_VERSION} ./gradlew build
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
context: .
dockerfile: docker/Dockerfile
target: elasticsearch-plugin-debug
args:
ES_VERSION: ${ES_VERSION}
PLUGIN_VERSION: ${PLUGIN_VERSION}
PLUGIN_FILENAME: pathhierarchy-aggregation-${PLUGIN_VERSION}.zip
environment:
- discovery.type=single-node
# NO DEBUG
Expand Down
14 changes: 11 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
FROM docker.elastic.co/elasticsearch/elasticsearch:7.17.28 AS elasticsearch-plugin-debug
ARG ES_VERSION
ARG PLUGIN_FILENAME

COPY /build/distributions/pathhierarchy-aggregation-7.17.28.0.zip /tmp/pathhierarchy-aggregation-7.17.28.0.zip
RUN ./bin/elasticsearch-plugin install file:/tmp/pathhierarchy-aggregation-7.17.28.0.zip
FROM docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION} AS elasticsearch-plugin-debug

COPY build/distributions/${PLUGIN_FILENAME} /tmp/${PLUGIN_FILENAME}

# mandatory because docker ARG is scoped to stage (forgotten after the FROM scope above...!)
ARG PLUGIN_FILENAME
# madantory because ARGS cannot be used inside RUN shell
ENV PLUGIN_FILENAME=${PLUGIN_FILENAME}
RUN ./bin/elasticsearch-plugin install --batch file:/tmp/${PLUGIN_FILENAME}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
34 changes: 21 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,10 +85,9 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +134,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
38 changes: 38 additions & 0 deletions prepare-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Helper script to prepare a version of the plugin based on a specific elasticsearch version
#
# given the elasticsearch version as argument, it generates the needed configuration file to build the plugin

[ -z "$1" ] && {
echo "1st argument should be the targeted elasticsearch version"
exit 1
}

ES_VERSION="$1"

# retrieve version information from ES repository
GRADLE_VERSION=$(curl -s https://raw.githubusercontent.com/elastic/elasticsearch/refs/tags/v${ES_VERSION}/build-tools-internal/src/main/resources/minimumGradleVersion)
JAVA_COMPILER_VERSION=$(curl -s https://raw.githubusercontent.com/elastic/elasticsearch/refs/tags/v${ES_VERSION}/build-tools-internal/src/main/resources/minimumCompilerVersion)
JAVA_RUNTIME_VERSION=$(curl -s https://raw.githubusercontent.com/elastic/elasticsearch/refs/tags/v${ES_VERSION}/build-tools-internal/src/main/resources/minimumRuntimeVersion)

PLUGIN_VERSION="${ES_VERSION}.0"

echo "GRADLE_VERSION ${GRADLE_VERSION}"
echo "JAVA_COMPILER_VERSION ${JAVA_COMPILER_VERSION}"
echo "ES_VERSION ${ES_VERSION}"
echo "PLUGIN_VERSION ${PLUGIN_VERSION}"

echo "es_version = ${ES_VERSION}
plugin_version = ${PLUGIN_VERSION}" > gradle.properties

echo "ES_VERSION=${ES_VERSION}
PLUGIN_VERSION=${PLUGIN_VERSION}
JAVA_COMPILER_VERSION=${JAVA_COMPILER_VERSION}
GRADLE_VERSION=${GRADLE_VERSION}" > .env

docker run --rm \
-v .:/opt/gen \
-w /opt/gen \
-u gradle \
gradle:"${GRADLE_VERSION}" /usr/bin/gradle wrapper --gradle-version "${GRADLE_VERSION}" --distribution-type bin
Loading