Skip to content

Allow the default docker command that packages gems to be overriden #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,23 @@ class PackageRubyBundlePlugin {
const localPath = this.serverless.config.servicePath;
const imageTag = this.serverless.service.provider.runtime.slice(-3);
const dockerImage = `amazon/aws-lambda-ruby:${imageTag}`;
const command = `docker run --rm \
--volume "${localPath}:/var/task" \
--entrypoint '/bin/bash' \
${dockerImage} \
'/var/task/node_modules/serverless-ruby-package/build-gems.sh'`
const default_command = `docker run --rm \
--volume "${localPath}:/var/task" \
Copy link
Author

@lwoodson lwoodson Aug 30, 2023

Choose a reason for hiding this comment

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

A more targeted but less flexible change would be to allow ENV var to override the localPath here. In our case:

  • build host: a CI worker node. Mount is something like /var/build/<project_checkout>:/app
  • build container: the docker container launched by the host with all the dependencies for a serverless ruby project that has the project checkout mounted to /app and runs the serverless package command
  • native extension container: the docker container spawned by serverless-ruby-package inside the build container. Here, localPath is evaluating to /app but since the build container is sharing the docker socket with the build host, localPath needs to be a path to where the project is on the build host. So the mount here should be /var/build/<project_checkout>:/var/task and not /app:/var/task

Copy link
Author

Choose a reason for hiding this comment

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

We may want to also include documentation for docker-in-docker in the readme. Many CI/CD systems will use a docker-in-docker approach.

Copy link
Owner

Choose a reason for hiding this comment

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

This seems like a reasonable approach, if we are unable to detect the "docker in docker" situation and determine the volume mount automatically.

--entrypoint '/bin/bash' \
${dockerImage} \
'/var/task/node_modules/serverless-ruby-package/build-gems.sh'`
const command = process.env.SRP_DOCKER_COMMAND || default_command;

if (this.config.debug){
this.log(`local path: ${localPath}`);
this.log(`image tag: ${imageTag}`);
this.log(`docker image: ${dockerImage}`);
this.log(`command: ${command}`);
this.log(`docker command: ${command}`);
}
const output = execSync(command)
if (this.config.debug) {
this.log(`docker command output: ${output}`);
}
execSync(command)
}

warnOnUnsupportedRuntime(){
Expand Down