Skip to content

Commit 17c2d2b

Browse files
authored
Merge pull request #61 from sebasmagri/feature-override-docker-cli
feat: add the capability to override the docker cli and arguments
2 parents e787e79 + 39b407a commit 17c2d2b

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

index.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ class RustPlugin {
5151
}
5252

5353
runDocker(funcArgs, cargoPackage, binary, profile) {
54-
const cargoHome = process.env.CARGO_HOME || path.join(homedir(), ".cargo");
55-
const cargoRegistry = path.join(cargoHome, "registry");
56-
const cargoDownloads = path.join(cargoHome, "git");
54+
const cargoHome = process.env.CARGO_HOME || path.join(homedir(), '.cargo');
55+
const cargoRegistry = path.join(cargoHome, 'registry');
56+
const cargoDownloads = path.join(cargoHome, 'git');
57+
58+
const dockerCLI = process.env['SLS_DOCKER_CLI'] || 'docker';
5759
const defaultArgs = [
58-
"run",
59-
"--rm",
60-
"-t",
61-
"-e",
60+
'run',
61+
'--rm',
62+
'-t',
63+
'-e',
6264
`BIN=${binary}`,
6365
`-v`,
6466
`${this.servicePath}:/code`,
@@ -67,12 +69,12 @@ class RustPlugin {
6769
`-v`,
6870
`${cargoDownloads}:/root/.cargo/git`
6971
];
70-
const customArgs = [];
72+
const customArgs = (process.env['SLS_DOCKER_ARGS'] || '').split(' ') || [];
7173

7274
let cargoFlags = (funcArgs || {}).cargoFlags || this.custom.cargoFlags;
7375
if (profile) {
7476
// release or dev
75-
customArgs.push("-e", `PROFILE=${profile}`);
77+
customArgs.push('-e', `PROFILE=${profile}`);
7678
}
7779
if (cargoPackage != undefined) {
7880
if (cargoFlags) {
@@ -83,14 +85,21 @@ class RustPlugin {
8385
}
8486
if (cargoFlags) {
8587
// --features awesome-feature, ect
86-
customArgs.push("-e", `CARGO_FLAGS=${cargoFlags}`);
88+
customArgs.push('-e', `CARGO_FLAGS=${cargoFlags}`);
8789
}
8890
const dockerTag = (funcArgs || {}).dockerTag || this.custom.dockerTag;
89-
return spawnSync(
90-
"docker",
91-
[...defaultArgs, ...customArgs, `softprops/lambda-rust:${dockerTag}`],
92-
NO_OUTPUT_CAPTURE
91+
92+
const finalArgs = [
93+
...defaultArgs,
94+
...customArgs,
95+
`softprops/lambda-rust:${dockerTag}`
96+
].filter(i => i);
97+
98+
this.serverless.cli.log(
99+
`Running container build with: ${dockerCLI}, args: ${finalArgs}.`
93100
);
101+
102+
return spawnSync(dockerCLI, finalArgs, NO_OUTPUT_CAPTURE);
94103
}
95104

96105
functions() {

tests/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ for project in test-func test-func-dev; do
3333
unzip -o \
3434
target/lambda/"${target}"/test-func.zip \
3535
-d /tmp/lambda > /dev/null 2>&1 && \
36-
docker run \
36+
${SLS_DOCKER_CLI:-docker} run \
3737
-i --rm \
3838
-e DOCKER_LAMBDA_USE_STDIN=1 \
3939
-v /tmp/lambda:/var/task \
@@ -63,4 +63,4 @@ for project in test-func test-func-dev; do
6363
# diff test-local.json local-out.log
6464
done
6565

66-
end_tests
66+
end_tests

0 commit comments

Comments
 (0)