From e4df956fb629490dbc7af43ec9c5edda3245d45f Mon Sep 17 00:00:00 2001 From: Pengyuan Bian Date: Tue, 14 Jan 2020 19:08:51 -0800 Subject: [PATCH] Push generated wasm files in postsubmit (#2623) * push generated wasm file in post submit * rename sha256 file * add check before push wasm file * clean up --- Makefile.core.mk | 2 +- scripts/generate-wasm.sh | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Makefile.core.mk b/Makefile.core.mk index b31938ab3037..b3e525806102 100644 --- a/Makefile.core.mk +++ b/Makefile.core.mk @@ -111,7 +111,7 @@ test_release: export PATH=$(PATH) CC=$(CC) CXX=$(CXX) BAZEL_BUILD_ARGS="$(BAZEL_BUILD_ARGS)" && ./scripts/release-binary.sh -i push_release: - export PATH=$(PATH) CC=$(CC) CXX=$(CXX) BAZEL_BUILD_ARGS="$(BAZEL_BUILD_ARGS)" && ./scripts/release-binary.sh -d "$(RELEASE_GCS_PATH)" -p && ./scripts/generate-wasm.sh -b -p + export PATH=$(PATH) CC=$(CC) CXX=$(CXX) BAZEL_BUILD_ARGS="$(BAZEL_BUILD_ARGS)" && ./scripts/release-binary.sh -d "$(RELEASE_GCS_PATH)" -p && ./scripts/generate-wasm.sh -b -p -d "$(RELEASE_GCS_PATH)" .PHONY: build clean test check artifacts diff --git a/scripts/generate-wasm.sh b/scripts/generate-wasm.sh index b889505204d2..6207c86d4f5b 100755 --- a/scripts/generate-wasm.sh +++ b/scripts/generate-wasm.sh @@ -25,19 +25,22 @@ function usage() { If the image already exist in the HUB, this will be noop. The container will be used to compile wasm files. -p push the wasm sdk container built from the envoy SHA. Must use with `-b` - -c controls whether to check diff of generated wasm files." + -c controls whether to check diff of generated wasm files. + -d The bucket name to store the generated wasm files." exit 1 } BUILD_CONTAINER=0 PUSH_CONTAINER=0 CHECK_DIFF=0 +DST_BUCKET="" -while getopts bpc arg ; do +while getopts bpcd: arg ; do case "${arg}" in b) BUILD_CONTAINER=1;; p) PUSH_DOCKER_IMAGE=1;; c) CHECK_DIFF=1;; + d) DST_BUCKET="${OPTARG}";; *) usage;; esac done @@ -90,3 +93,28 @@ if [[ ${CHECK_DIFF} == 1 ]]; then echo "wasm files are up to dated" fi fi + +echo "Destination bucket: ${DST_BUCKET}" +if [ -n "${DST_BUCKET}" ]; then + cd ${ROOT} + # Get SHA of proxy repo + SHA="$(git rev-parse --verify HEAD)" + TMP_WASM=$(mktemp -d -t wasm-plugins-XXXXXXXXXX) + trap "rm -rf ${TMP_WASM}" EXIT + for i in `find . -name "*.wasm" -type f`; do + # Get name of the plugin + PLUGIN_NAME=$(basename $(dirname ${i})) + # Rename the plugin file and generate sha256 for it + WASM_NAME="${PLUGIN_NAME}-${SHA}.wasm" + WASM_PATH="${TMP_WASM}/${WASM_NAME}" + SHA256_PATH="${WASM_PATH}.sha256" + cp ${i} ${WASM_PATH} + sha256sum "${WASM_PATH}" > "${SHA256_PATH}" + + # push wasm files and sha to the given bucket + gsutil stat "${DST_BUCKET}/${WASM_NAME}" \ + && { echo "WASM file ${WASM_NAME} already exist"; continue; } \ + || echo "Pushing the WASM file ${WASM_NAME}" + gsutil cp "${WASM_PATH}" "${SHA256_PATH}" "${DST_BUCKET}" + done +fi