Skip to content

Commit e29f4e6

Browse files
committed
Adds a dockerBuildCmdExtraArgs option for adding arbitrary arguments to the Docker build step.
1 parent d74b1c0 commit e29f4e6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ServerlessPythonRequirements {
4848
dockerImage: null,
4949
dockerFile: null,
5050
dockerEnv: false,
51+
dockerBuildCmdExtraArgs: [],
5152
dockerRunCmdExtraArgs: [],
5253
useStaticCache: false,
5354
useDownloadCache: false,

lib/docker.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ function dockerCommand(options) {
2525
/**
2626
* Build the custom Docker image
2727
* @param {string} dockerFile
28+
* @param {string[]} extraArgs
2829
* @return {string} The name of the built docker image.
2930
*/
30-
function buildImage(dockerFile) {
31+
function buildImage(dockerFile, extraArgs) {
3132
const imageName = 'sls-py-reqs-custom';
32-
const options = ['build', '-f', dockerFile, '-t', imageName, '.'];
33+
const options = ['build', '-f', dockerFile, '-t', imageName];
34+
35+
if (Array.isArray(extraArgs)) {
36+
options.push(...extraArgs);
37+
} else {
38+
throw new Error('dockerRunCmdExtraArgs option must be an array');
39+
}
40+
41+
options.push('.');
42+
3343
dockerCommand(options);
3444
return imageName;
3545
}

lib/pip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function installRequirements(targetFolder, serverless, options) {
180180
serverless.cli.log(
181181
`Building custom docker image from ${options.dockerFile}...`
182182
);
183-
dockerImage = buildImage(options.dockerFile);
183+
dockerImage = buildImage(options.dockerFile, options.dockerBuildCmdExtraArgs);
184184
} else {
185185
dockerImage = options.dockerImage;
186186
}

0 commit comments

Comments
 (0)