Skip to content

[7.17] Add support for bumping, WORKFLOW, and user/group IDs to make.sh #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2022
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
32 changes: 24 additions & 8 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,36 @@

FROM openjdk:15

# Default UID/GID to 1000
# it can be overridden at build time
ARG BUILDER_UID=1000
ARG BUILDER_GID=1000

# Create group and user if needed
RUN (getent group ${BUILDER_GID} || groupadd -g ${BUILDER_GID} elastic) \
&& (getent passwd ${BUILDER_UID} || useradd -u ${BUILDER_UID} -g ${BUILDER_GID} elastic) \
&& mkdir -p /elasticsearch-java/build \
&& chown -R ${BUILDER_UID}:${BUILDER_GID} /elasticsearch-java

WORKDIR /elasticsearch-java/
USER ${BUILDER_UID}:${BUILDER_GID}

# Download and initialize Gradle
COPY gradlew ./
COPY gradle ./gradle
COPY --chown=$BUILDER_UID:$BUILDER_GID gradlew ./
COPY --chown=$BUILDER_UID:$BUILDER_GID gradle ./gradle
RUN ./gradlew

COPY LICENSE.txt NOTICE.txt ./
COPY --chown=$BUILDER_UID:$BUILDER_GID LICENSE.txt NOTICE.txt ./

# Prefetch dependencies
COPY build.gradle.kts settings.gradle.kts ./
COPY buildSrc ./buildSrc/
COPY config ./config/
COPY java-client/build.gradle.kts ./java-client/
# Prefetch and cache dependencies
COPY --chown=$BUILDER_UID:$BUILDER_GID build.gradle.kts settings.gradle.kts ./
COPY --chown=$BUILDER_UID:$BUILDER_GID buildSrc ./buildSrc/
COPY --chown=$BUILDER_UID:$BUILDER_GID config ./config/
COPY --chown=$BUILDER_UID:$BUILDER_GID java-client/build.gradle.kts ./java-client/
RUN ./gradlew resolveDependencies

# Build artifacts. Expects these mounted directories:
# /elasticsearch-java/.git - git index (read-only)
# /elasticsearch-java/java-client/src - source files (read-only)
# /elasticsearch-java/build - output directory (read-write)
ENTRYPOINT ["./gradlew"]
25 changes: 18 additions & 7 deletions .ci/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ product="elastic/elasticsearch-java"
output_folder=".ci/output"
codegen_folder=".ci/output"
OUTPUT_DIR="$repo/${output_folder}"
WORKFLOW="${WORKFLOW-staging}"
mkdir -p "$OUTPUT_DIR"

echo -e "\033[34;1mINFO:\033[0m PRODUCT ${product}\033[0m"
Expand Down Expand Up @@ -110,7 +111,7 @@ case $CMD in
TASK_ARGS=("$VERSION" "$codegen_folder")
;;
bump)
if [ -v $VERSION ]; then
if [ -z "$VERSION" ]; then
echo -e "\033[31;1mTARGET: bump -> missing version parameter\033[0m"
exit 1
fi
Expand All @@ -137,9 +138,11 @@ output_mount="-v $repo/.ci/output:/elasticsearch-java/build"
build_image() {
echo -e "\033[34;1mINFO: building $product container\033[0m"

docker build --file .ci/Dockerfile --tag $docker_image \
--build-arg USER_ID="$(id -u)" \
--build-arg GROUP_ID="$(id -g)" .
docker build \
--file .ci/Dockerfile \
--tag $docker_image \
--build-arg BUILDER_UID="$(id -u)" \
--build-arg BUILDER_GID="$(id -g)" .
}

# ------------------------------------------------------- #
Expand All @@ -148,8 +151,16 @@ build_image() {

if [[ "$CMD" == "assemble" ]]; then
rm -rf .ci/output/repository

if [[ "$WORKFLOW" == 'snapshot' ]]; then
assemble_version="$VERSION-SNAPSHOT"
else
assemble_version="$VERSION"
fi

build_image
docker run --rm --env VERSION=$VERSION \
echo -e "\033[34;1mINFO:\033[0m Building version ${assemble_version}\033[0m"
docker run --rm --env VERSION=$assemble_version -u "$(id -u)" \
$git_mount $src_mount $output_mount \
$docker_image \
publishForReleaseManager
Expand All @@ -158,15 +169,15 @@ if [[ "$CMD" == "assemble" ]]; then
if [[ -n ${DEPENDENCIES_REPORTS_DIR+x} ]]; then
cp .ci/output/release/dependencies.csv "$DEPENDENCIES_REPORTS_DIR"/"$DEPENDENCIES_REPORT"
fi
echo -e "\033[32;1mTARGET: successfully assembled client version $VERSION\033[0m"
echo -e "\033[32;1mTARGET: successfully assembled client version $assemble_version\033[0m"
else
echo -e "\033[31;1mTARGET: assemble failed, empty workspace!\033[0m"
exit 1
fi
fi

if [[ "$CMD" == "bump" ]]; then
echo "TODO"
echo $VERSION > config/version.txt
fi

if [[ "$CMD" == "codegen" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion config/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.17
7.17.7