Skip to content

Commit c377205

Browse files
committed
Merge branch 'master' of https://github.com/navarasu/serverless-ruby-layer into fix_11_add_docs
2 parents 634cd34 + 00c68b4 commit c377205

File tree

8 files changed

+43
-0
lines changed

8 files changed

+43
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'pg'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'pg'
2+
3+
def hello(event:, context:)
4+
{ statusCode: 200, body: {
5+
"pg_version": PG.library_version
6+
}
7+
}
8+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
service: using-docker-file
2+
3+
plugins:
4+
- serverless-ruby-layer
5+
6+
custom:
7+
rubyLayer:
8+
use_docker: true
9+
docker_yums:
10+
- postgresql-devel
11+
native_libs:
12+
- /usr/lib64/libpq.so.5
13+
14+
provider:
15+
name: aws
16+
runtime: ruby2.5
17+
18+
functions:
19+
hello:
20+
handler: handler.hello

lib/bundle.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,22 @@ function bundleInstall(){
4444
if (ps.error && ps.error.code === 'ENOENT') {
4545
throw new Error('docker command not found');
4646
}
47+
let buildDocker = false;
4748
if (this.options.docker_file) {
4849
fs.copySync(path.join(this.servicePath, this.options.docker_file),
4950
path.join(this.ruby_layer,'Dockerfile'))
51+
buildDocker = true
52+
}else if (this.options.docker_yums) {
53+
docker_steps =['FROM lambci/lambda:build-'+this.serverless.service.provider.runtime]
54+
this.options.docker_yums.forEach(function(package_name) {
55+
docker_steps.push('RUN yum install -y '+package_name)
56+
})
57+
docker_steps.push('RUN gem update bundler')
58+
docker_steps.push('CMD "/bin/bash"')
59+
fs.writeFileSync(path.join(this.ruby_layer,'Dockerfile'),docker_steps.join('\n'))
60+
buildDocker = true
61+
}
62+
if (buildDocker) {
5063
docker_name ='ruby-layer:docker'
5164
docker(['build', '-t', docker_name, '-f', 'Dockerfile', '.'], options,this.cli)
5265
}

0 commit comments

Comments
 (0)