2017-04-28 16:04:37 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Copyright 2015 The Kubernetes Authors.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
# Script to fetch latest swagger spec.
|
|
|
|
|
# Puts the updated spec at api/swagger-spec/
|
|
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
|
set -o nounset
|
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
|
|
# Generates client.
|
|
|
|
|
# Required env vars:
|
|
|
|
|
# CLEANUP_DIRS: List of directories to cleanup before generation for this language
|
2017-08-10 03:49:03 -07:00
|
|
|
# KUBERNETES_BRANCH: Kubernetes branch name to get the swagger spec from
|
|
|
|
|
# CLIENT_VERSION: Client version. Will be used in the comment sections of the generated code
|
|
|
|
|
# PACKAGE_NAME: Name of the client package.
|
|
|
|
|
# CLIENT_LANGUAGE: Language of the client. ${CLIENT_LANGUAGE}.xml should exists.
|
|
|
|
|
# Optional env vars:
|
2019-01-15 07:52:13 +01:00
|
|
|
# OPENAPI_GENERATOR_USER_ORG: openapi-generator-user-org
|
|
|
|
|
# OPENAPI_GENERATOR_COMMIT: openapi-generator-version
|
2017-04-28 16:04:37 -07:00
|
|
|
# Input vars:
|
|
|
|
|
# $1: output directory
|
|
|
|
|
kubeclient::generator::generate_client() {
|
|
|
|
|
: "${CLEANUP_DIRS?Must set CLEANUP_DIRS env var}"
|
|
|
|
|
: "${KUBERNETES_BRANCH?Must set KUBERNETES_BRANCH env var}"
|
|
|
|
|
: "${CLIENT_VERSION?Must set CLIENT_VERSION env var}"
|
|
|
|
|
: "${PACKAGE_NAME?Must set PACKAGE_NAME env var}"
|
|
|
|
|
: "${CLIENT_LANGUAGE?Must set CLIENT_LANGUAGE env var}"
|
|
|
|
|
|
2019-01-15 07:52:13 +01:00
|
|
|
OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG:-OpenAPITools}"
|
|
|
|
|
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v3.3.4}"
|
2020-06-13 19:35:55 -04:00
|
|
|
OPENAPI_MODEL_LENGTH="${OPENAPI_MODEL_LENGTH:-}"
|
2019-07-19 11:59:11 +08:00
|
|
|
OPENAPI_SKIP_FETCH_SPEC="${OPENAPI_SKIP_FETCH_SPEC:-}"
|
2020-06-30 14:13:58 +08:00
|
|
|
OPENAPI_SKIP_BASE_INTERFACE="${OPENAPI_SKIP_BASE_INTERFACE:-}"
|
2020-06-13 19:35:55 -04:00
|
|
|
KUBERNETES_CRD_MODE="${KUBERNETES_CRD_MODE:-}"
|
|
|
|
|
KUBERNETES_CRD_GROUP_PREFIX="${KUBERNETES_CRD_GROUP_PREFIX:-}"
|
2020-12-03 12:49:01 -05:00
|
|
|
GENERATE_APIS="${GENERATE_APIS:-true}"
|
2021-02-26 17:40:17 +01:00
|
|
|
HIDE_GENERATION_TIMESTAMP="${HIDE_GENERATION_TIMESTAMP:-false}"
|
2018-05-03 07:10:16 +02:00
|
|
|
USERNAME="${USERNAME:-kubernetes}"
|
2018-06-25 07:30:35 -07:00
|
|
|
REPOSITORY="${REPOSITORY:-kubernetes}"
|
2017-08-10 03:49:03 -07:00
|
|
|
|
2017-04-28 16:04:37 -07:00
|
|
|
local output_dir=$1
|
|
|
|
|
pushd "${output_dir}" > /dev/null
|
|
|
|
|
local output_dir=`pwd`
|
|
|
|
|
popd > /dev/null
|
2019-01-15 07:52:13 +01:00
|
|
|
local SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
2017-04-28 16:04:37 -07:00
|
|
|
pushd "${SCRIPT_ROOT}" > /dev/null
|
|
|
|
|
local SCRIPT_ROOT=`pwd`
|
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
|
|
mkdir -p "${output_dir}"
|
|
|
|
|
|
2018-05-03 07:10:16 +02:00
|
|
|
if [ "${USERNAME}" != "kubernetes" ]; then
|
2019-01-15 07:52:13 +01:00
|
|
|
image_name="${USERNAME}-${REPOSITORY}-${CLIENT_LANGUAGE}-client-gen-with-openapi-generator:v1"
|
2018-05-03 07:10:16 +02:00
|
|
|
else
|
2019-01-15 07:52:13 +01:00
|
|
|
image_name="${REPOSITORY}-${CLIENT_LANGUAGE}-client-gen-with-openapi-generator:v1"
|
2018-05-03 07:10:16 +02:00
|
|
|
fi
|
2019-01-15 07:52:13 +01:00
|
|
|
|
|
|
|
|
echo "--- Building docker image ${image_name}..."
|
|
|
|
|
docker build "${SCRIPT_ROOT}"/../ -f "${SCRIPT_ROOT}/Dockerfile" -t "${image_name}" \
|
|
|
|
|
--build-arg OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG}" \
|
|
|
|
|
--build-arg OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT}" \
|
2017-08-10 03:49:03 -07:00
|
|
|
--build-arg GENERATION_XML_FILE="${CLIENT_LANGUAGE}.xml"
|
2017-04-28 16:04:37 -07:00
|
|
|
|
2017-08-10 17:26:32 -07:00
|
|
|
# Docker does not support passing arrays, pass the string representation
|
|
|
|
|
# of the array instead (space separated)
|
|
|
|
|
CLEANUP_DIRS_STRING="${CLEANUP_DIRS[@]}"
|
|
|
|
|
|
2017-08-10 03:49:03 -07:00
|
|
|
echo "--- Running generator inside container..."
|
2020-03-05 15:50:49 -08:00
|
|
|
docker run --security-opt="label=disable" -u $(id -u) \
|
2017-08-10 17:26:32 -07:00
|
|
|
-e CLEANUP_DIRS="${CLEANUP_DIRS_STRING}" \
|
2017-08-15 10:45:50 -07:00
|
|
|
-e KUBERNETES_BRANCH="${KUBERNETES_BRANCH}" \
|
|
|
|
|
-e CLIENT_VERSION="${CLIENT_VERSION}" \
|
2017-10-31 14:59:19 -04:00
|
|
|
-e CLIENT_LANGUAGE="${CLIENT_LANGUAGE}" \
|
2017-08-15 10:45:50 -07:00
|
|
|
-e PACKAGE_NAME="${PACKAGE_NAME}" \
|
2019-01-15 07:52:13 +01:00
|
|
|
-e OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG}" \
|
|
|
|
|
-e OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT}" \
|
2020-06-13 19:35:55 -04:00
|
|
|
-e OPENAPI_MODEL_LENGTH="${OPENAPI_MODEL_LENGTH}" \
|
2019-07-19 11:59:11 +08:00
|
|
|
-e OPENAPI_SKIP_FETCH_SPEC="${OPENAPI_SKIP_FETCH_SPEC}" \
|
2020-06-13 19:35:55 -04:00
|
|
|
-e KUBERNETES_CRD_MODE="${KUBERNETES_CRD_MODE}" \
|
|
|
|
|
-e KUBERNETES_CRD_GROUP_PREFIX="${KUBERNETES_CRD_GROUP_PREFIX}" \
|
2020-12-03 12:49:01 -05:00
|
|
|
-e GENERATE_APIS="${GENERATE_APIS}" \
|
2020-06-30 14:13:58 +08:00
|
|
|
-e OPENAPI_SKIP_BASE_INTERFACE="${OPENAPI_SKIP_BASE_INTERFACE}" \
|
2021-02-26 17:40:17 +01:00
|
|
|
-e HIDE_GENERATION_TIMESTAMP="${HIDE_GENERATION_TIMESTAMP}" \
|
|
|
|
|
-e LIBRARY="${LIBRARY}" \
|
2018-05-03 07:10:16 +02:00
|
|
|
-e USERNAME="${USERNAME}" \
|
2018-06-25 07:30:35 -07:00
|
|
|
-e REPOSITORY="${REPOSITORY}" \
|
2017-08-10 03:49:03 -07:00
|
|
|
-v "${output_dir}:/output_dir" \
|
2018-05-03 07:10:16 +02:00
|
|
|
"${image_name}" "/output_dir"
|
2017-04-28 16:04:37 -07:00
|
|
|
|
|
|
|
|
echo "---Done."
|
2017-05-10 10:41:40 -07:00
|
|
|
}
|