From 364459c5765b38530cba775a5654ebeb260b462a Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 9 May 2018 18:54:13 +0100 Subject: [PATCH] ci(docs-infra): move AIO preview deployment to CircleCI Now instead of pushing the AIO build artifacts to the preview server from inside a Travis job, the artifacts are built and hosted on the CircleCI infrastructure. The preview server will then pull these down after being triggered by a CircleCI build webhook. --- .circleci/config.yml | 20 +++++++ aio/aio-builds-setup/dockerbuild/Dockerfile | 4 ++ .../dockerbuild/nginx/aio-builds.conf | 13 +---- aio/package.json | 1 - aio/scripts/build-artifacts.sh | 16 +++++ aio/scripts/deploy-preview.sh | 58 ------------------- scripts/ci/build.sh | 10 ---- 7 files changed, 43 insertions(+), 79 deletions(-) create mode 100755 aio/scripts/build-artifacts.sh delete mode 100755 aio/scripts/deploy-preview.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 2469efc165..6350a32324 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -148,6 +148,22 @@ jobs: - run: bazel run @yarn//:yarn - run: bazel query --output=label //... | xargs bazel test --define=compile=local --build_tag_filters=ivy-local --test_tag_filters=-manual,ivy-local + aio_preview: + <<: *job_defaults + environment: + AIO_SNAPSHOT_ARTIFACT_PATH: &aio_preview_artifact_path 'aio/tmp/snapshot.tgz' + steps: + - checkout: + <<: *post_checkout + - restore_cache: + key: *cache_key + - run: ./aio/scripts/build-artifacts.sh $AIO_SNAPSHOT_ARTIFACT_PATH + - store_artifacts: + path: *aio_preview_artifact_path + # The `destination` needs to be kept in synch with the value of + # `AIO_ARTIFACT_PATH` in `aio/aio-builds-setup/Dockerfile` + destination: aio/dist/aio-snapshot.tgz + # This job exists only for backwards-compatibility with old scripts and tests # that rely on the pre-Bazel dist/packages-dist layout. # It duplicates some work with the job above: we build the bazel packages @@ -245,6 +261,7 @@ workflows: - test_ivy_jit - test_ivy_aot - build-packages-dist + - aio_preview - integration_test: requires: - build-packages-dist @@ -273,3 +290,6 @@ workflows: branches: only: - master +notify: + webhooks: + - url: https://35.224.48.224/circle-build \ No newline at end of file diff --git a/aio/aio-builds-setup/dockerbuild/Dockerfile b/aio/aio-builds-setup/dockerbuild/Dockerfile index 858439ab2d..e12bc29536 100644 --- a/aio/aio-builds-setup/dockerbuild/Dockerfile +++ b/aio/aio-builds-setup/dockerbuild/Dockerfile @@ -13,6 +13,10 @@ EXPOSE 80 443 # Build-time args and env vars +# The AIO_ARTIFACT_PATH path needs to be kept in synch with the value of +# `aio_preview->steps->store_artifacts->destination` property in `.circleci/config.yml` +ARG AIO_ARTIFACT_PATH=aio/dist/aio-snapshot.tgz +ARG TEST_AIO_ARTIFACT_PATH=$AIO_ARTIFACT_PATH ARG AIO_BUILDS_DIR=/var/www/aio-builds ARG TEST_AIO_BUILDS_DIR=/tmp/aio-builds ARG AIO_DOMAIN_NAME=ngbuilds.io diff --git a/aio/aio-builds-setup/dockerbuild/nginx/aio-builds.conf b/aio/aio-builds-setup/dockerbuild/nginx/aio-builds.conf index ec2a244f48..6399bfab3c 100644 --- a/aio/aio-builds-setup/dockerbuild/nginx/aio-builds.conf +++ b/aio/aio-builds-setup/dockerbuild/nginx/aio-builds.conf @@ -66,23 +66,16 @@ server { return 200 ''; } - # Upload builds - location "~^/create-build/(?[1-9][0-9]*)/(?[0-9a-f]{40})/?$" { + # Notify about CircleCI builds + location "~^/circle-build/?$" { if ($request_method != "POST") { add_header Allow "POST"; return 405; } - client_body_temp_path /tmp/aio-create-builds; - client_body_buffer_size 128K; - client_max_body_size {{$AIO_UPLOAD_MAX_SIZE}}; - client_body_in_file_only on; - proxy_pass_request_headers on; - proxy_set_header X-FILE $request_body_file; - proxy_set_body off; proxy_redirect off; - proxy_method GET; + proxy_method POST; proxy_pass http://{{$AIO_UPLOAD_HOSTNAME}}:{{$AIO_UPLOAD_PORT}}$request_uri; resolver 127.0.0.1; diff --git a/aio/package.json b/aio/package.json index b8cdcaff5f..99d5d396cf 100644 --- a/aio/package.json +++ b/aio/package.json @@ -35,7 +35,6 @@ "example-use-local": "node tools/ng-packages-installer overwrite ./tools/examples/shared --debug", "example-use-npm": "node tools/ng-packages-installer restore ./tools/examples/shared", "example-check-local": "node tools/ng-packages-installer check ./tools/examples/shared", - "deploy-preview": "scripts/deploy-preview.sh", "deploy-production": "scripts/deploy-to-firebase.sh", "check-env": "yarn ~~check-env", "postcheck-env": "yarn aio-check-local", diff --git a/aio/scripts/build-artifacts.sh b/aio/scripts/build-artifacts.sh new file mode 100755 index 0000000000..2104db5908 --- /dev/null +++ b/aio/scripts/build-artifacts.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +source "`dirname $0`/../../scripts/ci/env.sh" print + +readonly INPUT_DIR=dist/ +readonly OUTPUT_FILE=$PROJECT_ROOT/$1 +( + cd $PROJECT_ROOT/aio + + # Build and store the app + yarn build + mkdir -p "`dirname $OUTPUT_FILE`" + tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" . +) diff --git a/aio/scripts/deploy-preview.sh b/aio/scripts/deploy-preview.sh deleted file mode 100755 index 70b3e2ee84..0000000000 --- a/aio/scripts/deploy-preview.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -# WARNING: NGBUILDS_IO_KEY should NOT be printed. -set +x -eu -o pipefail -exec 3>&1 - - -readonly INPUT_DIR=dist/ -readonly OUTPUT_FILE=/tmp/snapshot.tar.gz -readonly AIO_BUILDS_DOMAIN=ngbuilds.io -readonly UPLOAD_URL=https://$AIO_BUILDS_DOMAIN/create-build/$TRAVIS_PULL_REQUEST/$TRAVIS_PULL_REQUEST_SHA - -readonly SHORT_SHA=$(echo $TRAVIS_PULL_REQUEST_SHA | cut -c1-7) -readonly DEPLOYED_URL=https://pr$TRAVIS_PULL_REQUEST-$SHORT_SHA.$AIO_BUILDS_DOMAIN - -readonly skipBuild=$([[ "$1" == "--skip-build" ]] && echo "true" || echo ""); -readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -P "^(?:aio|packages)/(?!.*[._]spec\.[jt]s$)" | wc -l) - -( - cd "`dirname $0`/.." - - # Do not deploy unless this PR has touched relevant files: `aio/` or `packages/` (except for spec files) - if [[ $relevantChangedFilesCount -eq 0 ]]; then - echo "Skipping deploy because this PR did not touch any relevant files." - exit 0 - fi - - # Build the app - if [[ "$skipBuild" != "true" ]]; then - yarn build - fi - tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" . - - # Deploy to staging - readonly output=$( - curl --include --location --request POST --silent --write-out "\nHTTP_CODE: %{http_code}\n" \ - --header "Authorization: Token $NGBUILDS_IO_KEY" --data-binary "@$OUTPUT_FILE" "$UPLOAD_URL" \ - | sed 's/\r\n/\n/' \ - | tee /dev/fd/3 - ) - readonly isHidden=$([[ `echo $output | grep 'non-public'` ]] && echo "true" || echo "") - readonly httpCode=$(echo "$output" | tail -1 | sed 's/HTTP_CODE: //') - - # Exit with an error if the request failed. - # (Ignore 409 failures, which mean trying to re-deploy for the same PR/SHA.) - if [[ $httpCode -lt 200 ]] || ([[ $httpCode -ge 400 ]] && [[ $httpCode -ne 409 ]]); then - exit 1 - fi - - # Run PWA-score tests (unless the deployment is not public yet; - # i.e. it could not be automatically verified). - if [[ $httpCode -ne 202 ]] && [[ "$isHidden" != "true" ]]; then - yarn test-pwa-score "$DEPLOYED_URL" "$MIN_PWA_SCORE" - fi - - # Check the bundle sizes. - yarn payload-size -) diff --git a/scripts/ci/build.sh b/scripts/ci/build.sh index a14dab89ac..2a6b738cdf 100755 --- a/scripts/ci/build.sh +++ b/scripts/ci/build.sh @@ -25,16 +25,6 @@ if [[ ${CI_MODE:-} == "aio" ]]; then ( cd "`dirname $0`/../../aio" yarn build - - # If this is a PR for angular/angular@master or angular/angular@, deploy a - # snapshot for previewing early (if preconditions are met) regardless of the test outcome. - if [[ ${TRAVIS_REPO_SLUG} == "angular/angular" ]] && - ([[ $TRAVIS_BRANCH == "master" ]] || [[ $TRAVIS_BRANCH == $STABLE_BRANCH ]]) && - [[ $TRAVIS_PULL_REQUEST != "false" ]]; then - travisFoldStart "deploy.aio.pr-preview" - yarn deploy-preview --skip-build - travisFoldEnd "deploy.aio.pr-preview" - fi ) travisFoldEnd "build.aio" exit 0;