Skip to content

Commit

Permalink
Add set content type script (#1897)
Browse files Browse the repository at this point in the history
* Add set content type script

* Add entry

* Add credit
  • Loading branch information
compulim authored and cwhitten committed Apr 15, 2019
1 parent 79c39e5 commit f6f23df
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added something, by [@johndoe](https://github.com/johndoe), in PR [#XXX](https://github.com/Microsoft/BotFramework-WebChat/pull/XXX)
### Changed (for dependency bumps)
- `core`: Bumps to [`abc@1.2.3`](https://npmjs.com/package/abc/), in PR [#XXX](https://github.com/Microsoft/BotFramework-WebChat/pull/XXX)
- `core`: Bumps to [`abc@1.2.3`](https://npmjs.com/package/abc/), by [@johndoe](https://github.com/johndoe), in PR [#XXX](https://github.com/Microsoft/BotFramework-WebChat/pull/XXX)
### Fixed
- Fix [#XXX](https://github.com/Microsoft/BotFramework-WebChat/issues/XXX). Patched something, by [@johndoe](https://github.com/johndoe) in PR [#XXX](https://github.com/Microsoft/BotFramework-WebChat/pull/XXX)
Expand All @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed
- Added handling of reconnection, by [@compulim](https://github.com/compulim), in PR [#1880](https://github.com/Microsoft/BotFramework-WebChat/pull/1880)
- Deployment: Bumps to [`blobxfer@1.7.1`](https://github.com/azure/blobxfer/), by [@compulim](https://github.com/compulim), in PR [#1897](https://github.com/Microsoft/BotFramework-WebChat/pull/1897)
- Deployment: Adds `charset` to content type of JavaScript files on CDN, by [@compulim](https://github.com/compulim), in PR [#1897](https://github.com/Microsoft/BotFramework-WebChat/pull/1897)

### Fixed
- Fix [#1423](https://github.com/Microsoft/BotFramework-WebChat/issues/1423). Added sample for hosting WebChat in Angular, by [@omarsourour](https://github.com/omarsourour) in PR [#1813](https://github.com/Microsoft/BotFramework-WebChat/pull/1813)
Expand Down
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"watch": "lerna run --parallel --scope=botframework-webchat* --stream watch"
},
"devDependencies": {
"@azure/storage-blob": "^10.3.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
Expand Down
5 changes: 4 additions & 1 deletion scripts/deploy_cdn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Install blobxfer
curl -L -o ~/blobxfer https://github.com/Azure/blobxfer/releases/download/1.2.1/blobxfer-1.2.1-linux-x86_64
curl -L -o ~/blobxfer https://github.com/Azure/blobxfer/releases/download/1.7.1/blobxfer-1.7.1-linux-x86_64
chmod +x ~/blobxfer

PACKAGE_NAME=$(node -p require\(\'$TRAVIS_BUILD_DIR/packages/bundle/package.json\'\).name)
Expand All @@ -10,17 +10,20 @@ echo Will publish to CDN at $PACKAGE_NAME/$PACKAGE_VERSION/*

# Upload to based on version from package.json
~/blobxfer upload --local-path $TRAVIS_BUILD_DIR/packages/bundle/dist --remote-path $PACKAGE_NAME/$PACKAGE_VERSION --storage-account $CDN_BLOB_ACCOUNT --storage-account-key $CDN_BLOB_KEY
node ./setJavaScriptContentType.js $CDN_BLOB_ACCOUNT $CDN_BLOB_KEY $PACKAGE_NAME $PACKAGE_VERSION/

# If TRAVIS_TAG is present, it means this is going PRODUCTION
if [ -n "$TRAVIS_TAG" ]
then
# Upload to /latest/
~/blobxfer upload --local-path $TRAVIS_BUILD_DIR/packages/bundle/dist --remote-path $PACKAGE_NAME/latest --storage-account $CDN_BLOB_ACCOUNT --storage-account-key $CDN_BLOB_KEY
node ./setJavaScriptContentType.js $CDN_BLOB_ACCOUNT $CDN_BLOB_KEY $PACKAGE_NAME latest/
fi

# If on "master" branch, deploy to "master" tag too
if [ "$TRAVIS_BRANCH" = "master" ]
then
# Upload to /master/
~/blobxfer upload --local-path $TRAVIS_BUILD_DIR/packages/bundle/dist --remote-path $PACKAGE_NAME/master --storage-account $CDN_BLOB_ACCOUNT --storage-account-key $CDN_BLOB_KEY
node ./setJavaScriptContentType.js $CDN_BLOB_ACCOUNT $CDN_BLOB_KEY $PACKAGE_NAME master/
fi
57 changes: 57 additions & 0 deletions scripts/setJavaScriptContentType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { extname } = require('path');

const {
Aborter,
BlobURL,
ContainerURL,
ServiceURL,
SharedKeyCredential,
StorageURL
} = require('@azure/storage-blob');

const BLOB_DELIMITER = '/';
const BLOB_OPERATION_TIMEOUT = 15000;
const TARGET_EXTNAME = '.js';
const TARGET_CONTENT_TYPE = 'text/javascript; charset=utf-8';

async function main(accountName, accountKey, container, prefix) {
const containerURL = ContainerURL.fromServiceURL(
new ServiceURL(
`https://${ accountName }.blob.core.windows.net`,
StorageURL.newPipeline(new SharedKeyCredential(accountName, accountKey))
),
container
);

const { segment } = await containerURL.listBlobHierarchySegment(
Aborter.timeout(BLOB_OPERATION_TIMEOUT),
BLOB_DELIMITER,
null,
{ prefix }
);

console.log([
`Found ${ segment.blobItems.length } blob in container "${ container }" with prefix "${ prefix || '' }"`,
...segment.blobItems.map(({ name, properties: { contentLength } }) => ` ${ name } (${ contentLength } bytes)`),
''
].join('\n'));

await Promise.all(
segment.blobItems
.filter(({ name }) => extname(name) === TARGET_EXTNAME)
.map(async ({ name }) => {
console.log(`Setting content type for blob "${ name }"`);

const blobURL = BlobURL.fromContainerURL(containerURL, name);

await blobURL.setHTTPHeaders(
Aborter.timeout(BLOB_OPERATION_TIMEOUT),
{
blobContentType: TARGET_CONTENT_TYPE
}
)
})
);
}

main(...process.argv.slice(2)).catch(err => console.error(err));

0 comments on commit f6f23df

Please sign in to comment.