Skip to content

add support for native binaries and directories #84

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 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ custom:
use_docker: true
docker_yums:
- postgresql-devel
natvie_bins:
- /usr/bin/psql
native_libs:
- /usr/lib64/libpq.so.5
environment:
Expand All @@ -23,6 +25,7 @@ custom:
| ------------- |-------- |-------------- | --------------------|
| **use_docker** | boolean | false | Set true to use Docker to bundle gems with OS native C extensions or system libraries |
| **docker_yums** | array | undefined | List of yum libraries to be preinstalled for gems which require OS native system libraries |
| **native_bins** | array | undefined | Paths of the native executable files that need to be packed in lambda layer along with gems |
| **native_libs** | array | undefined | Paths of the native libraries files that need to be packed in lambda layer along with gems |
| **docker_file** | string | undefined | Path of the custom docker file to be used for bundling gems|
| **include_functions** | array | all functions | List of functions to be configured with the gem layer |
Expand Down
2 changes: 2 additions & 0 deletions docs/usage_examples/use_docker_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ custom:
rubyLayer:
use_docker: true
docker_file: Dockerfile
native_bins:
- /usr/bin/pdfinfo
native_libs:
- /usr/lib64/libpq.so.5
- /usr/lib64/libldap_r-2.4.so.2
Expand Down
2 changes: 2 additions & 0 deletions docs/usage_examples/use_docker_with_yums.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ custom:
use_docker: true
docker_yums:
- postgresql-devel
native_bins:
- /usr/bin/psql
native_libs:
- /usr/lib64/libpq.so.5
- /usr/lib64/libldap_r-2.4.so.2
Expand Down
3 changes: 2 additions & 1 deletion examples/use-docker-file/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ custom:
rubyLayer:
use_docker: true
docker_file: Dockerfile
native_bins:
- /usr/bin/psql
native_libs:
- /usr/lib64/libpq.so.5
- /usr/lib64/libldap_r-2.4.so.2
Expand All @@ -23,4 +25,3 @@ provider:
functions:
hello:
handler: handler.hello

2 changes: 2 additions & 0 deletions examples/use-docker-with-yums-pg-old/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ custom:
use_docker: true
docker_yums:
- postgresql-devel
native_bins:
- /usr/bin/psql
native_libs:
- /usr/lib64/libpq.so.5
- /usr/lib64/libldap_r-2.4.so.2
Expand Down
24 changes: 23 additions & 1 deletion lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var JSZip = require('jszip');
Promise.promisifyAll(fs);

function runCommand(cmd,args,options,cli) {
if (process.env.SLS_DEBUG){
cli.log(cmd, args, options)
}
const ps = spawnSync(cmd, args,options);
if (ps.stdout && process.env.SLS_DEBUG){
cli.log(ps.stdout.toString())
Expand Down Expand Up @@ -106,11 +109,27 @@ function bundleInstall(){
ps=docker(['run','-it','--name',docker_id,'-d', docker_name,'/bin/bash'], options,this.cli)
container_id = ps.stdout.toString().trim()
console.log(container_id)
if (this.options.native_bins) {
this.cli.log("Packing the native binraries from the specified path")
let bin_path = path.join(this.build_path,'bin')
fs.mkdirSync(bin_path)
this.options.native_bins.forEach(bin_to_copy => {
// if the last characte is a / then we assume that we want to copy the whole directory
if(bin_to_copy.slice(-1) === '/'){
bin_path = this.build_path
}
ps=docker(['cp','-L', container_id+':'+bin_to_copy, bin_path],options,this.cli)
})
}
if (this.options.native_libs) {
this.cli.log("Packing the native libraries from the specified path")
const lib_path = path.join(this.build_path,'lib')
let lib_path = path.join(this.build_path,'lib')
fs.mkdirSync(lib_path)
this.options.native_libs.forEach(lib_to_copy => {
// if the last characte is a / then we assume that we want to copy the whole directory
if(lib_to_copy.slice(-1) === '/'){
lib_path = this.build_path
}
ps=docker(['cp','-L', container_id+':'+lib_to_copy, lib_path],options,this.cli)
})
}
Expand Down Expand Up @@ -205,6 +224,9 @@ function zipBundleFolder() {
this.gem_folder= fs.readdirSync(path.join(this.build_path,'ruby'))[0]
const platform = process.platform == 'win32' ? 'DOS' : 'UNIX'
zipping_message = "Zipping the gemfiles"
if (this.options.native_bins) {
zipping_message+=" and native bins"
}
if (this.options.native_libs) {
zipping_message+=" and native libs"
}
Expand Down