diff --git a/docs/api-reference/extensions/v1beta1/definitions.html b/docs/api-reference/extensions/v1beta1/definitions.html old mode 100644 new mode 100755 diff --git a/docs/api-reference/extensions/v1beta1/operations.html b/docs/api-reference/extensions/v1beta1/operations.html old mode 100644 new mode 100755 diff --git a/docs/api-reference/v1/definitions.html b/docs/api-reference/v1/definitions.html old mode 100644 new mode 100755 diff --git a/docs/api-reference/v1/operations.html b/docs/api-reference/v1/operations.html old mode 100644 new mode 100755 diff --git a/hack/gen-swagger-doc/Dockerfile b/hack/gen-swagger-doc/Dockerfile index 27e2d3b9b13..9ad26afcc61 100644 --- a/hack/gen-swagger-doc/Dockerfile +++ b/hack/gen-swagger-doc/Dockerfile @@ -7,6 +7,9 @@ RUN wget https://services.gradle.org/distributions/gradle-2.5-bin.zip RUN mkdir build/ RUN unzip gradle-2.5-bin.zip -d build/ +RUN mkdir gradle-cache/ +ENV GRADLE_USER_HOME=/gradle-cache + COPY build.gradle build/ COPY gen-swagger-docs.sh build/ @@ -17,5 +20,7 @@ RUN wget https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/swag RUN build/gen-swagger-docs.sh v1 https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes/master/pkg/api/v1/register.go RUN rm /output/* RUN rm /swagger-source/* +RUN chmod -R 777 build/ +RUN chmod -R 777 gradle-cache/ ENTRYPOINT ["build/gen-swagger-docs.sh"] diff --git a/hack/gen-swagger-doc/gen-swagger-docs.sh b/hack/gen-swagger-doc/gen-swagger-docs.sh index 3ed3a9c0e33..91f39cf5a0a 100755 --- a/hack/gen-swagger-doc/gen-swagger-docs.sh +++ b/hack/gen-swagger-doc/gen-swagger-docs.sh @@ -20,7 +20,7 @@ set -o errexit set -o nounset set -o pipefail -cd /build/ +cd /build wget "$2" -O register.go diff --git a/hack/update-api-reference-docs.sh b/hack/update-api-reference-docs.sh index 8f5806c8740..5753b98d11c 100755 --- a/hack/update-api-reference-docs.sh +++ b/hack/update-api-reference-docs.sh @@ -22,27 +22,71 @@ set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. -REPO_DIR=${REPO_DIR:-"${PWD}/${KUBE_ROOT}"} -DEFAULT_OUTPUT_PATH="${REPO_DIR}/docs/api-reference" -OUTPUT=${1:-${DEFAULT_OUTPUT_PATH}} +source "${KUBE_ROOT}/hack/lib/init.sh" +kube::golang::setup_env -echo "Generating api reference docs at ${OUTPUT}" +DEFAULT_OUTPUT="${KUBE_ROOT}/docs/api-reference" +OUTPUT=${1:-${DEFAULT_OUTPUT}} +# Use REPO_DIR if provided so we can set it to the host-resolvable path +# to the repo root if we are running this script from a container with +# docker mounted in as a volume. +# We pass the host output dir as the source dir to `docker run -v`, but use +# the regular one to compute diff (they will be the same if running this +# test on the host, potentially different if running in a container). +REPO_DIR=${REPO_DIR:-"${KUBE_ROOT}"} +TMP_SUBPATH="_output/generated_html" +OUTPUT_TMP_IN_HOST="${REPO_DIR}/${TMP_SUBPATH}" +OUTPUT_TMP="${KUBE_ROOT}/${TMP_SUBPATH}" -V1_PATH="${OUTPUT}/v1/" -V1BETA1_PATH="${OUTPUT}/extensions/v1beta1" +echo "Generating api reference docs at ${OUTPUT_TMP}" + +V1_TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/v1/" +V1_TMP="${OUTPUT_TMP}/v1/" +mkdir -p ${V1_TMP} +V1BETA1_TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/extensions/v1beta1/" +V1BETA1_TMP="${OUTPUT_TMP}/extensions/v1beta1/" +mkdir -p ${V1BETA1_TMP} SWAGGER_PATH="${REPO_DIR}/api/swagger-spec/" echo "Reading swagger spec from: ${SWAGGER_PATH}" -mkdir -p $V1_PATH -mkdir -p $V1BETA1_PATH - -docker run --rm -v $V1_PATH:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v3 \ +docker run -u $(id -u) --rm -v $V1_TMP_IN_HOST:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4 \ v1 \ https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/api/v1/register.go -docker run --rm -v $V1BETA1_PATH:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v3 \ +docker run -u $(id -u) --rm -v $V1BETA1_TMP_IN_HOST:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4 \ v1beta1 \ https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/apis/extensions/v1beta1/register.go +# Check if we actually changed anything +pushd "${OUTPUT_TMP}" > /dev/null +touch .generated_html +find . -type f | cut -sd / -f 2- | LC_ALL=C sort > .generated_html +popd > /dev/null + +while read file; do + if [[ -e "${OUTPUT}/${file}" && -e "${OUTPUT_TMP}/${file}" ]]; then + echo "comparing ${OUTPUT}/${file} with ${OUTPUT_TMP}/${file}" + # Filter all munges from original content. + original=$(cat "${OUTPUT}/${file}") + generated=$(cat "${OUTPUT_TMP}/${file}") + + # Filter out meaningless lines with timestamps + original=$(echo "${original}" | grep -v "Last updated" || :) + generated=$(echo "${generated}" | grep -v "Last updated" || :) + + # By now, the contents should be normalized and stripped of any + # auto-managed content. + if diff -Bw >/dev/null <(echo "${original}") <(echo "${generated}"); then + # actual contents same, overwrite generated with original. + cp "${OUTPUT}/${file}" "${OUTPUT_TMP}/${file}" + fi + fi +done <"${OUTPUT_TMP}/.generated_html" + +echo "Moving api reference docs from ${OUTPUT_TMP} to ${OUTPUT}" + +cp -af "${OUTPUT_TMP}"/* "${OUTPUT}" +rm -r ${OUTPUT_TMP} + # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/verify-api-reference-docs.sh b/hack/verify-api-reference-docs.sh index f718836a4ad..af93a63a4d4 100755 --- a/hack/verify-api-reference-docs.sh +++ b/hack/verify-api-reference-docs.sh @@ -26,23 +26,16 @@ source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env API_REFERENCE_DOCS_ROOT="${KUBE_ROOT}/docs/api-reference" -# Use REPO_DIR if provided so we can set it to the host-resolvable path -# to the repo root if we are running this script from a container with -# docker mounted in as a volume. -# We pass the host output dir to update-api-reference-docs.sh, but use -# the regular one to compute diff (they will be the same if running this -# test on the host, potentially different if running in a container). -REPO_DIR=${REPO_DIR:-"${KUBE_ROOT}"} -HOST_OUTPUT_DIR="${REPO_DIR}/_tmp/api-reference" -TMP_OUTPUT_DIR="${KUBE_ROOT}/_tmp/api-reference" +OUTPUT_DIR="${KUBE_ROOT}/_tmp/api-reference" +mkdir -p ${OUTPUT_DIR} TMP_ROOT="${KUBE_ROOT}/_tmp" # Generate API reference docs in tmp. -"./hack/update-api-reference-docs.sh" "${HOST_OUTPUT_DIR}" +"./hack/update-api-reference-docs.sh" "${OUTPUT_DIR}" echo "diffing ${API_REFERENCE_DOCS_ROOT} against freshly generated docs" ret=0 -diff -Naupr -I 'Last update' --exclude=*.md "${API_REFERENCE_DOCS_ROOT}" "${TMP_OUTPUT_DIR}" || ret=$? +diff -Naupr -I 'Last update' --exclude=*.md "${API_REFERENCE_DOCS_ROOT}" "${OUTPUT_DIR}" || ret=$? rm -rf "${TMP_ROOT}" if [[ $ret -eq 0 ]] then