Skip to content

Commit 347fef4

Browse files
authored
Merge pull request #11 from karnafun/master
Adding serverless support for dotnet6
2 parents 8b0ac96 + 4b11d69 commit 347fef4

File tree

5 files changed

+2302
-2968
lines changed

5 files changed

+2302
-2968
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ package:
1818
```
1919
It equivalent to going into functionproject-folder and executing dotnet lambda package -o publish/deploy-package.zip
2020

21+
If you want to execute serverless deploy for dotnet 6, you should add to serverless.yml: provider.runtime=dotnet6
22+
23+
If you want to execute serverless deploy for arm64 architecture, you should add to serverless.yml: provider.architecture=arm64
24+
2125
If you want to execute serverless deploy with no repacking of C# projects, you should add --nopack option
2226

2327
As of version 0.9, the plugin now supports supplying a projectFolder setting for scenarios when a more complex folder structure is needed.

index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ class ServerlessDotNet {
99
constructor(serverless, options) {
1010
this.serverless = serverless;
1111
this.options = options;
12-
13-
if(!options["nopack"]){
14-
15-
Object.assign( this, pack );
16-
Object.assign( this, getPackingInfo );
17-
Object.assign( this, funcRuntimeIsDotNet )
18-
12+
if (!options["nopack"]) {
13+
Object.assign(this, pack);
14+
Object.assign(this, getPackingInfo);
15+
Object.assign(this, funcRuntimeIsDotNet);
1916
this.hooks = {
2017
'package:createDeploymentArtifacts': () => BbPromise.bind(this).then(this.pack)
2118
};
22-
}
19+
}
2320
}
2421
}
2522

lib/pack.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
const BbPromise = require('bluebird');
44
const program = require('child_process');
55

6+
function getLambdaPackageFlags(service) {
7+
8+
let myFramework = '';
9+
var frameworkList = {
10+
"dotnet6": "net6.0" //can add more mappings for more support
11+
};
12+
if (service.provider.runtime && frameworkList[service.provider.runtime]) {
13+
myFramework = ' -f ' + frameworkList[service.provider.runtime];
14+
}
15+
let architecture = '';
16+
if (service.provider.architecture) {
17+
architecture = ' -farch ' + service.provider.architecture
18+
}
19+
return architecture + myFramework;
20+
}
621
module.exports = {
722

823
getPackingInfo() {
9-
1024
let service = this.serverless.service;
11-
1225
const packages = service.getAllFunctions().reduce((dotnetPackages, funcName) => {
1326
let func = service.getFunction(funcName);
1427

@@ -18,14 +31,14 @@ module.exports = {
1831

1932
return dotnetPackages;
2033
}, [])
21-
34+
2235
let dicArtifacts = {};
2336

2437
packages.forEach(p => {
2538

2639
const projectFolder = p.projectFolder || "";
2740
// Validate artifact starts with project folder
28-
if (projectFolder && !p.artifact.startsWith(projectFolder)){
41+
if (projectFolder && !p.artifact.startsWith(projectFolder)) {
2942
const error = `Serverless DotNet: function/package/projectFolder '${projectFolder}' is defined and should be root of function/package/artifact path '${p.artifact}'. Pleas update your configuration...`;
3043
throw new Error(error);
3144
}
@@ -39,10 +52,6 @@ module.exports = {
3952
// subtract project folder from the artifact path
4053
let artifactLessProjectFolderParts = [...artifactPathParts];
4154
artifactLessProjectFolderParts.splice(0, cwdParts.length);
42-
// console.log('artifact: ' +p.artifact);
43-
// console.log('artifact parts: ' +artifactPathParts);
44-
// console.log('cwd parts: ' +cwdParts);
45-
// console.log('artifact less cwd parts: ' +artifactLessProjectFolderParts);
4655

4756
dicArtifacts[p.artifact] = {
4857
currentWorkingDir: cwd,
@@ -61,33 +70,33 @@ module.exports = {
6170
if (!providerRuntime && !funcRuntime) {
6271
console.error('No runtime found at global provider or local function level, eg. dotnetcore2.1')
6372
}
64-
73+
6574
return (providerRuntime && providerRuntime.startsWith('dotnet') && !funcRuntime)
66-
|| (funcRuntime && funcRuntime.startsWith('dotnet'))
67-
|| (!providerRuntime && funcRuntime && funcRuntime.startsWith('dotnet'));
75+
|| (funcRuntime && funcRuntime.startsWith('dotnet'))
76+
|| (!providerRuntime && funcRuntime && funcRuntime.startsWith('dotnet'));
6877
},
6978

7079
pack() {
7180
let cli = this.serverless.cli;
81+
let flags = getLambdaPackageFlags(this.serverless.service)
7282
cli.log('Serverless DotNet: Pack');
73-
7483
const dicArtifacts = this.getPackingInfo();
75-
7684
var promises = Object.entries(dicArtifacts).map(kv => {
7785
return new BbPromise(function (resolve, reject) {
7886

7987
try {
8088
const packingInfo = kv[1];
8189

82-
var output=program.execSync('dotnet lambda package -o ' + packingInfo.artifactOutput, { "cwd": packingInfo.currentWorkingDir }, function (error, stdout, stderr) {
83-
//console.log(stdout);
90+
var output = program.execSync('dotnet lambda package ' + flags + ' -o ' + packingInfo.artifactOutput, { "cwd": packingInfo.currentWorkingDir }, function (error, stdout, stderr) {
91+
console.log(output)
8492
cli.log(stdout);
8593

8694
if (error) {
8795
console.error('An error occured while restoring packages');
88-
console.error(stderr.toString('utf8'));
89-
process.exit(error.code);
90-
return reject(error);
96+
console.error(err.stdout.toString('utf8'));
97+
console.error(err.toString('utf8'));
98+
process.exit();
99+
return reject(err);
91100
}
92101

93102
console.log('Publishing');
@@ -96,7 +105,7 @@ module.exports = {
96105
});
97106

98107
cli.log(output);
99-
return resolve();
108+
return resolve();
100109
} catch (err) {
101110
console.error('An error occured while restoring packages');
102111
console.error(err.stdout.toString('utf8'));

0 commit comments

Comments
 (0)