Skip to content

Commit 6b06ecf

Browse files
committed
#12 Added exmaples for docker file and fixed test
1 parent 64fad87 commit 6b06ecf

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

examples/using_docker_file/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM lambci/lambda:build-ruby2.5
2+
3+
RUN yum install -y postgresql-devel
4+
RUN gem update bundler
5+
6+
CMD "/bin/bash"

examples/using_docker_file/Gemfile

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'

examples/using_docker_file/handler.rb

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
service: using-docker-file
2+
3+
plugins:
4+
- serverless-ruby-layer
5+
6+
custom:
7+
rubyLayer:
8+
use_docker: true
9+
docker_file: Dockerfile
10+
native_libs:
11+
- /usr/lib64/libpq.so.5
12+
13+
provider:
14+
name: aws
15+
runtime: ruby2.5
16+
17+
functions:
18+
hello:
19+
handler: handler.hello

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function readZip(filePath){
2323
.then(function (zip) {
2424
let check = []
2525
zip.forEach(function (relativePath, file){
26-
if (file.dir && relativePath.split(path.sep).length <= 4){
26+
if (file.dir && relativePath.split(path.sep).length <= 5){
2727
check.push(relativePath)
2828
} else if (relativePath.split(path.sep).length <= 1) {
2929
check.push(relativePath)

test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('serverless package', function () {
1919
runCommand('npm',['link','serverless-ruby-layer'],options)
2020
runCommand('sls',['package'],options)
2121
let dot_serverless_path = path.join(context_path,'.serverless')
22-
let layer_zip_path = path.join(dot_serverless_path,'build','ruby_layer','gemLayer.zip')
22+
let layer_zip_path = path.join(dot_serverless_path,'ruby_layer','gemLayer.zip')
2323
let function_zip_path = path.join(dot_serverless_path,'basic.zip')
2424
value = readZip(function_zip_path)
2525
.then(function(data){
@@ -32,7 +32,7 @@ describe('serverless package', function () {
3232
'/gems/','/specifications/','/gems/httparty-0.18.1/',
3333
'/gems/mime-types-3.3.1/','/gems/multi_xml-0.6.0/',
3434
'/gems/mime-types-data-3.2020.0512/']
35-
.map(data => run_time+'.0'+data).sort(),
35+
.map(data => 'ruby/'+run_time+'.0'+data).concat(['ruby/']).sort(),
3636
data.sort())
3737
})
3838
let rawdata = fs.readFileSync(path.join(dot_serverless_path,'serverless-state.json'));
@@ -51,6 +51,6 @@ describe('serverless package', function () {
5151
})
5252
assert.deepEqual(cloud_resource['HelloLambdaFunction']['Properties']['Layers'],[ { Ref: 'GemLayerLambdaLayer' } ])
5353
assert.deepEqual(cloud_resource['HelloLambdaFunction']['Properties']['Environment'],
54-
{Variables: { GEM_PATH: '/opt/'+run_time+'.0'}})
54+
{Variables: { GEM_PATH: '/opt/ruby/'+run_time+'.0'}})
5555
});
5656
});

0 commit comments

Comments
 (0)