sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/cmd/deck/gather-static.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2022 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -o errexit 17 set -o nounset 18 set -o pipefail 19 20 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" 21 cd "${REPO_ROOT}" 22 23 # Build ts-rollup so that it can run in docker 24 source hack/build/setup-go.sh 25 if [[ -z ${NO_DOCKER:-} ]]; then 26 GOOS=linux GOARCH=amd64 go build -o _bin/ts-rollup ./hack/ts-rollup 27 else 28 go build -o _bin/ts-rollup ./hack/ts-rollup 29 fi 30 31 readonly STATIC_MAP_FILE="cmd/deck/static-map" 32 readonly JS_OUTPUT_DIR="_output/js" 33 mkdir -p "${JS_OUTPUT_DIR}" 34 readonly KO_DATA_PATH="cmd/deck/kodata" 35 if [[ -d $KO_DATA_PATH ]]; then 36 rm -rf $KO_DATA_PATH 37 fi 38 39 # Clean if meant to be 40 if [[ "${1:-}" == "--cleanup" ]]; then 41 echo "Running in cleanup mode" 42 ./hack/run-in-node-container.sh _bin/ts-rollup --packages="${REPO_ROOT}/cmd/deck/.ts-packages" --root-dir=. --cleanup-only 43 rm -rf ${KO_DATA_PATH} 44 exit 0 45 fi 46 47 # ensure deps are installed 48 ./hack/build/ensure-node_modules.sh 49 50 # Roll up typescripts 51 ./hack/run-in-node-container.sh _bin/ts-rollup --packages="${REPO_ROOT}/cmd/deck/.ts-packages" --root-dir=. 52 53 STATIC_MAP=() 54 while IFS= read -r map; do 55 STATIC_MAP+=("${map}") 56 done < "${STATIC_MAP_FILE}" 57 58 for map in "${STATIC_MAP[@]}"; do 59 parts=(${map//->/ }) 60 src="${REPO_ROOT}/${parts[0]}" 61 dst="${KO_DATA_PATH}/${parts[1]}" 62 echo "src: $src, dst: $dst" 63 mkdir -p $dst 64 rsync \ 65 -av \ 66 --exclude='*.go' \ 67 --exclude='*.ts' \ 68 --exclude='tsconfig.json' \ 69 --exclude='*.bazel' \ 70 --exclude='*/*.go' \ 71 --exclude='*/*.ts' \ 72 --exclude='*/tsconfig.json' \ 73 --exclude='*/*.bazel' \ 74 $src \ 75 $dst 76 done