Skip to content

Commit a8b7dc4

Browse files
JoshMockgithub-actions[bot]
authored andcommitted
Update codegen task to be runnable via CI (#1944)
(cherry picked from commit 6fef22d)
1 parent a8ae21f commit a8b7dc4

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

.ci/Dockerfile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
ARG NODE_JS_VERSION=18
22
FROM node:${NODE_JS_VERSION}
33

4-
# Create app directory
5-
WORKDIR /usr/src/app
4+
ARG BUILDER_UID=1000
5+
ARG BUILDER_GID=1000
6+
ENV BUILDER_USER elastic
7+
ENV BUILDER_GROUP elastic
68

7-
RUN apt-get clean -y
8-
RUN apt-get update -y
9-
RUN apt-get install -y zip
9+
# install zip util
10+
RUN apt-get clean -y && \
11+
apt-get update -y && \
12+
apt-get install -y zip
13+
14+
# Set user permissions and directory
15+
RUN groupadd --system -g ${BUILDER_GID} ${BUILDER_GROUP} \
16+
&& useradd --system --shell /bin/bash -u ${BUILDER_UID} -g ${BUILDER_GROUP} -m elastic 1>/dev/null 2>/dev/null \
17+
&& mkdir -p /usr/src/elasticsearch-js \
18+
&& chown -R ${BUILDER_USER}:${BUILDER_GROUP} /usr/src/
19+
WORKDIR /usr/src/elasticsearch-js
20+
USER ${BUILDER_USER}:${BUILDER_GROUP}
1021

1122
# Install app dependencies
12-
COPY package*.json ./
23+
COPY --chown=$BUILDER_USER:$BUILDER_GROUP package*.json ./
1324
RUN npm install
1425

15-
COPY . .
26+
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .

.ci/make.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# assemble <VERSION> : build client artifacts with version
1313
# bump <VERSION> : bump client internals to version
1414
# bumpmatrix <VERSION> : bump stack version in test matrix to version
15-
# codegen : generate endpoints
15+
# codegen <VERSION> : generate endpoints
1616
# docsgen <VERSION> : generate documentation
1717
# examplegen : generate the doc examples
1818
# clean : clean workspace
@@ -24,7 +24,6 @@
2424
# ------------------------------------------------------- #
2525
script_path=$(dirname "$(realpath -s "$0")")
2626
repo=$(realpath "$script_path/../")
27-
generator=$(realpath "$script_path/../../elastic-client-generator-js")
2827

2928
# shellcheck disable=SC1090
3029
CMD=$1
@@ -38,7 +37,6 @@ product="elastic/elasticsearch-js"
3837
output_folder=".ci/output"
3938
codegen_folder=".ci/output"
4039
OUTPUT_DIR="$repo/${output_folder}"
41-
# REPO_BINDING="${OUTPUT_DIR}:/sln/${output_folder}"
4240
NODE_JS_VERSION=18
4341
WORKFLOW=${WORKFLOW-staging}
4442
mkdir -p "$OUTPUT_DIR"
@@ -59,18 +57,29 @@ case $CMD in
5957
echo -e "\033[31;1mTARGET: assemble -> missing version parameter\033[0m"
6058
exit 1
6159
fi
62-
echo -e "\033[36;1mTARGET: assemble artefact $VERSION\033[0m"
60+
echo -e "\033[36;1mTARGET: assemble artifact $VERSION\033[0m"
6361
TASK=release
6462
TASK_ARGS=("$VERSION" "$output_folder")
6563
;;
6664
codegen)
67-
if [ -v $VERSION ]; then
68-
echo -e "\033[31;1mTARGET: codegen -> missing version parameter\033[0m"
69-
exit 1
65+
if [ -v "$VERSION" ] || [[ -z "$VERSION" ]]; then
66+
# fall back to branch name or `main` if no VERSION is set
67+
branch_name=$(git rev-parse --abbrev-ref HEAD)
68+
if [[ "$branch_name" =~ ^\d+\.\d+ ]]; then
69+
echo -e "\033[36;1mTARGET: codegen -> No VERSION found, using branch name: \`$VERSION\`\033[0m"
70+
VERSION="$branch_name"
71+
else
72+
echo -e "\033[36;1mTARGET: codegen -> No VERSION found, using \`main\`\033[0m"
73+
VERSION="main"
74+
fi
7075
fi
71-
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
76+
if [ "$VERSION" = 'main' ]; then
77+
echo -e "\033[36;1mTARGET: codegen API $VERSION\033[0m"
78+
else
79+
echo -e "\033[36;1mTARGET: codegen API v$VERSION\033[0m"
80+
fi
81+
7282
TASK=codegen
73-
# VERSION is BRANCH here for now
7483
TASK_ARGS=("$VERSION")
7584
;;
7685
docsgen)
@@ -80,13 +89,11 @@ case $CMD in
8089
fi
8190
echo -e "\033[36;1mTARGET: generate docs for $VERSION\033[0m"
8291
TASK=codegen
83-
# VERSION is BRANCH here for now
8492
TASK_ARGS=("$VERSION" "$codegen_folder")
8593
;;
8694
examplesgen)
8795
echo -e "\033[36;1mTARGET: generate examples\033[0m"
8896
TASK=codegen
89-
# VERSION is BRANCH here for now
9097
TASK_ARGS=("$VERSION" "$codegen_folder")
9198
;;
9299
bump)
@@ -96,7 +103,6 @@ case $CMD in
96103
fi
97104
echo -e "\033[36;1mTARGET: bump to version $VERSION\033[0m"
98105
TASK=bump
99-
# VERSION is BRANCH here for now
100106
TASK_ARGS=("$VERSION")
101107
;;
102108
bumpmatrix)
@@ -128,6 +134,8 @@ docker build \
128134
--file .ci/Dockerfile \
129135
--tag "$product" \
130136
--build-arg NODE_JS_VERSION="$NODE_JS_VERSION" \
137+
--build-arg "BUILDER_UID=$(id -u)" \
138+
--build-arg "BUILDER_GID=$(id -g)" \
131139
.
132140

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

139147
docker run \
140-
--volume "$repo:/usr/src/app" \
141-
--volume "$generator:/usr/src/elastic-client-generator-js" \
142-
--volume /usr/src/app/node_modules \
148+
--volume "$repo:/usr/src/elasticsearch-js" \
149+
--volume /usr/src/elasticsearch-js/node_modules \
143150
-u "$(id -u):$(id -g)" \
144151
--env "WORKFLOW=$WORKFLOW" \
145152
--name make-elasticsearch-js \
146153
--rm \
147154
$product \
148-
node .ci/make.mjs --task $TASK ${TASK_ARGS[*]}
155+
/bin/bash -c "cd /usr/src && \
156+
git clone https://$CLIENTS_GITHUB_TOKEN@github.com/elastic/elastic-client-generator-js.git && \
157+
mkdir -p /usr/src/elastic-client-generator-js/output && \
158+
cd /usr/src/elasticsearch-js && \
159+
node .ci/make.mjs --task $TASK ${TASK_ARGS[*]}"
149160

150161
# ------------------------------------------------------- #
151162
# Post Command tasks & checks

0 commit comments

Comments
 (0)