forked from justinram11/serverless-aws-batch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
66 lines (55 loc) · 2.69 KB
/
index.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
62
63
64
65
66
'use strict';
const BbPromise = require('bluebird');
const fse = require('fs-extra');
const generateCoreTemplate = require('./lib/generateCoreTemplate');
const ecr = require('./lib/ecr');
const docker = require('./lib/docker');
const batchenvironment = require('./lib/batchenvironment');
const batchtask = require('./lib/batchtask');
const awscli = require('./lib/awscli');
const _ = require('lodash');
BbPromise.promisifyAll(fse);
class ServerlessAWSBatch {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.provider = this.serverless.getProvider('aws');
// Make sure that we add the names for our ECR, docker, and batch resources to the provider
_.merge(
this.provider.naming,
{
'getECRLogicalId': ecr.getECRLogicalId,
'getECRRepositoryName': ecr.getECRRepositoryName,
'getECRRepositoryURL': ecr.getECRRepositoryURL,
'getDockerImageName': docker.getDockerImageName,
'getBatchServiceRoleLogicalId': batchenvironment.getBatchServiceRoleLogicalId,
'getBatchInstanceManagementRoleLogicalId': batchenvironment.getBatchInstanceManagementRoleLogicalId,
'getBatchInstanceManagementProfileLogicalId': batchenvironment.getBatchInstanceManagementProfileLogicalId,
'getBatchSpotFleetManagementRoleLogicalId': batchenvironment.getBatchSpotFleetManagementRoleLogicalId,
'getBatchJobExecutionRoleLogicalId': batchtask.getBatchJobExecutionRoleLogicalId,
'getLambdaScheduleExecutionRoleLogicalId': batchenvironment.getLambdaScheduleExecutionRoleLogicalId,
'getBatchComputeEnvironmentLogicalId': batchenvironment.getBatchComputeEnvironmentLogicalId,
'getBatchJobQueueLogicalId': batchenvironment.getBatchJobQueueLogicalId,
'getBatchJobQueueName': batchenvironment.getBatchJobQueueName,
'getJobDefinitionLogicalId': batchtask.getJobDefinitionLogicalId
}
);
// Define inner lifecycles
this.commands = {}
this.hooks = {
'after:package:initialize': () => BbPromise.bind(this)
.then(generateCoreTemplate.generateCoreTemplate),
'before:package:compileFunctions': () => BbPromise.bind(this)
.then(batchenvironment.validateAWSBatchServerlessConfig)
.then(batchenvironment.generateAWSBatchTemplate)
.then(batchtask.compileBatchTasks),
'after:package:finalize': () => BbPromise.bind(this)
.then(docker.buildDockerImage),
'before:aws:deploy:deploy:uploadArtifacts': () => BbPromise.bind(this)
.then(docker.pushDockerImageToECR),
'before:remove:remove': () => BbPromise.bind(this)
.then(awscli.deleteAllDockerImagesInECR)
}
}
}
module.exports = ServerlessAWSBatch;