Skip to content

Commit

Permalink
Fix permissions on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumar-kailasam committed Apr 14, 2018
1 parent ff28b47 commit e911c07
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
tmp
.vscode
yarn-error.log
70 changes: 31 additions & 39 deletions lib/s3-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const ora = require('ora')
const http = require('http')
const https = require('https')
const humanSize = require('human-size')
const extendObj = require('lodash/merge')

// To increase s3's download & upload dir perf
http.globalAgent.maxSockets = https.globalAgent.maxSockets = 30
Expand All @@ -26,57 +25,51 @@ const jsonDocsDirDownloadOptions = {
}
}

const jsonDocsDirUploadOptions = extendObj(
{
s3Params: {
CacheControl: 'max-age=365000000, immutable',
GrantRead: 'uri=http://acs.amazonaws.com/groups/global/AllUsers'
}
},
jsonDocsDirDownloadOptions
)
const jsonDocsDirUploadOptions = {
localDir: 'tmp/json-docs',
s3Params: {
ACL: 'public-read',
Bucket: 'api-docs.emberjs.com',
CacheControl: 'max-age=365000000, immutable',
GrantRead: 'uri=http://acs.amazonaws.com/groups/global/AllUsers',
maxRetries: 5,
Prefix: 'json-docs'
}
}

const revDocsDirUploadOptions = {
localDir: 'tmp/rev-index',
s3Params: {
ACL: 'public-read',
Bucket: 'api-docs.emberjs.com',
Prefix: 'rev-index',
GrantRead: 'uri=http://acs.amazonaws.com/groups/global/AllUsers'
GrantRead: 'uri=http://acs.amazonaws.com/groups/global/AllUsers',
maxRetries: 5,
Prefix: 'rev-index'
}
}

const handleCompression = directory => Promise.resolve()
const handleDecompression = directory => Promise.resolve()

const syncDir = (operation, options) => {
return new Promise((resolve, reject) => {
let isDownload = operation === 'download'

let preSyncStep = !isDownload ? handleCompression(options.localDir) : Promise.resolve()

preSyncStep.then(() => {
let sync = isDownload ? client.downloadDir(options) : client.uploadDir(options)
let progressIndicator = ora(`${operation}ing ${options.s3Params.Prefix} docs`).start()
let sync = isDownload ? client.downloadDir(options) : client.uploadDir(options)
let progressIndicator = ora(`${operation}ing ${options.s3Params.Prefix} docs`).start()

sync.on('progress', () => {
const { progressAmount, progressTotal } = sync
progressIndicator.text = `${operation}ing json docs (${humanSize(
progressAmount
)} of ${humanSize(progressTotal)})`
})
sync.on('progress', () => {
const { progressAmount, progressTotal } = sync
progressIndicator.text = `${operation}ing json docs (${humanSize(
progressAmount
)} of ${humanSize(progressTotal)})`
})

sync.on('end', () => {
let postSyncStep = isDownload ? handleDecompression(options.localDir) : Promise.resolve()
postSyncStep.then(() => {
progressIndicator.succeed(`${operation}ed ${options.s3Params.Prefix} docs`)
resolve()
})
})
sync.on('end', () => {
progressIndicator.succeed(`${operation}ed ${options.s3Params.Prefix} docs`)
resolve()
})

sync.on('error', err => {
progressIndicator.fail()
reject(err)
})
sync.on('error', err => {
progressIndicator.fail()
reject(err)
})
})
}
Expand All @@ -90,9 +83,8 @@ module.exports.downloadExistingDocsToLocal = function downloadExistingDocsToLoca
syncDir('download', jsonDocsDirDownloadOptions),
syncDir('download', revDocsDirDownloadOptions)
])
} else {
console.log('Skipping download of pre-cached docs')
}
console.log('Skipping download of pre-cached docs')
return Promise.resolve()
}

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
"engines": {
"node": ">= 8"
},
"cacheDirectories": [
"tmp"
],
"cacheDirectories": ["tmp"],
"resolutions": {
"aws-sdk": "~2.224.1",
"graceful-fs": "^4.1.11"
}
}
98 changes: 80 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ assertion-error@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"

aws-sdk@~2.0.31:
version "2.0.31"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.0.31.tgz#e72cf1fdc69015bd9fd2bdf3d3b88c16507d268e"
dependencies:
xml2js "0.2.6"
xmlbuilder "0.4.2"
aws-sdk@~2.0.31, aws-sdk@~2.224.1:
version "2.224.1"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.224.1.tgz#82fe93e10b3e818f315c35ce8667cdc8db94a0b3"
dependencies:
buffer "4.9.1"
events "1.1.1"
ieee754 "1.1.8"
jmespath "0.15.0"
querystring "0.2.0"
sax "1.2.1"
url "0.10.3"
uuid "3.1.0"
xml2js "0.4.17"
xmlbuilder "4.2.1"

babel-code-frame@^6.22.0:
version "6.26.0"
Expand All @@ -98,6 +106,10 @@ balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"

base64-js@^1.0.2:
version "1.2.3"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.3.tgz#fb13668233d9614cf5fb4bce95a9ba4096cdf801"

boolbase@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand All @@ -117,6 +129,14 @@ buffer-from@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.0.0.tgz#4cb8832d23612589b0406e9e2956c17f06fdf531"

[email protected]:
version "4.9.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298"
dependencies:
base64-js "^1.0.2"
ieee754 "^1.1.4"
isarray "^1.0.0"

caller-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f"
Expand Down Expand Up @@ -441,6 +461,10 @@ esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"

external-editor@^2.0.4:
version "2.2.0"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.2.0.tgz#045511cfd8d133f3846673d1047c154e214ad3d5"
Expand Down Expand Up @@ -600,6 +624,14 @@ iconv-lite@^0.4.17:
dependencies:
safer-buffer "^2.1.0"

[email protected]:
version "1.1.8"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"

ieee754@^1.1.4:
version "1.1.11"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.11.tgz#c16384ffe00f5b7835824e67b6f2bd44a5229455"

ignore@^3.3.3, ignore@^3.3.6:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"
Expand Down Expand Up @@ -674,7 +706,7 @@ is-stream@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"

isarray@~1.0.0:
isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"

Expand All @@ -686,6 +718,10 @@ jest-docblock@^21.0.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414"

[email protected]:
version "0.15.0"
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217"

js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
Expand Down Expand Up @@ -848,7 +884,7 @@ lodash@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^4.15.0, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0:
lodash@^4.0.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0:
version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"

Expand Down Expand Up @@ -1045,6 +1081,14 @@ pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"

[email protected]:
version "1.3.2"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"

readable-stream@^2.0.2, readable-stream@^2.2.2:
version "2.3.6"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
Expand Down Expand Up @@ -1155,9 +1199,13 @@ safer-buffer@^2.1.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"

[email protected]:
version "0.4.2"
resolved "https://registry.yarnpkg.com/sax/-/sax-0.4.2.tgz#39f3b601733d6bec97105b242a2a40fd6978ac3c"
[email protected]:
version "1.2.1"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a"

sax@>=0.6.0:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

semver-extra@^2.0.1:
version "2.0.1"
Expand Down Expand Up @@ -1289,10 +1337,21 @@ universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"

[email protected]:
version "0.10.3"
resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64"
dependencies:
punycode "1.3.2"
querystring "0.2.0"

util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

[email protected]:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
Expand All @@ -1319,15 +1378,18 @@ write@^0.2.1:
dependencies:
mkdirp "^0.5.1"

xml2js@0.2.6:
version "0.2.6"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.2.6.tgz#d209c4e4dda1fc9c452141ef41c077f5adfdf6c4"
xml2js@0.4.17:
version "0.4.17"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.17.tgz#17be93eaae3f3b779359c795b419705a8817e868"
dependencies:
sax "0.4.2"
sax ">=0.6.0"
xmlbuilder "^4.1.0"

[email protected]:
version "0.4.2"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-0.4.2.tgz#1776d65f3fdbad470a08d8604cdeb1c4e540ff83"
[email protected], xmlbuilder@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-4.2.1.tgz#aa58a3041a066f90eaa16c2f5389ff19f3f461a5"
dependencies:
lodash "^4.0.0"

yallist@^2.1.2:
version "2.1.2"
Expand Down

0 comments on commit e911c07

Please sign in to comment.