Skip to content

Commit

Permalink
#38 Added example for pg using ruby2.7 and updated testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
navarasu committed May 3, 2021
1 parent 973d462 commit a2e201d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: use-docker-with-yums
service: use-docker-with-yums-pg-ruby2.5

plugins:
- serverless-ruby-layer
Expand Down
2 changes: 2 additions & 0 deletions examples/use-docker-with-yums-pg-ruby2.7/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'pg'
8 changes: 8 additions & 0 deletions examples/use-docker-with-yums-pg-ruby2.7/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'pg'

def hello(event:, context:)
{ statusCode: 200, body: {
"pg_version": PG.library_version
}
}
end
26 changes: 26 additions & 0 deletions examples/use-docker-with-yums-pg-ruby2.7/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
service: use-docker-with-yums-pg-ruby2.7

plugins:
- serverless-ruby-layer

custom:
rubyLayer:
use_docker: true
docker_yums:
- postgresql-devel
native_libs:
- /usr/lib64/libpq.so.5
- /usr/lib64/libldap_r-2.4.so.2
- /usr/lib64/liblber-2.4.so.2
- /usr/lib64/libsasl2.so.3
- /usr/lib64/libssl3.so
- /usr/lib64/libsmime3.so
- /usr/lib64/libnss3.so

provider:
name: aws
runtime: ruby2.7

functions:
hello:
handler: handler.hello
10 changes: 7 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ let test_data = [
'/gems/mini_portile2/', '/gems/nokogiri/', '/gems/public_suffix/', '/gems/rake/', '/gems/unf/', '/gems/unf_ext/' ],
function_files: ['handler.rb'], include_functions: ['Hello'], exclude_functions:[] },

{ folder: 'use-docker-with-yums', gem_zip_dirs: [ '/', '/build_info/', '/doc/', '/extensions/', '/gems/',
{ folder: 'use-docker-with-yums-pg-ruby2.5', gem_zip_dirs: [ '/', '/build_info/', '/doc/', '/extensions/', '/gems/',
'/specifications/', '/gems/pg/', '/extensions/x86_64-linux/', 'lib/', 'lib/libpq.so.5' ],
function_files: ['handler.rb'], include_functions: ['Hello'], exclude_functions:[] },

{ folder: 'use-docker-with-yums-pg-ruby2.7', gem_zip_dirs: [ '/', '/build_info/', '/doc/', '/extensions/', '/gems/', '/plugins/',
'/specifications/', '/gems/pg/', '/extensions/x86_64-linux/', 'lib/', 'lib/libpq.so.5', 'lib/liblber', 'lib/libldap_r', 'lib/libnss3.so', 'lib/libsasl2.so.3', 'lib/libsmime3.so', 'lib/libssl3.so' ],
function_files: ['handler.rb'], include_functions: ['Hello'], exclude_functions:[] },

{ folder: 'use-docker-file', gem_zip_dirs: [ '/', '/build_info/', '/doc/', '/extensions/', '/gems/',
'/specifications/', '/gems/pg/', '/extensions/x86_64-linux/', 'lib/', 'lib/libpq.so.5' ],
function_files: ['handler.rb'], include_functions: ['Hello'], exclude_functions:[] },
Expand Down Expand Up @@ -82,7 +86,7 @@ describe('serverless package', function () {
.then(function(data){
assert.deepEqual(function_files,data)
})
run_time ='2.5'
run_time = folder.endsWith('2.7')? '2.7': '2.5'
value = readZip(layer_zip_path)
.then(function(data){
if (!check_version) {
Expand All @@ -94,7 +98,7 @@ describe('serverless package', function () {
assert.deepEqual(serverless_config['service']['layers']['gem']['package']['artifact'], path.resolve(layer_zip_path))
cloud_resource = serverless_config['service']['provider']['compiledCloudFormationTemplate']['Resources']
const {Content, ...others} = cloud_resource['GemLambdaLayer']['Properties']
assert.deepEqual(others,{CompatibleRuntimes: ['ruby2.5'],
assert.deepEqual(others,{CompatibleRuntimes: ['ruby'+run_time],
Description: 'Ruby gem generated by serverless-ruby-bundler',
LayerName: `${folder}-dev-ruby-bundle`
})
Expand Down

0 comments on commit a2e201d

Please sign in to comment.