diff --git a/.env b/.env new file mode 100644 index 0000000..a3f7f95 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +ES_VERSION=7.17.28 +PLUGIN_VERSION=7.17.28.0 +JAVA_COMPILER_VERSION=17 +GRADLE_VERSION=8.10.2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..12f5395 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/README.md b/README.md index 1bfa814..0f2c7a4 100644 --- a/README.md +++ b/README.md @@ -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 ------------ diff --git a/build.gradle b/build.gradle index 34296fc..19a82d5 100644 --- a/build.gradle +++ b/build.gradle @@ -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' @@ -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 { diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..86323ba --- /dev/null +++ b/build.sh @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index ec4c3f4..9054f8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index 9533fd3..03ea8c6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index afba109..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c40527..df97d72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew index 65dcd68..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -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/. @@ -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 @@ -133,10 +134,13 @@ 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. @@ -144,7 +148,7 @@ 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 @@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | 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 @@ -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" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85..9b42019 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -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 ########################################################################## @@ -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 @@ -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 diff --git a/prepare-version.sh b/prepare-version.sh new file mode 100755 index 0000000..1e2fb5e --- /dev/null +++ b/prepare-version.sh @@ -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