mirror of https://github.com/k3s-io/k3s
address host dir vs docker dir issue
parent
358221f9fd
commit
4e4c67c624
|
@ -24,49 +24,52 @@ set -o pipefail
|
|||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
kube::golang::setup_env
|
||||
kube::util::ensure-temp-dir
|
||||
|
||||
#KUBE_ROOT should be an absolute path now that we have run kube::golang::setup_env.
|
||||
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}"}
|
||||
DEFAULT_OUTPUT_PATH="${REPO_DIR}/docs/api-reference"
|
||||
OUTPUT=${1:-${DEFAULT_OUTPUT_PATH}}
|
||||
OUTPUT_TEMP="${KUBE_TEMP}/generated_html"
|
||||
TMP_SUBPATH="_output/generated_html"
|
||||
OUTPUT_TMP_IN_HOST="${REPO_DIR}/${TMP_SUBPATH}"
|
||||
OUTPUT_TMP="${KUBE_ROOT}/${TMP_SUBPATH}"
|
||||
|
||||
echo "Generating api reference docs at ${OUTPUT}"
|
||||
echo "Generating api reference docs at ${OUTPUT_TMP}"
|
||||
|
||||
V1_PATH="${OUTPUT}/v1/"
|
||||
V1_TEMP_PATH="${OUTPUT_TEMP}/v1/"
|
||||
mkdir -p ${V1_TEMP_PATH}
|
||||
V1BETA1_PATH="${OUTPUT}/extensions/v1beta1/"
|
||||
V1BETA1_TEMP_PATH="${OUTPUT_TEMP}/extensions/v1beta1/"
|
||||
mkdir -p ${V1BETA1_TEMP_PATH}
|
||||
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 -u $(id -u) --rm -v $V1_TEMP_PATH:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4 \
|
||||
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 -u $(id -u) --rm -v $V1BETA1_TEMP_PATH:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4 \
|
||||
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_TEMP}" > /dev/null
|
||||
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_TEMP}/${file}" ]]; then
|
||||
echo "comparing ${OUTPUT}/${file} with ${OUTPUT_TEMP}/${file}"
|
||||
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_TEMP}/${file}")
|
||||
generated=$(cat "${OUTPUT_TMP}/${file}")
|
||||
|
||||
# Filter out meaningless lines with timestamps
|
||||
original=$(echo "${original}" | grep -v "Last updated" || :)
|
||||
|
@ -76,11 +79,14 @@ while read file; do
|
|||
# auto-managed content.
|
||||
if diff -Bw >/dev/null <(echo "${original}") <(echo "${generated}"); then
|
||||
# actual contents same, overwrite generated with original.
|
||||
cp "${OUTPUT}/${file}" "${OUTPUT_TEMP}/${file}"
|
||||
cp "${OUTPUT}/${file}" "${OUTPUT_TMP}/${file}"
|
||||
fi
|
||||
fi
|
||||
done <"${OUTPUT_TEMP}/.generated_html"
|
||||
done <"${OUTPUT_TMP}/.generated_html"
|
||||
|
||||
cp -af "${OUTPUT_TEMP}"/* "${OUTPUT}"
|
||||
echo "Moving api reference docs from ${OUT_TMP} to ${OUTPUT}"
|
||||
|
||||
cp -af "${OUTPUT_TMP}"/* "${OUTPUT}"
|
||||
rm -r ${OUTPUT_TMP}
|
||||
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
||||
|
|
|
@ -26,15 +26,8 @@ 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"
|
||||
HOST_OUTPUT_DIR="${KUBE_ROOT}/_tmp/api-reference"
|
||||
mkdir -p ${HOST_OUTPUT_DIR}
|
||||
TMP_ROOT="${KUBE_ROOT}/_tmp"
|
||||
|
||||
# Generate API reference docs in tmp.
|
||||
|
@ -42,7 +35,7 @@ TMP_ROOT="${KUBE_ROOT}/_tmp"
|
|||
|
||||
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}" "${HOST_OUTPUT_DIR}" || ret=$?
|
||||
rm -rf "${TMP_ROOT}"
|
||||
if [[ $ret -eq 0 ]]
|
||||
then
|
||||
|
|
Loading…
Reference in New Issue