Skip to content

Commit

Permalink
ruby2.7 / pg shared libs, update readme instructions (#89)
Browse files Browse the repository at this point in the history
* add postgres required shared lib, update readme instructions
* fix: update to ruby2.7 runtime
* update run steps
* chore: add additional pg deps, updates yarn deps
  • Loading branch information
YOU54F authored May 5, 2022
1 parent 70d6396 commit 25c1e77
Show file tree
Hide file tree
Showing 20 changed files with 2,724 additions and 2,964 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ vendor/bundle
.DS_Store
.bundle/config
.env
lib/
pact_broker
1 change: 0 additions & 1 deletion .slsignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
rubypg_layer/**
node_modules/**
.serverless/**
.circleci/**
.bundle/**
.gitignore
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM lambci/lambda:build-ruby2.5
FROM lambci/lambda:build-ruby2.7

RUN yum install -y postgresql postgresql-devel
RUN yum install -y postgresql postgresql-devel mysql-devel
RUN yum install -y postgresql postgresql-devel mysql-devel sqlite-devel

ADD pact_broker/Gemfile /var/task/Gemfile
ADD pact_broker/Gemfile.lock /var/task/Gemfile.lock

# hack because pg isnt pinned
RUN sed -i 's/gem "pg", "~>1.0"/gem "pg", "1.2.3"/g' /var/task/Gemfile
RUN bundle install && bundle install --deployment
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ buildpglayer:
cd rubypg_layer && ./build.sh

deploypglayer:
cd rubypg_layer && sls deploy -v
cd rubypg_layer && npm run deploy -v

logs:
awslogs get /aws/lambda/pact-broker-serverless-dev-api --profile=${AWS_PROFILE_NAME}

deploy:
sls deploy -v
npm run deploy
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ _Caveat_ - This was an experimental POC and there are several open [issues](http

## Prerequisites

* A running postgresql database and the ability to connect to it (see [POSTGRESQL.md][postgres]).
* A running postgresql database and the ability to connect to it (instructions for that are outside of scope).
* An AWS account
* A custom domain in route 53 with a certificate
* A custom domain in route 53 with a certificate (not required if using standard api gateway supplied endpoint)

## Getting Started

Expand Down Expand Up @@ -48,6 +48,7 @@ plugins:
## Running with Serverless

1. Run `make downloadpb` which will download the latest version of the `pact_broker` folder from `pact-foundation/pact-broker-docker` _note_ this command will remove the old folder without futher warning.
1. MacOS user? : Run `make downloadpbmac` instead
2. Run `make packagewithpg` to build the pact broker bundle dependencies and postgres dependencies in a docker container, and copy them to your `vendor` and `lib` folders.
Alternatively you can run `make package` to build the pact broker bundle dependencies. You will need a custom aws layer with the postgres dependencies satisfied to run your function successfully. See the next section
3. Run `yarn install` or delete the `.lock` file and run `npm install` if you prefer. This will install serverless, along with serverless-rack, serverless-ignore & serverless-domain-manager.
Expand Down
20 changes: 18 additions & 2 deletions build-withpg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ set -e
rm -rf lib && mkdir -p lib
rm -rf vendor

docker build -t ruby25-pg-builder -f Dockerfile .
docker build -t ruby27-pg-builder -f Dockerfile .

CONTAINER=$(docker run -d ruby25-pg-builder false)
CONTAINER=$(docker run -d ruby27-pg-builder false)

docker cp \
$CONTAINER:/usr/lib64/libpq.so.5.5 \
lib/libpq.so.5
docker cp \
$CONTAINER:/usr/lib64/libpq.so.5.5 lib/libpq.so.5
docker cp \
$CONTAINER:/usr/lib64/libldap_r-2.4.so.2.10.7 lib/libldap_r-2.4.so.2
docker cp \
$CONTAINER:/usr/lib64/liblber-2.4.so.2.10.7 lib/liblber-2.4.so.2
docker cp \
$CONTAINER:/usr/lib64/libsasl2.so.3.0.0 lib/libsasl2.so.3
docker cp \
$CONTAINER:/usr/lib64/libssl3.so lib/
docker cp \
$CONTAINER:/usr/lib64/libsmime3.so lib/
docker cp \
$CONTAINER:/usr/lib64/libnss3.so lib/
docker cp \
$CONTAINER:/usr/lib64/libnssutil3.so lib/

docker cp \
$CONTAINER:/var/task/vendor \
Expand Down
4 changes: 2 additions & 2 deletions build-withpglayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -e

rm -rf vendor

docker build -t ruby25-pg-builder -f Dockerfile .
docker build -t ruby27-pg-builder -f Dockerfile .

CONTAINER=$(docker run -d ruby25-pg-builder false)
CONTAINER=$(docker run -d ruby27-pg-builder false)

docker cp \
$CONTAINER:/var/task/vendor \
Expand Down
Binary file added lib/liblber-2.4.so.2
Binary file not shown.
Binary file added lib/libldap_r-2.4.so.2
Binary file not shown.
Binary file added lib/libnss3.so
Binary file not shown.
Binary file added lib/libnssutil3.so
Binary file not shown.
Binary file added lib/libpq.so.5
Binary file not shown.
Binary file added lib/libsasl2.so.3
Binary file not shown.
Binary file added lib/libsmime3.so
Binary file not shown.
Binary file added lib/libssl3.so
Binary file not shown.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "pact_broker-serverless",
"version": "1.0.0",
"description": "Running the pact_broker application on AWS Lambda. It is tested with Ruby 2.5.x and bundler-1.17.x.",
"description": "Running the pact_broker application on AWS Lambda. It is tested with Ruby 2.7.x and bundler-1.17.x.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"create-domain": "sls create_domain",
"deploy": "sls deploy"
"deploy": "sls deploy -v"
},
"repository": {
"type": "git",
Expand All @@ -16,11 +16,12 @@
"license": "ISC",
"homepage": "https://github.com/you54f/pact_broker-serverless#readme",
"devDependencies": {
"serverless": "1.74.1",
"serverless": "^2.72.3",
"serverless-apigw-binary": "0.4.4",
"serverless-domain-manager": "4.1.1",
"serverless-ignore": "0.1.5",
"serverless-rack": "1.0.5"
"serverless-domain-manager": "6.0.3",
"serverless-ignore": "0.2.1",
"serverless-rack": "1.0.7",
"serverless-offline": "8.7.0"
},
"dependencies": {
}
Expand Down
2 changes: 1 addition & 1 deletion rubypg_layer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lambci/lambda:build-ruby2.5
FROM lambci/lambda:build-ruby2.7

RUN yum install -y postgresql postgresql-devel

Expand Down
6 changes: 3 additions & 3 deletions rubypg_layer/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ provider:
region: ${env:AWS_REGION}

layers:
pgRuby25:
pgRuby27:
path: layer
description: A Layer to fix postgres support in Ruby 2.5 Lambda functions
description: A Layer to fix postgres support in Ruby 2.7 Lambda functions
compatibleRuntimes:
- ruby2.5
- ruby2.7
25 changes: 13 additions & 12 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: pact-broker-serverless

provider:
name: aws
runtime: ruby2.5
runtime: ruby2.7
region: ${env:AWS_REGION}
environment:
# API_GATEWAY_BASE_PATH: ${self:custom.customDomain.basePath}
Expand All @@ -11,7 +11,7 @@ provider:
PACT_BROKER_DATABASE_HOST: ${env:PACT_BROKER_DATABASE_HOST}
PACT_BROKER_DATABASE_NAME: ${env:PACT_BROKER_DATABASE_NAME}
PACT_BROKER_LOG_LEVEL: ${env:PACT_BROKER_LOG_LEVEL}
PACT_BROKER_BASE_URL: ${env:PACT_BROKER_BASE_URL}
# PACT_BROKER_BASE_URL: ${env:PACT_BROKER_BASE_URL}
RACK_ENV: production
# PACT_BROKER_BASIC_AUTH_USERNAME: ${env:PACT_BROKER_BASIC_AUTH_USERNAME}
# PACT_BROKER_BASIC_AUTH_PASSWORD: ${env:PACT_BROKER_BASIC_AUTH_PASSWORD}
Expand All @@ -21,18 +21,19 @@ provider:
plugins:
- serverless-rack
- serverless-ignore
- serverless-domain-manager
# - serverless-domain-manager
- serverless-apigw-binary
- serverless-offline

functions:
api:
timeout: 30
handler: rack_adapter.handler
layers:
- ${env:PG_RUBY_LAYER_ARN}
# layers:
# - ${env:PG_RUBY_LAYER_ARN}
events:
- http: ANY /
- http: ANY {proxy+}
- http: ANY /{proxy+}

custom:
ignore: true
Expand All @@ -59,9 +60,9 @@ custom:
- 'application/json'
- 'application/hal+json'
- 'application/xhtml+xml'
customDomain:
# basePath: pactbroker
domainName: ${env:SERVERLESS_DOMAIN_NAME}
certificateName: ${env:SERVERLESS_CERTIFICATE_NAME}
stage: dev
createRoute53Record: true
# customDomain:
# # basePath: pactbroker
# domainName: ${env:SERVERLESS_DOMAIN_NAME}
# certificateName: ${env:SERVERLESS_CERTIFICATE_NAME}
# stage: dev
# createRoute53Record: true
Loading

0 comments on commit 25c1e77

Please sign in to comment.