Skip to content

Update codegen task to be runnable via CI #1944

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 7 commits into from
Jul 17, 2023
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
25 changes: 18 additions & 7 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
ARG NODE_JS_VERSION=18
FROM node:${NODE_JS_VERSION}

# Create app directory
WORKDIR /usr/src/app
ARG BUILDER_UID=1000
ARG BUILDER_GID=1000
ENV BUILDER_USER elastic
ENV BUILDER_GROUP elastic

RUN apt-get clean -y
RUN apt-get update -y
RUN apt-get install -y zip
# install zip util
RUN apt-get clean -y && \
apt-get update -y && \
apt-get install -y zip

# Set user permissions and directory
RUN groupadd --system -g ${BUILDER_GID} ${BUILDER_GROUP} \
&& useradd --system --shell /bin/bash -u ${BUILDER_UID} -g ${BUILDER_GROUP} -m elastic 1>/dev/null 2>/dev/null \
&& mkdir -p /usr/src/elasticsearch-js \
&& chown -R ${BUILDER_USER}:${BUILDER_GROUP} /usr/src/
WORKDIR /usr/src/elasticsearch-js
USER ${BUILDER_USER}:${BUILDER_GROUP}

# Install app dependencies
COPY package*.json ./
COPY --chown=$BUILDER_USER:$BUILDER_GROUP package*.json ./
RUN npm install

COPY . .
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
43 changes: 27 additions & 16 deletions .ci/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# assemble <VERSION> : build client artifacts with version
# bump <VERSION> : bump client internals to version
# bumpmatrix <VERSION> : bump stack version in test matrix to version
# codegen : generate endpoints
# codegen <VERSION> : generate endpoints
# docsgen <VERSION> : generate documentation
# examplegen : generate the doc examples
# clean : clean workspace
Expand All @@ -24,7 +24,6 @@
# ------------------------------------------------------- #
script_path=$(dirname "$(realpath -s "$0")")
repo=$(realpath "$script_path/../")
generator=$(realpath "$script_path/../../elastic-client-generator-js")

# shellcheck disable=SC1090
CMD=$1
Expand All @@ -38,7 +37,6 @@ product="elastic/elasticsearch-js"
output_folder=".ci/output"
codegen_folder=".ci/output"
OUTPUT_DIR="$repo/${output_folder}"
# REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}"
NODE_JS_VERSION=18
WORKFLOW=${WORKFLOW-staging}
mkdir -p "$OUTPUT_DIR"
Expand All @@ -59,18 +57,29 @@ case $CMD in
echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m"
exit 1
fi
echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m"
echo -e "\033[36;1mTARGET: assemble artifact $VERSION\033[0m"
TASK=release
TASK_ARGS=("$VERSION" "$output_folder")
;;
codegen)
if [ -v $VERSION ]; then
echo -e "\033[31;1mTARGET: codegen -> missing version parameter\033[0m"
exit 1
if [ -v "$VERSION" ] || [[ -z "$VERSION" ]]; then
# fall back to branch name or `main` if no VERSION is set
branch_name=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch_name" =~ ^\d+\.\d+ ]]; then
echo -e "\033[36;1mTARGET: codegen -> No VERSION found, using branch name: \`$VERSION\`\033[0m"
VERSION="$branch_name"
else
echo -e "\033[36;1mTARGET: codegen -> No VERSION found, using \`main\`\033[0m"
VERSION="main"
fi
fi
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
if [ "$VERSION" = 'main' ]; then
echo -e "\033[36;1mTARGET: codegen API $VERSION\033[0m"
else
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
fi

TASK=codegen
# VERSION is BRANCH here for now
TASK_ARGS=("$VERSION")
;;
docsgen)
Expand All @@ -80,13 +89,11 @@ case $CMD in
fi
echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m"
TASK=codegen
# VERSION is BRANCH here for now
TASK_ARGS=("$VERSION" "$codegen_folder")
;;
examplesgen)
echo -e "\033[36;1mTARGET: generate examples\033[0m"
TASK=codegen
# VERSION is BRANCH here for now
TASK_ARGS=("$VERSION" "$codegen_folder")
;;
bump)
Expand All @@ -96,7 +103,6 @@ case $CMD in
fi
echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m"
TASK=bump
# VERSION is BRANCH here for now
TASK_ARGS=("$VERSION")
;;
bumpmatrix)
Expand Down Expand Up @@ -128,6 +134,8 @@ docker build \
--file .ci/Dockerfile \
--tag "$product" \
--build-arg NODE_JS_VERSION="$NODE_JS_VERSION" \
--build-arg "BUILDER_UID=$(id -u)" \
--build-arg "BUILDER_GID=$(id -g)" \
.

# ------------------------------------------------------- #
Expand All @@ -137,15 +145,18 @@ docker build \
echo -e "\033[34;1mINFO: running $product container\033[0m"

docker run \
--volume "$repo:/usr/src/app" \
--volume "$generator:/usr/src/elastic-client-generator-js" \
--volume /usr/src/app/node_modules \
--volume "$repo:/usr/src/elasticsearch-js" \
--volume /usr/src/elasticsearch-js/node_modules \
-u "$(id -u):$(id -g)" \
--env "WORKFLOW=$WORKFLOW" \
--name make-elasticsearch-js \
--rm \
$product \
node .ci/make.mjs --task $TASK ${TASK_ARGS[*]}
/bin/bash -c "cd /usr/src && \
git clone https://[email protected]/elastic/elastic-client-generator-js.git && \
mkdir -p /usr/src/elastic-client-generator-js/output && \
cd /usr/src/elasticsearch-js && \
node .ci/make.mjs --task $TASK ${TASK_ARGS[*]}"

# ------------------------------------------------------- #
# Post Command tasks & checks
Expand Down