Skip to content

Commit cf459f0

Browse files
authored
Merge pull request #56 from softprops/custom-profiles
support custom profile
2 parents dad6a27 + 2272913 commit cf459f0

19 files changed

+10862
-1716
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
node_modules
22
target
33
tests/test-func/test-out.log
4+
tests/test-func-dev/test-out.log
5+
tests/test-func/local-out.log
6+
tests/test-func-dev/local-out.log
47
.serverless

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ⚡ 0.3.7
22

3-
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to `0.2.4-rust-1.38.0` to gain rust [1.37.0](https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html) and [1.38.0](https://blog.rust-lang.org/2019/09/26/Rust-1.38.0.html) features
3+
* bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to `0.2.6-rust-1.38.0` to gain rust [1.37.0](https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html) and [1.38.0](https://blog.rust-lang.org/2019/09/26/Rust-1.38.0.html) features and dropping over 200 megabytes from previous docker images.
44
* This plugin now respects your `CARGO_HOME` environment variable if set [#46](https://github.com/softprops/serverless-rust/pull/46). This is useful when you for cases where where you do not have cache cargo artifacts in your `${HOME}/.cargo` directory.
55

66
# ⚡ 0.3.6

index.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { spawnSync } = require("child_process");
88
const { homedir } = require("os");
99
const path = require("path");
1010

11-
const DEFAULT_DOCKER_TAG = "0.2.4-rust-1.38.0";
11+
const DEFAULT_DOCKER_TAG = "0.2.6-rust-1.38.0";
1212
const RUST_RUNTIME = "rust";
1313
const BASE_RUNTIME = "provided";
1414
const NO_OUTPUT_CAPTURE = { stdio: ["ignore", process.stdout, process.stderr] };
@@ -50,7 +50,7 @@ class RustPlugin {
5050
this.serverless.service.package.excludeDevDependencies = false;
5151
}
5252

53-
runDocker(funcArgs, cargoPackage, binary) {
53+
runDocker(funcArgs, cargoPackage, binary, profile) {
5454
const cargoHome = process.env.CARGO_HOME || path.join(homedir(), ".cargo");
5555
const cargoRegistry = path.join(cargoHome, "registry");
5656
const cargoDownloads = path.join(cargoHome, "git");
@@ -68,7 +68,12 @@ class RustPlugin {
6868
`${cargoDownloads}:/root/.cargo/git`
6969
];
7070
const customArgs = [];
71+
7172
let cargoFlags = (funcArgs || {}).cargoFlags || this.custom.cargoFlags;
73+
if (profile) {
74+
// release or dev
75+
customArgs.push("-e", `PROFILE=${profile}`);
76+
}
7277
if (cargoPackage != undefined) {
7378
if (cargoFlags) {
7479
cargoFlags = `${cargoFlags} -p ${cargoPackage}`;
@@ -115,7 +120,8 @@ class RustPlugin {
115120
binary = cargoPackage;
116121
}
117122
this.serverless.cli.log(`Building native Rust ${func.handler} func...`);
118-
const res = this.runDocker(func.rust, cargoPackage, binary);
123+
let profile = (func.rust || {}).profile || this.custom.profile;
124+
const res = this.runDocker(func.rust, cargoPackage, binary, profile);
119125
if (res.error || res.status > 0) {
120126
this.serverless.cli.log(
121127
`Dockerized Rust build encountered an error: ${res.error} ${res.status}.`
@@ -131,7 +137,10 @@ class RustPlugin {
131137
// we leverage the ability to declare a package artifact directly
132138
// see https://serverless.com/framework/docs/providers/aws/guide/packaging/
133139
// for more information
134-
const artifactPath = path.join("target/lambda/release", binary + ".zip");
140+
const artifactPath = path.join(
141+
`target/lambda/${"dev" === profile ? "debug" : "release"}`,
142+
binary + ".zip"
143+
);
135144
func.package = func.package || {};
136145
func.package.artifact = artifactPath;
137146

0 commit comments

Comments
 (0)