From 6249bfc5cb249f1a89c315b340379bf0cf789c2a Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 21 Oct 2020 16:50:22 +0300 Subject: [PATCH] scripts: copy prow integration from master Copy all test-infra scripts and cloudbuild.yaml from master. Also cherry-pick the required poll-image Makefile target. (copied from commit a08fb66fa7f926af60b5b1293110885f3b44ac6a) --- Makefile | 12 ++++++++++ cloudbuild.yaml | 12 ++++++++++ scripts/test-infra/build-gh-pages.sh | 11 +++++++++ scripts/test-infra/build-image.sh | 3 +++ scripts/test-infra/build.sh | 3 +++ scripts/test-infra/push-image.sh | 9 ++++++++ scripts/test-infra/test-e2e.sh | 34 ++++++++++++++++++++++++++++ scripts/test-infra/verify.sh | 9 ++++++++ 8 files changed, 93 insertions(+) create mode 100644 cloudbuild.yaml create mode 100755 scripts/test-infra/build-gh-pages.sh create mode 100755 scripts/test-infra/build-image.sh create mode 100755 scripts/test-infra/build.sh create mode 100755 scripts/test-infra/push-image.sh create mode 100755 scripts/test-infra/test-e2e.sh create mode 100755 scripts/test-infra/verify.sh diff --git a/Makefile b/Makefile index afcfc649b..bfd86f727 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,18 @@ push: $(IMAGE_PUSH_CMD) $(IMAGE_TAG) for tag in $(IMAGE_EXTRA_TAGS); do $(IMAGE_PUSH_CMD) $$tag; done +poll-image: + set -e; \ + image=$(IMAGE_REPO):$(IMAGE_TAG_NAME); \ + base_url=`echo $(IMAGE_REPO) | sed -e s'!\([^/]*\)!\1/v2!'`; \ + errors=`curl -fsS -X GET https://$$base_url/manifests/$(IMAGE_TAG_NAME)|jq .errors`; \ + if [ "$$errors" = "null" ]; then \ + echo Image $$image found; \ + else \ + echo Image $$image not found; \ + exit 1; \ + fi; + site-build: @mkdir -p docs/vendor/bundle $(SITE_BUILD_CMD) sh -c "bundle install && jekyll build $(JEKYLL_OPTS)" diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 000000000..78745f313 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,12 @@ +steps: + - name: gcr.io/k8s-testimages/gcb-docker-gcloud:v20200824-5d057db + entrypoint: scripts/test-infra/push-image.sh + env: + - IMAGE_REGISTRY=gcr.io/$PROJECT_ID + - _GIT_TAG=$_GIT_TAG + - IMAGE_EXTRA_TAG_NAMES=$_PULL_BASE_REF +substitutions: + _GIT_TAG: '0.0.0' + _PULL_BASE_REF: 'master' +options: + substitution_option: ALLOW_LOOSE diff --git a/scripts/test-infra/build-gh-pages.sh b/scripts/test-infra/build-gh-pages.sh new file mode 100755 index 000000000..c62571c8c --- /dev/null +++ b/scripts/test-infra/build-gh-pages.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +# Pre-create output directory with all write access. The Jekyll docker image is +# stupid enough to do all sorts of uid/gid/chown magic making build fail for +# root user. In prow we run as root because of DIND. +_outdir="docs/_site" +mkdir -p "$_outdir" +chmod a+rwx "$_outdir" + +# Build docs +make site-build diff --git a/scripts/test-infra/build-image.sh b/scripts/test-infra/build-image.sh new file mode 100755 index 000000000..88381a134 --- /dev/null +++ b/scripts/test-infra/build-image.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +make image diff --git a/scripts/test-infra/build.sh b/scripts/test-infra/build.sh new file mode 100755 index 000000000..817e90187 --- /dev/null +++ b/scripts/test-infra/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +make build diff --git a/scripts/test-infra/push-image.sh b/scripts/test-infra/push-image.sh new file mode 100755 index 000000000..adefba64a --- /dev/null +++ b/scripts/test-infra/push-image.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +# Override VERSION if _GIT_TAG is specified. Strip 10 first characters +# ('vYYYYMMDD-') from _GIT_TAG in order to get a reproducible version and +# container image tag +VERSION_OVERRIDE=${_GIT_TAG+VERSION=${_GIT_TAG:10}} + +make image $VERSION_OVERRIDE +make push $VERSION_OVERRIDE diff --git a/scripts/test-infra/test-e2e.sh b/scripts/test-infra/test-e2e.sh new file mode 100755 index 000000000..7cebec82d --- /dev/null +++ b/scripts/test-infra/test-e2e.sh @@ -0,0 +1,34 @@ +#!/bin/bash -e + +# Install deps +curl -o $HOME/bin/aws-iam-authenticator --create-dirs https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator +chmod a+x $HOME/bin/aws-iam-authenticator +export PATH=$PATH:$HOME/bin + + +# Configure environment +export KUBECONFIG=`pwd`/kubeconfig +export E2E_TEST_CONFIG=`pwd`/e2e-test-config + +echo "$KUBECONFIG_DATA" > "$KUBECONFIG" +echo "$E2E_TEST_CONFIG_DATA" > "$E2E_TEST_CONFIG" + + +# Wait for the image to be built and published +i=1 +while true; do + if make poll-image; then + break + elif [ $i -ge 10 ]; then + "ERROR: too many tries when polling for image" + exit 1 + fi + sleep 60 + + i=$(( $i + 1 )) +done + + +# Configure environment and run tests +make e2e-test + diff --git a/scripts/test-infra/verify.sh b/scripts/test-infra/verify.sh new file mode 100755 index 000000000..efd721e48 --- /dev/null +++ b/scripts/test-infra/verify.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +# Install deps +curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.30.0 +export PATH=$PATH:$(go env GOPATH)/bin + +# Run verify steps +make gofmt-verify +make ci-lint