Skip to content
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

update gen-sdk.sh to generate sdk using docker container #681

Merged
Changes from 12 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
39 changes: 23 additions & 16 deletions hack/python-sdk/gen-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ set -x

repo_root="$(dirname "${BASH_SOURCE}")/../.."

SWAGGER_JAR_URL="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar"
SWAGGER_CODEGEN_JAR="${repo_root}/hack/python-sdk/openapi-generator-cli.jar"
SWAGGER_CODEGEN_CONF="${repo_root}/hack/python-sdk/swagger_config.json"
SDK_OUTPUT_PATH="${repo_root}/sdk/python"
VERSION=0.1.4
Expand All @@ -37,31 +35,40 @@ fi
echo "Generating OpenAPI specification ..."
echo "./hack/update-codegen.sh already help us generate openapi specs ..."

if [[ ! -f "$SWAGGER_CODEGEN_JAR" ]]; then
echo "Downloading the swagger-codegen JAR package ..."
wget -O "${SWAGGER_CODEGEN_JAR}" ${SWAGGER_JAR_URL}
fi

if [ -z `which java` ]; then
apt-get update -y
# TODO: update this fallback (remove it) when openjdk-11 completely deprecated
echo "Installing OpenJDK 11 with fallback to OpenJDK 17"
apt-get install -y openjdk-11-jdk || apt-get install -y openjdk-17-jdk
fi

echo "Generating swagger file ..."
go run "${repo_root}"/hack/swagger/main.go ${VERSION} >"${SWAGGER_CODEGEN_FILE}"

echo "Removing previously generated files ..."
rm -rf "${SDK_OUTPUT_PATH}"/docs/V1*.md "${SDK_OUTPUT_PATH}"/jobset/models "${SDK_OUTPUT_PATH}"/test/test_*.py

echo "Generating Python SDK for JobSet..."
java -jar "${SWAGGER_CODEGEN_JAR}" generate -i ${SWAGGER_CODEGEN_FILE} -g python -o "${SDK_OUTPUT_PATH}" -c "${SWAGGER_CODEGEN_CONF}"

# Defaults the container engine to docker
CONTAINER_ENGINE=${CONTAINER_ENGINE:-docker}
ahg-g marked this conversation as resolved.
Show resolved Hide resolved
USERLEVEL="--user $(id -u):$(id -g)"

# Checking the path of podman, silencing the errors
#which podman &> /dev/null

## Checking the exit status of which command, 0 means that command exit successfully
#if [[ $? -eq 0 ]]; then
# echo "Podman is found, changing over to podman"
# CONTAINER_ENGINE=podman
# USERLEVEL=""
#fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please cleanup this code?


# Install the sdk using docker, using the user that is running the container engine so that files can still be removed
${CONTAINER_ENGINE} run $USERLEVEL --rm \
-v "${repo_root}":/local docker.io/openapitools/openapi-generator-cli generate \
-i /local/"${SWAGGER_CODEGEN_FILE}" \
-g python \
-o /local/"${SDK_OUTPUT_PATH}" \
-c local/"${SWAGGER_CODEGEN_CONF}"

echo "Running post-generation script ..."
"${repo_root}"/hack/python-sdk/post_gen.py

echo "JobSet Python SDK is generated successfully to folder ${SDK_OUTPUT_PATH}/."

# Remove setup.py
rm ${SDK_OUTPUT_PATH}/setup.py
rm "${SDK_OUTPUT_PATH}"/setup.py