-
Notifications
You must be signed in to change notification settings - Fork 14
/
deploy_ncm.js
61 lines (52 loc) · 1.89 KB
/
deploy_ncm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var deploy = require("deploy-azure-cdn");
var glob = require("glob");
// load environment variables from .env
if (require("fs").existsSync(".env")) {
require("dotenv").config();
}
// environment variables
var azure_account = process.env.AZURE_ACCOUNT,
azure_token = process.env.AZURE_TOKEN;
// global variables
var logger = console.log;
var opts = {
serviceOptions: [azure_account, azure_token], // custom arguments to azure.createBlobService
containerName: null, // container name in blob
containerOptions: {
publicAccessLevel: "blob"
}, // container options
folder: '', // path within container
deleteExistingBlobs: false, // true means recursively deleting anything under folder
concurrentUploadThreads: 2, // number of concurrent uploads, choose best for your network condition
zip: true, // gzip files if they become smaller after zipping, content-encoding header will change if file is zipped
metadata: {
cacheControl: 'public, max-age=31556926'
}, // metadata for each uploaded file
testRun: false // test run - means no blobs will be actually deleted or uploaded, see log messages for details
};
var mapFilesToDeploy = function (files) {
return files.map(function (item) {
return {
base: item.substring(0, 3),
path: item
};
});
};
var states = ["ac", "al", "am", "ap", "ba", "ce", "df", "es", "go", "ma", "mg",
"ms", "mt", "pa", "pb", "pe", "pi", "pr", "rj", "rn", "ro", "rr",
"rs", "sc", "se", "sp", "to"
];
states.forEach(function (state) {
// upload ncm json files
glob("ncm/" + state + "/*.json", null, function (er, files) {
opts.containerName = 'ncm';
deploy(opts, mapFilesToDeploy(files), logger, function (err) {
if (err) {
console.log('error: ncm upload job ' + state, err);
} else {
console.log('ok: ncm upload job ' + state);
}
});
console.log('queued jobs to state ' + state);
});
});