Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ The configuration includes the following parameters:
* `runtime`: (Optional) runtime of the function, if you need to deploy multiple functions with different runtimes in your Serverless Project. If absent, `provider.runtime` will be used to deploy the function, see [this example project](./examples/multiple).
* `events` (Optional): List of events to trigger your functions (e.g, trigger a function based on a schedule with `CRONJobs`). See `events` section below
* `custom_domains` (Optional): List of custom domains, refer to the [how to add a custom domain](https://www.scaleway.com/en/docs/compute/functions/how-to/add-a-custom-domain-name-to-a-function/) documentation page
* `httpOption` (Optional): force https redirection, possible values are `enabled` and `redirected` (default: `enabled`)

### Security and secret management

Expand Down Expand Up @@ -419,7 +420,7 @@ If `singleSource` is set to `true`, functions and containers not defined in your
- You have [created a Container Registry namespace](https://www.scaleway.com/en/docs/compute/container-registry/how-to/create-namespace/)
- You have installed Docker and can build and push your image to your registry.

To manafge your containers, you must first define them in the `custom.containers` field in your `serverless.yml` configuration file.
To manage your containers, you must first define them in the `custom.containers` field in your `serverless.yml` configuration file.

Each container must specify the relative path of its application directory (containing the Dockerfile, and all files related to the application to deploy):

Expand Down
2 changes: 2 additions & 0 deletions deploy/lib/createContainers.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = {
timeout: container.timeout,
privacy: container.privacy,
port: container.port,
http_option: container.httpOption,
};

// checking if there is custom_domains set on container creation.
Expand Down Expand Up @@ -121,6 +122,7 @@ module.exports = {
timeout: container.timeout,
privacy: container.privacy,
port: container.port,
http_option: container.httpOption,
};

this.serverless.cli.log(`Updating container ${container.name}...`);
Expand Down
2 changes: 2 additions & 0 deletions deploy/lib/createFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Runtime lifecycle doc : https://www.scaleway.com/en/docs/compute/functions/refer
handler: func.handler,
privacy: func.privacy,
domain_name: func.domain_name,
http_option: func.httpOption,
};

const availableRuntimes = await this.listRuntimes();
Expand Down Expand Up @@ -205,6 +206,7 @@ Runtime lifecycle doc : https://www.scaleway.com/en/docs/compute/functions/refer
handler: func.handler,
privacy: func.privacy,
domain_name: func.domain_name,
http_option: func.httpOption,
};

const availableRuntimes = await this.listRuntimes();
Expand Down
2 changes: 1 addition & 1 deletion examples/container-schedule/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
1 change: 1 addition & 0 deletions examples/container-schedule/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ custom:
# maxScale: 2
# maxConcurrency: 50
# timeout: 20000
# httpOption: redirected
# Local environment variables - used only in given function
env:
local: local
2 changes: 1 addition & 1 deletion examples/container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
1 change: 1 addition & 0 deletions examples/container/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ custom:
# maxConcurrency: 50
# timeout: 20000
# port: 8080
# httpOption: redirected
# Local environment variables - used only in given function
env:
local: local
2 changes: 1 addition & 1 deletion examples/go/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
2 changes: 1 addition & 1 deletion examples/go113/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
2 changes: 1 addition & 1 deletion examples/multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
2 changes: 1 addition & 1 deletion examples/nodejs-es-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
2 changes: 1 addition & 1 deletion examples/nodejs-schedule/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
2 changes: 1 addition & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
1 change: 1 addition & 0 deletions examples/nodejs/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package:
functions:
first:
handler: handler.handle
httpOption: redirected
# description: ""
# Local environment variables - used only in given function
env:
Expand Down
2 changes: 1 addition & 1 deletion examples/python3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {},
"devDependencies": {
"serverless-scaleway-functions": "^0.4.4"
"serverless-scaleway-functions": "^0.4.5"
},
"description": ""
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-scaleway-functions",
"version": "0.4.4",
"version": "0.4.5",
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Scaleway Functions.",
"main": "index.js",
"author": "scaleway.com",
Expand Down
36 changes: 34 additions & 2 deletions tests/functions/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { expect } = require('chai');
const { expect: jestExpect, it } = require('@jest/globals');

const { getTmpDirPath, replaceTextInFile } = require('../utils/fs');
const { getServiceName, sleep, serverlessDeploy, serverlessRemove} = require('../utils/misc');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE was signalling a text convention error, so I had to break it down into two lines

const { getServiceName, sleep } = require('../utils/misc');
const { serverlessDeploy, serverlessRemove } = require('../utils/misc');
const { FunctionApi, RegistryApi } = require('../../shared/api');
const { FUNCTIONS_API_URL, REGISTRY_API_URL } = require('../../shared/constants');
const { execSync, execCaptureOutput } = require('../../shared/child-process');
Expand All @@ -18,6 +19,8 @@ const serverlessExec = path.join('serverless');
const stringIdentifier = '# second-function-identifier';
const serverlessFile = 'serverless.yml';
const descriptionTest = 'slsfw test description';
const redirectedHttpOptionTest = 'redirected';
const enabledHttpOptionTest = 'enabled';

describe('Service Lifecyle Integration Test', () => {
const templateName = path.resolve(__dirname, '..', '..', 'examples', 'nodejs');
Expand Down Expand Up @@ -62,6 +65,7 @@ describe('Service Lifecyle Integration Test', () => {
namespace = await api.getNamespaceFromList(serviceName, scwProject);
namespace.functions = await api.listFunctions(namespace.id);
expect(namespace.functions[0].description).to.be.equal(descriptionTest);
expect(namespace.functions[0].http_option).to.be.equal(redirectedHttpOptionTest);
functionName = namespace.functions[0].name;
});

Expand Down Expand Up @@ -97,13 +101,18 @@ module.exports.handle = (event, context, cb) => {
fs.appendFileSync(`${tmpDir}/${serverlessFile}`, appendData);

serverlessDeploy();
namespace = await api.getNamespaceFromList(serviceName, scwProject);
namespace.functions = await api.listFunctions(namespace.id);
expect(namespace.functions.length).to.be.equal(2);
expect(namespace.functions[0].http_option).to.be.equal(redirectedHttpOptionTest);
expect(namespace.functions[1].http_option).to.be.equal(enabledHttpOptionTest);
});

it('should invoke first and second function', async () => {
const outputInvoke = execCaptureOutput(serverlessExec, ['invoke', '--function', namespace.functions[0].name]);
expect(outputInvoke).to.be.equal('{"message":"Serverless Update Succeeded"}');

const outputInvokeSecond = execCaptureOutput(serverlessExec, ['invoke', '--function', 'second']);
const outputInvokeSecond = execCaptureOutput(serverlessExec, ['invoke', '--function', namespace.functions[1].name]);
expect(outputInvokeSecond).to.be.equal('{"message":"Serverless Update Succeeded"}');
});

Expand All @@ -116,6 +125,9 @@ module.exports.handle = (event, context, cb) => {

// redeploy, func 2 should be removed
serverlessDeploy();
namespace = await api.getNamespaceFromList(serviceName, scwProject);
namespace.functions = await api.listFunctions(namespace.id);
expect(namespace.functions.length).to.be.equal(1);

const outputInvoke = execCaptureOutput(serverlessExec, ['invoke', '--function', namespace.functions[0].name]);
expect(outputInvoke).to.be.equal('{"message":"Serverless Update Succeeded"}');
Expand All @@ -124,6 +136,16 @@ module.exports.handle = (event, context, cb) => {
expect(outputInvokeSecond.startsWith('Error')).to.be.equal(true);
});

it('should deploy function with https redirection disabled', async () => {
replaceTextInFile(serverlessFile, redirectedHttpOptionTest, enabledHttpOptionTest);

// redeploy
serverlessDeploy();
namespace = await api.getNamespaceFromList(serviceName, scwProject);
namespace.functions = await api.listFunctions(namespace.id);
expect(namespace.functions[0].http_option).to.be.equal(enabledHttpOptionTest);
});

it('should invoke updated function from scaleway', async () => {
await sleep(30000);

Expand Down Expand Up @@ -188,6 +210,16 @@ def handle(event, context):
} catch (err) {
// if not try catch, test would fail
}
replaceTextInFile(serverlessFile, 'doesnotexist', 'node16');
});

it('should throw error unknown value on field http_option', () => {
replaceTextInFile(serverlessFile, enabledHttpOptionTest, 'random');
try {
expect(serverlessDeploy()).rejects.toThrow(Error);
} catch (err) {
// if not try catch, test would fail
}
});
});

Expand Down