From f0151e336cf9e80a24211b102d15bd3895a6a05b Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 16 Nov 2018 11:12:28 +0100 Subject: [PATCH] setup deployment --- .travis.yml | 3 +++ README.md | 20 ++++++++++++++++++ package.json | 3 ++- scripts/deploy.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 scripts/deploy.sh diff --git a/.travis.yml b/.travis.yml index cb673f33..55903909 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,9 @@ script: - npm test - 'if [ "$TRAVIS_SECURE_ENV_VARS" = "true" ]; then npm run build; fi' +after_success: + - npm run deploy + notifications: email: false diff --git a/README.md b/README.md index 7aa8cc53..cd3ad481 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ - [Linting & formatting](#linting--formatting) - [Editor setup: VS Code](#editor-setup-vs-code) - [GitHub GraphQL API](#github-graphql-api) +- [Deployment](#deployment) - [Authors](#authors) - [License](#license) @@ -271,6 +272,25 @@ query { } ``` +## Deployment + +Automatic deployments are triggered upon successful tests & builds on Travis: + +- push to `master` initiates a live deployment +- any Pull Request, and subsequent pushes to it, initiates a beta deployment + +The deploy command simply calls the [`scripts/deploy.sh`](scripts/deploy.sh) script, syncing the contents of the `public/` folder to S3: + +```bash +npm run deploy +``` + +Requires authorization against AWS with [one of the various ways](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html), on Travis this is done with those environment variables: + +- `AWS_ACCESS_KEY_ID` +- `AWS_SECRET_ACCESS_KEY` +- `AWS_DEFAULT_REGION` + ## Authors - Troy McConaghy ([@ttmc](https://github.com/ttmc)) - [Ocean Protocol](https://oceanprotocol.com) diff --git a/package.json b/package.json index 66811ff1..0efa2159 100755 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "lint:md": "markdownlint './**/*.{md,markdown}' --ignore './{node_modules,external,public}/**/*'", "lint:yml": "prettier '**/*.{yml,yaml}' --list-different", "lint": "run-p --continue-on-error lint:js lint:css lint:md lint:yml", - "test": "npm run lint" + "test": "npm run lint", + "deploy": "./scripts/deploy.sh" }, "dependencies": { "@oceanprotocol/art": "^1.0.2", diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 00000000..e8853bdb --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# required environment variables: +# AWS_ACCESS_KEY_ID +# AWS_SECRET_ACCESS_KEY +# AWS_DEFAULT_REGION +AWS_S3_BUCKET="docs.oceanprotocol.com" +AWS_S3_BUCKET_BETA="beta.docs.oceanprotocol.com" +SITEMAP_URL="https%3A%2F%2Fdocs.oceanprotocol.com%2Fsitemap.xml" + +# +set -e; + +function s3sync { + aws s3 sync ./public s3://"$1" --exclude "*.html" --exclude "*.xml" --cache-control max-age=31536000,public,immutable --delete --acl public-read --quiet + + aws s3 sync ./public s3://"$1" --exclude "*" --include "*.html" --include "*.xml" --cache-control max-age=0,no-cache,no-store,must-revalidate --delete --acl public-read --quiet +} + +## +## check for pull request against master +## +if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then + + s3sync $AWS_S3_BUCKET_BETA + +## +## check for master push which is no pull request +## +elif [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] || [ "$TRAVIS" != true ]; then + + s3sync $AWS_S3_BUCKET + + # ping search engines + # returns: HTTP_STATUSCODE URL + # curl -sL -w "%{http_code} %{url_effective}\\n" \ + # "http://www.google.com/webmasters/tools/ping?sitemap=$SITEMAP_URL" -o /dev/null \ + # "http://www.bing.com/webmaster/ping.aspx?siteMap=$SITEMAP_URL" -o /dev/null + + echo "---------------------------------------------" + echo " ✓ done deployment " + echo "---------------------------------------------" + + exit; + +else + + echo "---------------------------------------------" + echo " nothing to deploy " + echo "---------------------------------------------" + +fi