This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
902 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Simple Hello World function | ||
|
||
This function returns the given data capitalizing the first word. | ||
|
||
```console | ||
$ npm install | ||
$ serverless deploy | ||
$ serverless invoke -f php-echo -l --data 'hello!' | ||
Serverless: Calling function: php-echo... | ||
-------------------------------------------------------------------- | ||
hello! | ||
$ serverless remove | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
function foo($event, $context) { | ||
return json_encode($event->data); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "php-echo", | ||
"version": "1.0.0", | ||
"description": "Example function for serverless kubeless", | ||
"dependencies": { | ||
"serverless-kubeless": "^0.7.0" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "Apache-2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
service: php-echo-s3 | ||
|
||
provider: | ||
name: kubeless | ||
runtime: php7.2 | ||
deploy: | ||
strategy: S3ZipContent | ||
options: | ||
accessKeyId: minio | ||
secretAccessKey: minio123 | ||
endpoint: http://10.98.211.80:9000 | ||
bucket: kubeless | ||
region: eu-central-1 | ||
s3ForcePathStyle: True | ||
|
||
plugins: | ||
- serverless-kubeless | ||
|
||
functions: | ||
php-echo-s3: | ||
handler: handler.foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2017 Bitnami. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
const Base64ZipContent = require('./strategy/base64_zip_content'); | ||
const S3ZipContent = require('./strategy/s3_zip_content'); | ||
|
||
const strategies = { | ||
Base64ZipContent, | ||
S3ZipContent, | ||
}; | ||
|
||
class KubelessDeployStrategy { | ||
constructor(serverless) { | ||
this.serverless = serverless; | ||
} | ||
|
||
factory() { | ||
const deploy = _.defaults({}, this.serverless.service.provider.deploy, { | ||
strategy: 'Base64ZipContent', | ||
options: {}, | ||
}); | ||
|
||
if (deploy.strategy in strategies) { | ||
return new strategies[deploy.strategy](this, deploy.options); | ||
} | ||
|
||
throw new Error(`Unknown deploy strategy "${deploy.strategy}"`); | ||
} | ||
} | ||
|
||
module.exports = KubelessDeployStrategy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2017 Bitnami. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const BbPromise = require('bluebird'); | ||
|
||
class Base64ZipContent { | ||
constructor(strategy, options) { | ||
this.strategy = strategy; | ||
this.options = options; | ||
} | ||
|
||
deploy(description, artifact) { | ||
return new BbPromise((resolve) => { | ||
const shasum = crypto.createHash('sha256'); | ||
const content = fs.readFileSync(artifact); | ||
|
||
shasum.update(content); | ||
|
||
resolve({ | ||
content: content.toString('base64'), | ||
checksum: `sha256:${shasum.digest('hex')}`, | ||
contentType: 'base64+zip', | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Base64ZipContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright 2017 Bitnami. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const AWS = require('aws-sdk'); | ||
const BbPromise = require('bluebird'); | ||
const shellescape = require('shell-escape'); | ||
|
||
class S3ZipContent { | ||
constructor(strategy, options) { | ||
this.strategy = strategy; | ||
this.options = options; | ||
} | ||
|
||
deploy(description, artifact) { | ||
const options = _.defaults({}, this.options, { | ||
expires: 60 * 60 * 24 * 365, | ||
}); | ||
return new BbPromise((resolve, reject) => { | ||
const shasum = crypto.createHash('sha256'); | ||
const content = fs.readFileSync(artifact); | ||
shasum.update(content); | ||
|
||
AWS.config.update(options, true); | ||
const s3 = new AWS.S3(); | ||
const Key = `${description.name}-${+(new Date())}.zip`; | ||
|
||
this.strategy.serverless.cli.log(`Uploading function ${description.name} as ${Key}`); | ||
|
||
return s3.putObject({ | ||
Key, | ||
Bucket: options.bucket, | ||
Body: fs.readFileSync(artifact), | ||
}).promise() | ||
.then(() => { | ||
const url = s3.getSignedUrl('getObject', { | ||
Key, | ||
Bucket: options.bucket, | ||
Expires: options.expires, | ||
}); | ||
|
||
// fixme: unescaped url in pkg/utils/kubelessutil.go:82 | ||
resolve({ | ||
content: shellescape([url]), | ||
checksum: `sha256:${shasum.digest('hex')}`, | ||
contentType: 'url+zip', | ||
}); | ||
}, reject); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = S3ZipContent; |
Oops, something went wrong.