Skip to content

Commit e860f24

Browse files
committed
Merge branch 'master' of github.com:softprops/serverless-rust into bin-target
2 parents 307c9aa + d22712d commit e860f24

File tree

8 files changed

+1960
-5383
lines changed

8 files changed

+1960
-5383
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ language: node_js
22
node_js:
33
- "node"
44

5+
# only build pushes to master
6+
# prs are build separately
7+
# https://docs.travis-ci.com/user/pull-requests/#how-pull-requests-are-built
8+
branches:
9+
only:
10+
- master
11+
512
services:
613
# start docker to enable lambda ci compatible build env
714
- docker

CHANGELOG.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
1+
# ⚡ 0.2.2
2+
3+
- bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.2.1-rust-1.32.0, fixing a bug where cargo binaries named `bootstrap` weren't getting packaged. Reminder: this plugin renames binaries to `bootstrap` for the lambda runtime for you. You don't have do to this manually in your Cargo configuration. This also introduces an effiency in the way binaries are identified for packaging that may help some windows users.
4+
- bump serverless version to [`1.37.1`](https://github.com/serverless/serverless/releases/tag/v1.37.1)
5+
6+
7+
# ⚡ 0.2.1
8+
9+
- bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.2.0-rust-1.32.0, to make the new default Rust 1.32.0 (the latest release of Rust at this time)
10+
- bump serverless version to [`1.36.3`](https://github.com/serverless/serverless/releases/tag/v1.36.3)
11+
112
# ⚡ 0.2.0
213

3-
* Switch from supporting the Lambda `python3.6` runtime to a new ✨ `rust` runtime ✨ ( which runs on the `provided` runtime under the covers )
4-
* you can now deploy independent functions with `npx serverless deploy function -f func-name`
5-
* you no longer have to be explicit about function binary to include, this plugin generates and configures the artifact (zip) file for you
6-
* you no longer have to set default exclusion rules
7-
* you can deploy a `rust` runtime function side by side with other serverless runtime functions
8-
within the same service, to facilitate experimentation and learning.
14+
- Switch from supporting the Lambda `python3.6` runtime to a new ✨ `rust` runtime ✨ ( which runs on the `provided` runtime under the covers )
15+
- you can now deploy independent functions with `npx serverless deploy function -f func-name`
16+
- you no longer have to be explicit about function binary to include, this plugin generates and configures the artifact (zip) file for you
17+
- you no longer have to set default exclusion rules
18+
- you can deploy a `rust` runtime function side by side with other serverless runtime functions
19+
within the same service, to facilitate experimentation and learning.
920

1021
# ⚡ 0.1.7
1122

12-
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.1.0-rust-1.30.1, to make the new default Rust 1.30.1 (the latest release of Rust at this time)
13-
* bumb serverless version to [1.33.2](https://github.com/serverless/serverless/blob/master/CHANGELOG.md#1332-18112018) ( the latest serverless release at this time)
23+
- bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.1.0-rust-1.30.1, to make the new default Rust 1.30.1 (the latest release of Rust at this time)
24+
- bump serverless version to [1.33.2](https://github.com/serverless/serverless/blob/master/CHANGELOG.md#1332-18112018) ( the latest serverless release at this time)
1425

1526
# ⚡ 0.1.6
1627

17-
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.1.0-rust-1.28.0, to make the new default Rust 1.28.0 (the latest release of Rust at this time)
28+
- bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.1.0-rust-1.28.0, to make the new default Rust 1.28.0 (the latest release of Rust at this time)
1829

1930
# ⚡ 0.1.5
2031

21-
* ensure only a unique set of artifacts are collected for cleanup
22-
* Allocate a docker pseudo-tty so that process signals are forwarded (Keyboard interrupts stop docker process)
32+
- ensure only a unique set of artifacts are collected for cleanup
33+
- Allocate a docker pseudo-tty so that process signals are forwarded (Keyboard interrupts stop docker process)
2334

2435
# ⚡ 0.1.4
2536

26-
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.1.0-rust-1.27.2, to make the new default Rust 1.27.2 (the latest release of Rust at this time)
27-
* speed up deployments by ~3.2 seconds by disabling excludeDevDependencies. it's on by default but it's not useful for for Rust focused services
28-
* the `custom.rust` config object can be overrided at the function level
37+
- bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.1.0-rust-1.27.2, to make the new default Rust 1.27.2 (the latest release of Rust at this time)
38+
- speed up deployments by ~3.2 seconds by disabling excludeDevDependencies. it's on by default but it's not useful for for Rust focused services
39+
- the `custom.rust` config object can be overrided at the function level
2940

3041
```yaml
3142
functions:
3243
hello:
3344
rust:
34-
cargoFlags: '--features ...'
45+
cargoFlags: "--features ..."
3546
handler: liblambda.handler
3647
package:
3748
include:
@@ -42,17 +53,17 @@ functions:
4253
4354
# ⚡ 0.1.3
4455
45-
* bump lambda rust docker version to 0.1.0-rust-1.27.0
56+
- bump lambda rust docker version to 0.1.0-rust-1.27.0
4657
4758
# ⚡ 0.1.2
4859
49-
* bump lambda rust docker version to 0.1.0-rust-1.26.2
50-
* use a polyfill for fs.copyFileSync to accomidate older versions of node on travis ci
60+
- bump lambda rust docker version to 0.1.0-rust-1.26.2
61+
- use a polyfill for fs.copyFileSync to accomidate older versions of node on travis ci
5162
5263
# ⚡ 0.1.1
5364
54-
* fix exporting plugin
65+
- fix exporting plugin
5566
5667
# ⚡ 0.1.0
5768
58-
* initial release
69+
- initial release

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ functions:
3939
method: GET
4040
```
4141
42+
> 💡 The Rust Lambda runtime requires a binary named `bootstrap`. This plugin renames the binary cargo builds to `bootstrap` for you before packaging. You do not need to do this manually in your Cargo configuration.
4243

4344
## 🖍️ customize
4445

index.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
'use strict';
1+
"use strict";
22

33
// https://serverless.com/blog/writing-serverless-plugins/
44
// https://serverless.com/framework/docs/providers/aws/guide/plugins/
55
// https://github.com/softprops/lambda-rust/
66

7-
const { spawnSync } = require('child_process');
8-
const path = require('path');
7+
const { spawnSync } = require("child_process");
8+
const path = require("path");
99

10-
const DEFAULT_DOCKER_TAG = '0.2.0-rust-1.31.0';
11-
const RUST_RUNTIME = 'rust';
12-
const BASE_RUNTIME = 'provided';
13-
const NO_OUTPUT_CAPTURE = { stdio: ['ignore', process.stdout, process.stderr] };
10+
const DEFAULT_DOCKER_TAG = "0.2.1-rust-1.32.0";
11+
const RUST_RUNTIME = "rust";
12+
const BASE_RUNTIME = "provided";
13+
const NO_OUTPUT_CAPTURE = { stdio: ["ignore", process.stdout, process.stderr] };
1414

1515
/** assumes docker is on the host's execution path */
1616
class RustPlugin {
1717
constructor(serverless, options) {
18-
1918
this.serverless = serverless;
2019
this.options = options;
21-
this.servicePath = this.serverless.config.servicePath || '';
20+
this.servicePath = this.serverless.config.servicePath || "";
2221
this.hooks = {
23-
'before:package:createDeploymentArtifacts': this.build.bind(this),
24-
'before:deploy:function:packageFunction': this.build.bind(this),
22+
"before:package:createDeploymentArtifacts": this.build.bind(this),
23+
"before:deploy:function:packageFunction": this.build.bind(this)
2524
};
2625
this.custom = Object.assign(
2726
{
2827
cargoFlags: "",
2928
dockerTag: DEFAULT_DOCKER_TAG
3029
},
31-
this.serverless.service.custom && this.serverless.service.custom.rust || {}
30+
(this.serverless.service.custom && this.serverless.service.custom.rust) ||
31+
{}
3232
);
3333

3434
// By default, Serverless examines node_modules to figure out which
@@ -53,41 +53,37 @@ class RustPlugin {
5353
let cargoFlags = (funcArgs || {}).cargoFlags || this.custom.cargoFlags;
5454
if (cargoPackage != undefined) {
5555
if (cargoFlags) {
56-
cargoFlags = `${cargoFlags} -p ${cargoPackage}`
56+
cargoFlags = `${cargoFlags} -p ${cargoPackage}`;
5757
} else {
5858
cargoFlags = ` -p ${cargoPackage}`;
5959
}
6060
}
6161
if (cargoFlags) {
6262
// --features awesome-feature, ect
63-
customArgs.push('-e', `CARGO_FLAGS=${cargoFlags}`);
64-
};
63+
customArgs.push("-e", `CARGO_FLAGS=${cargoFlags}`);
64+
}
6565
const dockerTag = (funcArgs || {}).dockerTag || this.custom.dockerTag;
6666
return spawnSync(
67-
'docker',
68-
[
69-
...defaultArgs,
70-
...customArgs,
71-
`softprops/lambda-rust:${dockerTag}`
72-
],
67+
"docker",
68+
[...defaultArgs, ...customArgs, `softprops/lambda-rust:${dockerTag}`],
7369
NO_OUTPUT_CAPTURE
7470
);
7571
}
7672

7773
functions() {
7874
if (this.options.function) {
79-
return [this.options.function];
75+
return [this.options.function];
8076
} else {
81-
return this.serverless.service.getAllFunctions();
77+
return this.serverless.service.getAllFunctions();
8278
}
8379
}
8480

8581
build() {
8682
const service = this.serverless.service;
87-
if (service.provider.name != 'aws') {
83+
if (service.provider.name != "aws") {
8884
return;
8985
}
90-
let rustFunctionsFound = false
86+
let rustFunctionsFound = false;
9187
this.functions().forEach(funcName => {
9288
const func = service.getFunction(funcName);
9389
const runtime = func.runtime || service.provider.runtime;
@@ -96,14 +92,18 @@ class RustPlugin {
9692
return;
9793
}
9894
rustFunctionsFound = true;
99-
let [cargoPackage, binary] = func.handler.split('.');
95+
let [cargoPackage, binary] = func.handler.split(".");
10096
if (binary == undefined) {
10197
binary = cargoPackage;
10298
}
10399
this.serverless.cli.log(`Building native Rust ${func.handler} func...`);
104100
const res = this.runDocker(func.rust, cargoPackage, binary);
105101
if (res.error || res.status > 0) {
106-
this.serverless.cli.log(`Dockerized Rust build encountered an error: ${res.error} ${res.status}.`);
102+
this.serverless.cli.log(
103+
`Dockerized Rust build encountered an error: ${res.error} ${
104+
res.status
105+
}.`
106+
);
107107
throw new Error(res.error);
108108
}
109109
// If all went well, we should now have find a packaged compiled binary under `target/lambda/release`.
@@ -115,26 +115,26 @@ class RustPlugin {
115115
// we leverage the ability to declare a package artifact directly
116116
// see https://serverless.com/framework/docs/providers/aws/guide/packaging/
117117
// for more information
118-
const artifactPath = path.join('target/lambda/release', binary + ".zip")
118+
const artifactPath = path.join("target/lambda/release", binary + ".zip");
119119
func.package = func.package || {};
120120
func.package.artifact = artifactPath;
121121

122122
// Ensure the runtime is set to a sane value for other plugins
123123
if (func.runtime == RUST_RUNTIME) {
124-
func.runtime = BASE_RUNTIME
124+
func.runtime = BASE_RUNTIME;
125125
}
126-
})
126+
});
127127
if (service.provider.runtime === RUST_RUNTIME) {
128128
service.provider.runtime = BASE_RUNTIME;
129129
}
130130
if (!rustFunctionsFound) {
131131
throw new Error(
132132
`Error: no Rust functions found. ` +
133-
`Use 'runtime: ${RUST_RUNTIME}' in global or ` +
134-
`function configuration to use this plugin.`
133+
`Use 'runtime: ${RUST_RUNTIME}' in global or ` +
134+
`function configuration to use this plugin.`
135135
);
136136
}
137137
}
138138
}
139139

140-
module.exports = RustPlugin;
140+
module.exports = RustPlugin;

0 commit comments

Comments
 (0)