mup-aws-beanstalk
Version:
Deploy apps to AWS Elastic Beanstalk using Meteor Up
116 lines (96 loc) • 2.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ebVersions = ebVersions;
exports.s3Versions = s3Versions;
exports.largestVersion = largestVersion;
exports.largestEnvVersion = largestEnvVersion;
exports.oldEnvVersions = oldEnvVersions;
exports.oldVersions = oldVersions;
var _lodash = require("lodash");
var _aws = require("./aws");
var _utils = require("./utils");
async function ebVersions(api) {
const config = api.getConfig();
const versions = [0];
const {
app
} = (0, _utils.names)(config);
const appVersions = await _aws.beanstalk.describeApplicationVersions({
ApplicationName: app
}).promise();
if (appVersions.ApplicationVersions.length > 0) {
appVersions.ApplicationVersions.forEach(({
VersionLabel
}) => {
const parsedVersion = parseInt(VersionLabel, 10);
versions.push(parsedVersion);
});
}
return versions.sort((a, b) => b - a);
}
async function s3Versions(api, prefix) {
const config = api.getConfig();
const versions = [0];
const {
bucket,
bundlePrefix
} = (0, _utils.names)(config);
prefix = prefix || bundlePrefix;
const uploadedBundles = await _aws.s3.listObjectsV2({
Bucket: bucket,
Prefix: prefix
}).promise();
if (uploadedBundles.Contents.length > 0) {
uploadedBundles.Contents.forEach(bundle => {
const bundleVersion = parseInt(bundle.Key.split(prefix)[1], 10);
versions.push(bundleVersion);
});
}
return versions.sort((a, b) => b - a);
}
async function largestVersion(api) {
let [version] = await s3Versions(api);
const [appVersion] = await ebVersions(api);
if (appVersion > version) {
version = appVersion;
}
return version;
}
async function largestEnvVersion(api) {
const versions = [0];
const prefix = 'env/';
const config = api.getConfig();
const {
bucket: bucketName
} = (0, _utils.names)(config);
const uploadedBundles = await _aws.s3.listObjectsV2({
Bucket: bucketName,
Prefix: prefix
}).promise();
if (uploadedBundles.Contents.length > 0) {
uploadedBundles.Contents.forEach(bundle => {
const bundleVersion = parseInt(bundle.Key.split(prefix)[1], 10);
versions.push(bundleVersion);
});
}
return versions.sort((a, b) => b - a)[0];
}
async function oldEnvVersions(api) {
const keep = 10;
const versions = await s3Versions(api, 'env/');
return versions.slice(keep);
}
async function oldVersions(api) {
const keep = api.getConfig().app.oldVersions;
const appVersions = await ebVersions(api);
const bundleVersions = await s3Versions(api); // find unused bundles
const oldBundleVersions = (0, _lodash.difference)(bundleVersions, appVersions); // keep the 3 newest versions
const oldAppVersions = appVersions.slice(keep);
return {
bundles: oldBundleVersions,
versions: oldAppVersions
};
}
//# sourceMappingURL=versions.js.map
;