Skip to content

Commit ddcdda7

Browse files
authored
Merge pull request #50 from navarasu/fix_38_add_pg_example
#38 Added example for pg using ruby2.7 and updated testcases
2 parents 2e65670 + 20a9608 commit ddcdda7

File tree

11 files changed

+126
-13
lines changed

11 files changed

+126
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ For more detailse refer the docs [here](https://navarasu.github.io/serverless-ru
7979
Using the custom configuration, the plugin can be utilized for below cases,
8080
* Using locally installed bundler for gems without any native extensions - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/basic) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_local_bundler)
8181
* Using Docker for gems with OS native C extensions or system libraries like `http`, `Nokogiri` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker)
82-
* Preinstall OS packages (yum packages) for gems which requires OS native system libraries like `pg`, `mysql`, `RMagick` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_with_yums)
82+
* Preinstall OS packages (yum packages) for gems which requires OS native system libraries like `pg`, `mysql`, `RMagick` - [PG ruby2.5 Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums-pg-ruby2-5) , [PG ruby2.7 Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums-pg-ruby2-7) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_with_yums)
8383
* Using Dockerfile for gems which with other OS Linux image or system libraries and utilities - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-file) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_file)
8484
* Include / Exclude specific functions from layer configuration - [Include Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/include-functions) , [Exclude Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/exclude-functions) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/include_exclude)
8585
* Exclude test and development related gems from layer - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/exclude-dev-test-gems) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/exclude_dev_test_gems)

docs/home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ For more detailse refer the docs [here](https://navarasu.github.io/serverless-ru
7979
Using the custom configuration, the plugin can be utilized for below cases,
8080
* Using locally installed bundler for gems without any native extensions - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/basic) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_local_bundler)
8181
* Using Docker for gems with OS native C extensions or system libraries like `http`, `Nokogiri` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker)
82-
* Preinstall OS packages (yum packages) for gems which requires OS native system libraries like `pg`, `mysql`, `RMagick` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_with_yums)
82+
* Preinstall OS packages (yum packages) for gems which requires OS native system libraries like `pg`, `mysql`, `RMagick` - [PG ruby2.5 Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums-pg-ruby2-5) , [PG ruby2.7 Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums-pg-ruby2-7) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_with_yums)
8383
* Using Dockerfile for gems which with other OS Linux image or system libraries and utilities - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-file) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_file)
8484
* Include / Exclude specific functions from layer configuration - [Include Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/include-functions) , [Exclude Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/exclude-functions) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/include_exclude)
8585
* Exclude test and development related gems from layer - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/exclude-dev-test-gems) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/exclude_dev_test_gems)

docs/usage_examples/main.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
## Usage and Examples
33

44
Using the custom configuration, the plugin can be utilized for below cases,
5-
* Using locally installed bundler for gems without any native extensions [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/basic) - [Docs](/use_local_bundler)
6-
* Using Docker for gems with C extensions or system libraries like `http`, `Nokogiri` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use_docker) - [Docs](use_docker)
7-
* Preinstall OS packages (yum packages) for gems which requires OS native system libraries like `pg`, `mysql`, `RMagick` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use_docker_with_yums) - [Docs](use_docker_with_yums)
8-
* Using Dockerfile for gems which requires other system libraries and configuration - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use_docker_file) - [Docs](use_docker_file)
5+
* Using locally installed bundler for gems without any native extensions - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/basic) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_local_bundler)
6+
* Using Docker for gems with OS native C extensions or system libraries like `http`, `Nokogiri` - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker)
7+
* Preinstall OS packages (yum packages) for gems which requires OS native system libraries like `pg`, `mysql`, `RMagick` - [PG ruby2.5 Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums-pg-ruby2-5) , [PG ruby2.7 Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-with-yums-pg-ruby2-7) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_with_yums)
8+
* Using Dockerfile for gems which with other OS Linux image or system libraries and utilities - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/use-docker-file) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/use_docker_file)
9+
* Include / Exclude specific functions from layer configuration - [Include Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/include-functions) , [Exclude Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/exclude-functions) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/include_exclude)
910
* Exclude test and development related gems from layer - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/exclude-dev-test-gems) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/exclude_dev_test_gems)
1011
* Using `Bundler.require(:default)` to require all gems in handler.rb by respecting Gemfile.lock - [Example](https://github.com/navarasu/serverless-ruby-layer/blob/master/examples/bundler-require-all) - [Docs](https://navarasu.github.io/serverless-ruby-layer/#/bundler_require_all)
12+

docs/usage_examples/use_docker_with_yums.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Preinstall yum packages for gems which requires OS native system libraries
44

5+
### Example to deploy pg using Ruby 2.7
56

67
<!-- tabs:start -->
78

@@ -20,10 +21,16 @@ custom:
2021
- postgresql-devel
2122
native_libs:
2223
- /usr/lib64/libpq.so.5
24+
- /usr/lib64/libldap_r-2.4.so.2
25+
- /usr/lib64/liblber-2.4.so.2
26+
- /usr/lib64/libsasl2.so.3
27+
- /usr/lib64/libssl3.so
28+
- /usr/lib64/libsmime3.so
29+
- /usr/lib64/libnss3.so
2330

2431
provider:
2532
name: aws
26-
runtime: ruby2.5
33+
runtime: ruby2.7
2734

2835
functions:
2936
hello:
@@ -54,20 +61,84 @@ end
5461
<!-- tabs:end -->
5562

5663

64+
### Example to deploy pg using Ruby 2.5
65+
66+
<!-- tabs:start -->
67+
68+
#### ** serverless.yml **
69+
70+
```yml
71+
service: using-docker-yums
72+
73+
plugins:
74+
- serverless-ruby-layer
75+
76+
custom:
77+
rubyLayer:
78+
use_docker: true
79+
docker_yums:
80+
- postgresql-devel
81+
native_libs:
82+
- /usr/lib64/libpq.so.5
83+
84+
provider:
85+
name: aws
86+
runtime: ruby2.5
87+
88+
functions:
89+
hello:
90+
handler: handler.hello
91+
```
92+
93+
#### ** Gemfile **
94+
95+
```ruby
96+
source 'https://rubygems.org'
97+
gem 'pg'
98+
```
99+
100+
#### ** handler.rb **
101+
102+
```ruby
103+
require 'pg'
104+
105+
def hello(event:, context:)
106+
{ statusCode: 200, body: {
107+
"pg_version": PG.library_version
108+
}
109+
}
110+
end
111+
112+
```
113+
114+
<!-- tabs:end -->
57115

58116
#### Checkout above Example here
59117

60118

61119
```bash
62120
git clone https://github.com/navarasu/serverless-ruby.git
63121
```
122+
*Ruby 2.7*
123+
64124
```bash
65-
cd serverless-ruby/deploy_pg_gem
125+
cd serverless-ruby/deploy_pg_gem_2-7
66126

67127
sls plugin install -n serverless-ruby-layer
68128

69129
```
70130

131+
*Ruby 2.5*
132+
133+
```bash
134+
cd serverless-ruby/deploy_pg_gem_2-5
135+
136+
sls plugin install -n serverless-ruby-layer
137+
138+
```
139+
140+
141+
71142
#### Deploy to AWS
72143

73144
```bash
@@ -81,4 +152,4 @@ Running `sls deploy` automatically deploys the required gems as in Gemfile to AW
81152

82153
```bash
83154
sls invoke -f hello
84-
```
155+
```

examples/use-docker-with-yums/serverless.yml renamed to examples/use-docker-with-yums-pg-ruby2-5/serverless.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service: use-docker-with-yums
1+
service: use-docker-with-yums-pg-ruby2-5
22

33
plugins:
44
- serverless-ruby-layer
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
service: use-docker-with-yums-pg-ruby2-7
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+
- /usr/lib64/libldap_r-2.4.so.2
14+
- /usr/lib64/liblber-2.4.so.2
15+
- /usr/lib64/libsasl2.so.3
16+
- /usr/lib64/libssl3.so
17+
- /usr/lib64/libsmime3.so
18+
- /usr/lib64/libnss3.so
19+
20+
provider:
21+
name: aws
22+
runtime: ruby2.7
23+
24+
functions:
25+
hello:
26+
handler: handler.hello

0 commit comments

Comments
 (0)