Przeglądaj źródła

Upload Uppy releases to Edgly.net CDN (#558)

* Upload Uppy releases to Edgly.net CDN

* Install AWS CLI if needed

* Remove unpkg from docs

a) Good citizenship to pay for production bandwidth ourselves
b) Nice to have a CDN that will exist exactly as long we will :)

* Fix typos (thx @goto-bus-stop)
Kevin van Zonneveld 7 lat temu
rodzic
commit
33eb159a01

+ 1 - 0
.gitignore

@@ -22,3 +22,4 @@ config/
 nohup.out
 
 examples/bundled-example/bundle.js
+uppy-*.tgz

+ 3 - 0
.travis.yml

@@ -22,6 +22,7 @@ script:
 - npm run build
 - npm run test
 - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then npm run test:acceptance; fi
+- npm run uploadcdn
 env:
   global:
   - CXX=g++-4.8
@@ -33,6 +34,8 @@ env:
   - secure: YpVwjcpc6FomKgRb0tP8MpITEOfvMP2kTAnpSfG3USMW3mZ8Zkn8CLr471DjpmVE2jHklI6AfPTpGPFb1VOsrS7Ea4jxAJOdBwH6Ab7kL52GX0GYtPsSxeTVME5IMZXsU90UCbAXKOEkZbGq5sIaIHjAePmcNSv+OHb157fqcyX0oSJWDg1eVzBikgWhpKtlcbPFp7AdoIvhDr5bPLyV1c0HmOIEirc0VcoQg3fYsKB7mY5tP7KCqCIJtZtD0+FiSamp13WImD0/7wwX0hbTG2KH3zgjyiKOLxsbwXOIpXIJ0utXY4EFZBTTSZjItbL/f5wzZ+xBhwAsy5/Vi2pCtiVI2sUZ98b3FioLdQ7+3jQviNmOam6b56KTNAy2l4Tlu5h8PGtBvsDo+ZcgJ06q65YRZQcnOIweGv0vZ31cdgcVXRb+8fWFywQeIk6DD0FluB3/zZl7pn2Olha0gv4DxiythXDAHRoTzZfFfaPL1T+kl6ViGNQvKi6ucy8/ltlO/JKAeJlWKJouWOe2TvGMNU6JKQfAiqz1y16lVa8P5VYj+cRbsfalYfhqEf96kMdelgCup7mQdTMAiOP6lhIF9ItMjVqVFQECYy6oItxAGXc8UAJJcKJSc6DwVTgOK6V7LfkoM8O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l0PDy80RUY3uyK64qAgQ8U0M81/Ys1oyWyn78TqHcbby7V2Ws5I9Yakrq8D+mdfsWYCio8F6LXHSwJ0mt2FanJtdDvpPk9sAwsXZN0n8xhELt5TiRp3bzVIQ0IPUgF54dTG9/zWRvC1P4TFaFU/2fg73ZEUC5aWJoFMnLSZjbZvp5gwpCVd0MjSBk80nF9dHYcavIgJ0wMGI3BMb8Nn6+T11Gw/ycr7OGU4NMkj7i8vSFgKF74piWZyiNW8orkMN6XZgM+o=

+ 2 - 2
CHANGELOG.md

@@ -62,7 +62,6 @@ What we need to do to release Uppy 1.0
 - [ ] QA: test in multiple browsers and mobile devices
 - [ ] QA: test uppy server. benchmarks / stress test. multiple connections, different setups, large files (10 GB)
 - [ ] QA: tests for some plugins
-- [ ] automatically host releases on edgly and use that as our main CDN
 - [ ] docs: on using plugins, all options, list of plugins, i18n
 - [ ] feature: preset for Transloadit that mimics jQuery SDK, check https://github.com/transloadit/jquery-sdk docs
 - [ ] refactoring: possibly add CSS-in-JS
@@ -126,6 +125,7 @@ To be released: 2018-02-10.
 - [ ] uppy-server: benchmarks / stress test, large file, uppy-server / tus / S3 (10 GB)
 - [ ] meta: add https://twin.github.io/better-file-uploads-with-shrine-direct-uploads to the next blog post
 - [ ] uppy-server: document docker image setup for uppy-server (@ifedapoolarewaju)
+- [x] meta: automatically host releases on edgly and use that as our main CDN (#558 / @kvz)
 - [ ] uppy-server: pass response from uppy-server upload’s endpoint (@ifedapoolarewaju)
 - [ ] uppy-server: support localhost urls as endpoints (@ifedapoolarewaju)
 
@@ -554,7 +554,7 @@ Theme: Getting together.
 - [x] tus: add `resumable` capability flag (@arturi)
 - [x] tus: start fixing pause/resume issues and race conditions (@arturi)
 - [x] test: working Uppy example on Require Bin — latest version straight from NPM http://requirebin.com/?gist=54e076cccc929cc567cb0aba38815105 (@arturi @acconut)
-- [x] meta: update readme docs, add unpkg CDN links (https://unpkg.com/uppy/dist/uppy.min.css) (@arturi)
+- [x] meta: update readme docs, add unpkg CDN links (https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css) (@arturi)
 - [x] meta: write 0.10 release blog post (@arturi)
 
 ## 0.9.0

+ 4 - 4
README.md

@@ -64,21 +64,21 @@ $ npm install uppy --save
 
 We recommend installing from npm and then using a module bundler such as [Webpack](http://webpack.github.io/), [Browserify](http://browserify.org/) or [Rollup.js](http://rollupjs.org/).
 
-Add CSS [uppy.min.css](https://unpkg.com/uppy/dist/uppy.min.css), either to `<head>` of your HTML page or include in JS, if your bundler of choice supports it — transforms and plugins are available for Browserify and Webpack.
+Add CSS [uppy.min.css](https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css), either to `<head>` of your HTML page or include in JS, if your bundler of choice supports it — transforms and plugins are available for Browserify and Webpack.
 
-Alternatively, you can also use a pre-built bundle, for example from [unpkg CDN](https://unpkg.com/uppy/). In that case, `Uppy` will attach itself to the global `window.Uppy` object.
+Alternatively, you can also use a pre-built bundle from Transloadit's CDN: Edgly. In that case `Uppy` will attach itself to the global `window.Uppy` object.
 
 > ⚠️ The bundle currently consists of most Uppy plugins, so this method is not recommended for production, as your users will have to download all plugins when you are likely using just a few.
 
 1\. Add a script to the bottom of `<body>`:
 
 ``` html
-<script src="https://unpkg.com/uppy"></script>
+<script src="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.js"></script>
 ```
 
 2\. Add CSS to `<head>`:
 ``` html
-<link href="https://unpkg.com/uppy/dist/uppy.min.css" rel="stylesheet">
+<link href="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css" rel="stylesheet">
 ```
 
 3\. Initialize:

+ 100 - 0
bin/upload-to-cdn.sh

@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+# Upload Uppy releases to Edgly.net CDN. Copyright (c) 2018, Transloadit Ltd.
+#
+# This file:
+#
+#  - Assumes EDGLY_KEY and EDGLY_SECRET are available (e.g. set via Travis secrets)
+#  - Tries to load env.sh instead, if not
+#  - Checks if a tag is being built (on Travis - otherwise opts to continue execution regardless)
+#  - Installs AWS CLI if needed
+#  - Assumed a fully built uppy is in root dir (unless a specific tag was specified, then it's fetched from npm)
+#  - Runs npm pack, and stores files to e.g. https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.css
+#  - Uses local package by default, if [version] argument was specified, takes package from npm
+#
+# Run as:
+#
+#  ./upload-to-cdn.sh [version]
+#
+# To upload all versions in one go (DANGER):
+#
+#  git tag |awk -Fv '{print "./bin/upload-to-cdn.sh "$2}' |bash
+#
+# Authors:
+#
+#  - Kevin van Zonneveld <kevin@transloadit.com>
+set -o pipefail
+set -o errexit
+set -o nounset
+# set -o xtrace
+
+# Set magic variables for current FILE & DIR
+__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
+__base="$(basename ${__file} .sh)"
+__root="$(cd "$(dirname "${__dir}")" && pwd)"
+
+function fatal () {
+  echo "❌ ${*}";
+  exit 1
+}
+
+pushd "${__root}" > /dev/null 2>&1
+  if [ -z "${EDGLY_KEY:-}" ] && [ -f ./env.sh ]; then
+    source ./env.sh
+  fi
+
+  [ -z "${EDGLY_KEY:-}" ] && fatal "Unable to find or source EDGLY_KEY env var"
+
+  if [ "${TRAVIS:-}" = "true" ]; then
+    if [ -z "${TRAVIS_TAG:-}" ]; then 
+      echo "On Travis (TRAVIS is '${TRAVIS}'), I'm only pushing releases to the CDN when a tag is being built (TRAVIS_TAG is '${TRAVIS_TAG}')"
+      exit 0;
+    fi
+  fi
+
+  type aws || pip install --user awscli
+
+  remoteVersion="${1:-}"
+  version="${remoteVersion}"
+  if [ -z "${remoteVersion}" ]; then 
+    localVersion=$(node -pe "require('./package.json').version")
+    echo "${localVersion}"
+    version="${localVersion}"
+  fi
+
+  echo -n "--> Check if not overwriting an existing tag ... "
+  env \
+    AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
+    AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
+  aws s3 ls \
+    --region="us-east-1" \
+  "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${version}/package.json" > /dev/null 2>&1 && fatal "Tag ${version} already exists"
+  echo "✅"
+
+  echo "--> Obtain relevant npm files for uppy ${version} ... "
+  if [ -z "${remoteVersion}" ]; then 
+    npm pack || fatal "Unable to fetch "
+  else 
+    npm pack "uppy@${remoteVersion}"
+  fi
+  echo "✅"
+  rm -rf /tmp/uppy-to-edgly
+  mkdir -p /tmp/uppy-to-edgly
+  cp -af "uppy-${version}.tgz" /tmp/uppy-to-edgly/
+  tar zxvf "uppy-${version}.tgz" -C /tmp/uppy-to-edgly/
+
+  echo "--> Upload to edgly.net CDN"
+  pushd /tmp/uppy-to-edgly/package 
+    # --delete \
+    env \
+      AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
+      AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
+    aws s3 sync \
+      --region="us-east-1" \
+      --exclude 'website/*' \
+      --exclude 'node_modules/*' \
+      --exclude 'examples/*/node_modules/*' \
+    ./ "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${version}"    
+  popd > /dev/null 2>&1
+  rm -rf /tmp/uppy-to-edgly
+popd > /dev/null 2>&1

+ 2 - 0
env.example.sh

@@ -8,6 +8,8 @@ export UPPYSERVER_GOOGLE_KEY="***"
 export UPPYSERVER_GOOGLE_SECRET="***"
 export UPPYSERVER_INSTAGRAM_KEY="***"
 export UPPYSERVER_INSTAGRAM_SECRET="***"
+export EDGLY_KEY="***"
+export EDGLY_SECRET="***"
 
 # Let's not set this by default, because that will make acceptance tests Always run on Saucelabs
 ## export SAUCE_ACCESS_KEY="***"

+ 2 - 2
examples/cdn-example/index.html

@@ -4,11 +4,11 @@
     <title></title>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link href="https://unpkg.com/uppy/dist/uppy.min.css" rel="stylesheet">
+    <link href="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css" rel="stylesheet">
   </head>
   <body>
     <button id="uppyModalOpener">Open Modal</button>
-    <script src="https://unpkg.com/uppy/dist/uppy.min.js"></script>
+    <script src="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.js"></script>
     <script>
       const uppy = Uppy.Core({debug: true, autoProceed: false})
         .use(Uppy.Dashboard, { trigger: '#uppyModalOpener' })

+ 1 - 0
package.json

@@ -162,6 +162,7 @@
     "web:preview": "npm-run-all --parallel web:examples:watch web:bundle:update:watch web:serve",
     "web:update:frontpage:code:sample": "cd website && ./node_modules/.bin/hexo generate && cp -f public/frontpage-code-sample.html ./themes/uppy/layout/partials/frontpage-code-sample.html",
     "web": "npm-run-all web:clean web:build",
+    "uploadcdn": "bin/upload-to-cdn.sh",
     "prepublishOnly": "npm-run-all clean build"
   }
 }

+ 3 - 3
website/src/docs/index.md

@@ -41,19 +41,19 @@ $ npm install uppy
 
 We recommend installing from NPM and then using a module bundler such as [Webpack](http://webpack.github.io/), [Browserify](http://browserify.org/) or [Rollup.js](http://rollupjs.org/).
 
-If you like, you can also use a pre-built bundle, for example from [unpkg CDN](https://unpkg.com/uppy/). In that case `Uppy` will attach itself to the global `window.Uppy` object.
+Alternatively, you can also use a pre-built bundle from Transloadit's CDN: Edgly. In that case `Uppy` will attach itself to the global `window.Uppy` object.
 
 > ⚠️ The bundle currently consists of most Uppy plugins, so this method is not recommended for production, as your users will have to download all plugins, even if you're only using a few of them.
 
 1\. Add a script to the bottom of `<body>`:
 
 ``` html
-<script src="https://unpkg.com/uppy"></script>
+<script src="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.js"></script>
 ```
 
 2\. Add CSS to `<head>`:
 ``` html
-<link href="https://unpkg.com/uppy/dist/uppy.min.css" rel="stylesheet">
+<link href="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css" rel="stylesheet">
 ```
 
 3\. Initialize:

+ 4 - 2
website/src/examples/i18n/app.html

@@ -1,9 +1,11 @@
-<!-- Basic Uppy styles. You can use a CDN: https://unpkg.com/uppy/dist/uppy.min.css -->
+<!-- Basic Uppy styles. You can use Transloadit's CDN, Edgly: 
+https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css -->
 <link rel="stylesheet" href="/uppy/uppy.min.css">
 
 <div class="UppyDragDrop"></div>
 
-<!-- Load Uppy pre-built bundled version. You can use a CDN: https://unpkg.com/uppy -->
+<!-- Load Uppy pre-built bundled version. You can use Transloadit's CDN, Edgly: 
+https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.js -->
 <script src="/uppy/uppy.min.js"></script>
 <script>
   var uppy = Uppy.Core({ debug: true });

+ 2 - 2
website/themes/uppy/layout/index.ejs

@@ -79,8 +79,8 @@
   <p>© <%- date(Date.now(), 'YYYY') %> <a href="https://transloadit.com" target="_blank">Transloadit</a></p>
 </footer>
 
-<link href="https://unpkg.com/uppy/dist/uppy.min.css" rel="stylesheet">
-<script src="https://unpkg.com/uppy/dist/uppy.min.js"></script>
+<link href="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.css" rel="stylesheet">
+<script src="https://transloadit.edgly.net/releases/uppy/v0.22.0/dist/uppy.min.js"></script>
 
 <script>
   var PROTOCOL = location.protocol === 'https:' ? 'https' : 'http'