Merge pull request #28 from krabhishek8260/dockerizeautorest

Adds autorest to the common Dockerfile
This commit is contained in:
Mehdy Bohlool
2017-10-24 11:30:12 -07:00
committed by GitHub
5 changed files with 21 additions and 100 deletions

View File

@@ -32,6 +32,15 @@ RUN cd /source/swagger-codegen && \
mvn install -DskipTests -Dmaven.test.skip=true -pl modules/swagger-codegen-maven-plugin -am && \ mvn install -DskipTests -Dmaven.test.skip=true -pl modules/swagger-codegen-maven-plugin -am && \
cp -r /root/.m2/* /usr/share/maven/ref cp -r /root/.m2/* /usr/share/maven/ref
# Install Autorest
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update && apt-get -y install \
nodejs \
libunwind8-dev \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g autorest@preview #TODO-krabhishek8260: Remove preview as soon as the required bits are in release version
# Copy required files # Copy required files
COPY ${GENERATION_XML_FILE} /generation_params.xml COPY ${GENERATION_XML_FILE} /generation_params.xml
COPY generate_client_in_container.sh /generate_client.sh COPY generate_client_in_container.sh /generate_client.sh

View File

@@ -1,16 +0,0 @@
FROM node
RUN npm install -g autorest
ARG SWAGGER_CODEGEN_COMMIT
ARG GENERATION_XML_FILE
ARG SWAGGER_CODEGEN_USER_ORG
RUN apt-get update && apt-get -y install python-pip && pip install urllib3
RUN apt-get install libunwind8
COPY generate_client_in_container.csharp.sh /generate_client.sh
COPY preprocess_spec.py /
COPY custom_objects_spec.json /
ENTRYPOINT ["/generate_client.sh"]

View File

@@ -52,14 +52,8 @@ kubeclient::generator::generate_client() {
mkdir -p "${output_dir}" mkdir -p "${output_dir}"
local docker_file="${SCRIPT_ROOT}/Dockerfile"
if [ -e "${SCRIPT_ROOT}/Dockerfile.${CLIENT_LANGUAGE}" ];then
docker_file="${SCRIPT_ROOT}/Dockerfile.${CLIENT_LANGUAGE}"
fi
echo "--- Building docker image..." echo "--- Building docker image..."
docker build -f $docker_file "${SCRIPT_ROOT}" -t "kubernetes-${CLIENT_LANGUAGE}-client-gen:v1" \ docker build "${SCRIPT_ROOT}" -t "kubernetes-${CLIENT_LANGUAGE}-client-gen:v1" \
--build-arg SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT}" \ --build-arg SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT}" \
--build-arg GENERATION_XML_FILE="${CLIENT_LANGUAGE}.xml" --build-arg GENERATION_XML_FILE="${CLIENT_LANGUAGE}.xml"

View File

@@ -31,18 +31,17 @@
<configuration> <configuration>
<executable>autorest</executable> <executable>autorest</executable>
<arguments> <arguments>
<argument>-Input</argument> <argument>--input-file=${generator.spec.path}</argument>
<argument>${generator.spec.path}</argument> <argument>--csharp</argument>
<argument>-CodeGenerator</argument> <argument>--namespace=${generator.package.name}</argument>
<argument>CSharp</argument> <argument>--package-version=${generator.client.version}</argument>
<argument>-Namespace</argument> <argument>--output-folder=${generator.output.path}</argument>
<argument>${generator.package.name}</argument> <argument>--version=preview</argument>
<argument>-PackageVersion</argument> <argument>--add-credentials</argument>
<argument>${generator.client.version}</argument> <argument>--debug</argument>
<argument>-OutputDirectory</argument> <argument>--verbose</argument>
<argument>${generator.output.path}</argument> <argument>--directive={from: "swagger-document", where: "$..*[?(@.consumes[0] === \"*/*\")]", transform: "$.consumes[0] = \"application/json\""}</argument>
<argument>-AddCredentials</argument> <argument>--use=@microsoft.azure/autorest.csharp@preview</argument>
<argument>true</argument>
</arguments> </arguments>
</configuration> </configuration>
</plugin> </plugin>

View File

@@ -1,65 +0,0 @@
#!/bin/bash
# Copyright 2017 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 (string separated by space) to cleanup before generation for this language
# 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.
# Input vars:
# $1: output directory
: "${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}"
output_dir=$1
pushd "${output_dir}" > /dev/null
output_dir=`pwd`
popd > /dev/null
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
pushd "${SCRIPT_ROOT}" > /dev/null
SCRIPT_ROOT=`pwd`
popd > /dev/null
mkdir -p "${output_dir}"
echo "--- Downloading and pre-processing OpenAPI spec"
python "${SCRIPT_ROOT}/preprocess_spec.py" "${KUBERNETES_BRANCH}" "${output_dir}/swagger.json"
echo "--- Cleaning up previously generated folders"
for i in ${CLEANUP_DIRS}; do
echo "--- Cleaning up ${output_dir}/${i}"
rm -rf "${output_dir}/${i}"
done
echo "--- Generating client ..."
# TODO new wayautorest --input-file "${output_dir}/swagger.json" --namespace "${PACKAGE_NAME}" --output-folder "${output_dir}" --add-credentials
autorest -Input "${output_dir}/swagger.json" -CodeGenerator CSharp -Namespace "${PACKAGE_NAME}" -PackageVersion "${CLIENT_VERSION}" -OutputDirectory "${output_dir}" -AddCredentials true
mkdir -p "${output_dir}/.autorest-codegen"
autorest --info --json > "${output_dir}/.autorest-codegen/autorest-info.json"
echo "---Done."