#!/bin/bash # Copyright 2019 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. # This script build node problem detector for presubmit and CI jobs and push to # staging, so that kubernetes E2E tests have access to the build. set -o errexit set -o nounset set -o pipefail NPD_STAGING_PATH=${NPD_STAGING_PATH:-"gs://node-problem-detector-staging"} NPD_STAGING_REGISTRY=${NPD_STAGING_REGISTRY:-"gcr.io/node-problem-detector-staging"} PR_ENV_FILENAME=${PR_ENV_FILENAME:-"pr.env"} CI_ENV_FILENAME=${CI_ENV_FILENAME:-"ci.env"} CI_CUSTOM_FLAGS_ENV_FILENAME=${CI_CUSTOM_FLAGS_ENV_FILENAME:-"ci-custom-flags.env"} ROOT_PATH=$(git rev-parse --show-toplevel) GCS_URL_PREFIX="https://storage.googleapis.com/" function print-help() { echo "Usage: build.sh [flags] [command]" echo echo "Available flags:" echo " -p [PR_NUMBER] Specify the pull request number when building for a presubmit job." echo " -f Use custom flags." echo echo "Available commands:" echo " help Print this help message" echo " pr Build node-problem-detector for presubmit jobs and push to staging. Flag -p is required." echo " ci Build node-problem-detector for CI jobs and push to staging." echo " get-ci-env Download environment variable file from staging for CI job." echo " install-lib Install the required libraries and tools for presubmit and CI jobs." echo echo "Examples:" echo " build.sh help" echo " build.sh -p [PR_NUMBER] pr" echo " build.sh -p [PR_NUMBER] -f pr" echo " build.sh ci" echo " build.sh get-ci-env" echo " build.sh -f get-ci-env" echo " build.sh install-lib" } function get-version() { if [ -d .git ]; then echo `git describe --tags --dirty` else echo "UNKNOWN" fi } function install-lib() { apt-get update apt-get install -y libsystemd-dev # Turn off go modules here, because we are not trying to install # ginkgo library/module. We are trying to install the ginkgo executable. GO111MODULE=off go get -v github.com/onsi/ginkgo/ginkgo } function write-env-file() { local -r env_file="${1}" if [[ -z "${env_file}" ]]; then echo "ERROR: env_file is missing." exit 1 fi cat > ${ROOT_PATH}/${env_file} <> ${ROOT_PATH}/${env_file} <