From 55265cd05018ee0552e05532351f3fa83b8447fc Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Thu, 12 Nov 2020 19:20:52 +0200 Subject: [PATCH] Feature/s3 deploy (#243) * Create deploy.sh * Update .travis.yml * Update package.json * make deploy.sh exec * Update deploy.sh * Update .travis.yml * Update deploy.sh Co-authored-by: Matthias Kretschmann --- .travis.yml | 12 +++++++- package.json | 3 +- scripts/deploy.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100755 scripts/deploy.sh diff --git a/.travis.yml b/.travis.yml index 68ebbcf34..3295a3a9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,16 +5,26 @@ node_js: node cache: npm: true +before_install: + - sudo apt-get -qq update + - sudo apt-get install python3-pip + - sudo -H pip3 install --upgrade pip + - sudo -H pip3 install -U setuptools + before_script: # - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter # - chmod +x ./cc-test-reporter # - './cc-test-reporter before-build' - script: # will run `npm ci` automatically here - npm run lint # - './cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT' - npm run build +after_success: + - pip3 install --user awscli + - export PATH=$PATH:$HOME/.local/bin + - npm run deploy + notifications: email: false diff --git a/package.json b/package.json index 5f2e34112..cbe39ae2b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "analyze": "npm run build && source-map-explorer 'public/*.js'", "storybook": "start-storybook -p 4000 -c .storybook", "storybook:build": "build-storybook -c .storybook -o public/storybook", - "write:repoMetadata": "node ./scripts/write-repo-metadata > repo-metadata.json" + "write:repoMetadata": "node ./scripts/write-repo-metadata > repo-metadata.json", + "deploy": "./scripts/deploy.sh" }, "dependencies": { "@coingecko/cryptoformat": "^0.4.2", diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 000000000..f22167ca0 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# +# required environment variables: +# AWS_ACCESS_KEY_ID +# AWS_SECRET_ACCESS_KEY +# AWS_DEFAULT_REGION us-east-1 +AWS_S3_BUCKET="www-market" +AWS_S3_BUCKET_BETA="www-market-beta" + +# +set -e; + +function s3sync { + aws s3 sync ./public s3://"$1" \ + --include "*" \ + --exclude "*.html" \ + --exclude "sw.js" \ + --exclude "*page-data.json" \ + --exclude "chunk-map.json" \ + --exclude "sitemap.xml" \ + --exclude ".iconstats.json" \ + --exclude "humans.txt" \ + --exclude "robots.txt" \ + --cache-control public,max-age=31536000,immutable \ + --delete \ + --acl public-read + + aws s3 sync ./public s3://"$1" \ + --exclude "*" \ + --include "*.html" \ + --include "sw.js" \ + --include "*page-data.json" \ + --include "chunk-map.json" \ + --include "sitemap.xml" \ + --include ".iconstats.json" \ + --include "humans.txt" \ + --include "robots.txt" \ + --cache-control public,max-age=0,must-revalidate \ + --delete \ + --acl public-read +} + +## +## check for pull request against master +## +if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$TRAVIS_BRANCH" == "main" ]; then + + s3sync $AWS_S3_BUCKET_BETA + +## +## check for master push which is no pull request +## +elif [ "$TRAVIS_BRANCH" == "main" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] || [ "$TRAVIS" != true ]; then + + s3sync $AWS_S3_BUCKET + + + echo "---------------------------------------------" + echo " ✓ done deployment " + echo "---------------------------------------------" + + exit; + +else + + echo "---------------------------------------------" + echo " nothing to deploy " + echo "---------------------------------------------" + +fi