Skip to content

added functionality to autogenerate artifact name #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ BbPromise.promisifyAll(Fse);
class PkgPyFuncs {

fetchConfig(){

if (!this.serverless.service.custom){
this.error("No serverless custom configurations are defined")
}
Expand All @@ -36,6 +35,14 @@ class PkgPyFuncs {
this.dockerServicePath = '/var/task'
}

autoconfigArtifacts() {
_.map(this.serverless.service.functions, (func_config, func_name) => {
let autoArtifact = `${this.buildDir}/${func_name}.zip`
func_config.package.artifact = func_config.package.artifact || autoArtifact
this.serverless.service.functions[func_name] = func_config
})
}

clean(){
if (!this.cleanup) {
this.log('Cleanup is set to "false". Build directory and Docker container (if used) will be retained')
Expand All @@ -58,15 +65,17 @@ class PkgPyFuncs {
});

const info = _.map(functions, (target) => {


return {
name: target.name,
includes: target.package.include
includes: target.package.include,
artifact: target.package.artifact
}
})
return info
}


installRequirements(buildPath,requirementsPath){

if ( !Fse.pathExistsSync(requirementsPath) ) {
Expand Down Expand Up @@ -118,11 +127,11 @@ class PkgPyFuncs {
this.log('Container already exists. Reusing.')
} else {
let args = ['run', '--rm', '-dt', '-v', `${process.cwd()}:${this.dockerServicePath}`]

if (this.mountSSH) {
args = args.concat(['-v', `${process.env.HOME}/.ssh:/root/.ssh`])
}

args = args.concat(['--name',this.containerName, this.dockerImage, 'bash'])
this.runProcess('docker', args)
this.log('Container created')
Expand Down Expand Up @@ -171,14 +180,20 @@ class PkgPyFuncs {
zipper.sync.zip(buildPath).compress().save(`${buildPath}.zip`)
}



constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.log = (msg) => { this.serverless.cli.log(`[serverless-package-python-functions] ${msg}`) }
this.error = (msg) => { throw new Error(`[serverless-package-python-functions] ${msg}`) }



this.hooks = {
'before:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.fetchConfig)
.then(this.autoconfigArtifacts)
.then( () => { Fse.ensureDirAsync(this.buildDir) })
.then(this.setupDocker)
.then(this.selectAll)
Expand Down