Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for Ruby #214

Merged
merged 29 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
34e1550
Introduce support for Ruby
fallwith Feb 23, 2024
2a0e74a
Ruby publish script updates
fallwith Mar 1, 2024
33dae93
Ruby layer updates
fallwith Mar 2, 2024
b7d945d
Ruby: beta test feedback driven updates
fallwith Mar 15, 2024
2095fbd
support Ruby in libBuild.sh
fallwith Mar 26, 2024
6438948
Ruby: support building a fresh extension
fallwith Mar 28, 2024
be426c6
Added Dockerfile file for Ruby
fallwith Mar 28, 2024
26f72cc
Ruby: support Ruby v3.3 runtime
fallwith Apr 5, 2024
5d96736
CI content for Ruby
fallwith Apr 17, 2024
68a51b5
GHA workflows belong in .github/workflows
fallwith May 6, 2024
128e972
Merge branch 'master' into ruby
fallwith May 6, 2024
9e92311
Ruby Dockerfile files: fix aws-cli installation
fallwith May 6, 2024
306cc14
Ruby GHA workflow updates
fallwith May 6, 2024
9a1588d
Ruby workflow update
fallwith May 6, 2024
845c076
Ruby GHA workflow tweaks
fallwith May 6, 2024
f0076bb
Ruby: upgrade setup-ruby
fallwith May 6, 2024
c37929e
Ruby: temp testing
fallwith May 6, 2024
8ca838b
Ruby GHA testing
fallwith May 6, 2024
1585c1b
GHA substitution
fallwith May 6, 2024
b73f617
GHA: .value
fallwith May 6, 2024
dd185d5
Ruby GHA: use set-output
fallwith May 6, 2024
e6b1905
Ruby GHA
fallwith May 6, 2024
8a27900
Ruby: RuboCop driven linting fixes
fallwith May 7, 2024
ad66d63
Ruby unit tests: leave the unused named args alone
fallwith May 7, 2024
a0836f5
Ruby Dockerfiles: use CMD
fallwith May 7, 2024
dcb2ff1
Ruby publish - remove slash
fallwith May 7, 2024
7e00246
GHA Ruby: 'node' -> 'ruby'
fallwith May 7, 2024
b2de3e5
Ruby: dynamically adjust $LOAD_PATH
fallwith May 7, 2024
f98e99b
Ruby: gem path fix: 3.3 -> 3.3.0
fallwith May 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/publish-ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish Ruby Layers

on:
push:
tags:
- v**_ruby

jobs:
publish-ruby:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [3.2, 3.3]
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # tag v4.1.2
- name: Use Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@1198b074305f9356bd56dd4b311757cc0dab2f1c # tag v1.175.1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Check Tag
id: ruby-check-tag
run: |
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+(\.[0-9]+)*_ruby$ ]]; then
echo "match=true" >> $GITHUB_OUTPUT
fi
- name: Install Ruby Dependencies
run: bundle
working-directory: ruby
- name: Obtain Ruby version without the dot
id: ruby-version-without-dot
run: >-
echo "::set-output name=VERSION::$(
echo ${{ matrix.ruby-version }} | sed 's/\.//'
)"
- name: Publish layer
if: steps.ruby-check-tag.outputs.match == 'true'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: make publish-ruby${{ steps.ruby-version-without-dot.outputs.VERSION }}-ci
50 changes: 50 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Ruby Layer CI

on:
push:
branches: [master]
paths:
- 'ruby/**'
pull_request:
paths:
- 'ruby/**'
workflow_dispatch:
branches: [master]
paths:
- 'ruby/**'

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # tag v4.1.2
- uses: ruby/setup-ruby@1198b074305f9356bd56dd4b311757cc0dab2f1c # tag v1.175.1
with:
ruby-version: '3.3'
- run: bundle
working-directory: ruby
- run: rubocop
working-directory: ruby

unit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # tag v4.1.2
- uses: ruby/setup-ruby@1198b074305f9356bd56dd4b311757cc0dab2f1c # tag v1.175.1
with:
ruby-version: '3.3'
# Node.js powers serverless-offline, used for unit tests
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Node.js Dependencies
run: npm install
working-directory: ruby/test/support
- name: Install Ruby Depedencies
run: bundle
working-directory: ruby
- name: Run Unit Tests
run: bundle exec rake test
working-directory: ruby
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,41 @@ publish-nodejs20x-local: build-nodejs20x
-e AWS_PROFILE \
-v "${HOME}/.aws:/home/newrelic-lambda-layers/.aws" \
newrelic-lambda-layers-nodejs20x

build-ruby32:
docker build \
--no-cache \
-t newrelic-lambda-layers-ruby32 \
-f ./dockerfiles/Dockerfile.ruby32 \
.

publish-ruby32-ci: build-ruby32
docker run \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
newrelic-lambda-layers-ruby32

publish-ruby32-local: build-ruby32
docker run \
-e AWS_PROFILE \
-v "${HOME}/.aws:/home/newrelic-lambda-layers/.aws" \
newrelic-lambda-layers-ruby32

build-ruby33:
docker build \
--no-cache \
-t newrelic-lambda-layers-ruby33 \
-f ./dockerfiles/Dockerfile.ruby33 \
.

publish-ruby33-ci: build-ruby33
docker run \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
newrelic-lambda-layers-ruby33

publish-ruby33-local: build-ruby33
docker run \
-e AWS_PROFILE \
-v "${HOME}/.aws:/home/newrelic-lambda-layers/.aws" \
newrelic-lambda-layers-ruby33
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ cd ..
```

```
cd nodejs;
fallwith marked this conversation as resolved.
Show resolved Hide resolved
cd nodejs
./publish-layers.sh
cd ..
```

```
cd java;
cd ruby
./publish-layers.sh
cd ..
```

```
cd extension;
cd java
./publish-layers.sh
cd ..
```

```
cd extension
./publish-layer.sh
cd ..
```
Expand Down Expand Up @@ -68,6 +74,7 @@ These steps will help you configure the layers correctly:
3. Update your functions handler to point to the newly attached layer in the console for your function:
* Python: `newrelic_lambda_wrapper.handler`
* Node: `newrelic-lambda-wrapper.handler`
* Ruby: `newrelic_lambda_wrapper.handler`
* Java:
* RequestHandler implementation: `com.newrelic.java.HandlerWrapper::handleRequest`
* RequestStreamHandlerWrapper implementation: `com.newrelic.java.HandlerWrapper::handleStreamsRequest`
Expand Down
28 changes: 28 additions & 0 deletions dockerfiles/Dockerfile.ruby32
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ruby:3.2

RUN apt update

# curl - downloads the prebuilt NR Lambda extension
# python3/pip3 - for the AWS CLI
# zip/unzip - for building AWS Lambda layers .zip files
RUN apt install -y curl python3 python3-pip unzip zip

RUN useradd -m newrelic-lambda-layers
USER newrelic-lambda-layers
WORKDIR /home/newrelic-lambda-layers
RUN pip3 install -U awscli --user --no-cache-dir --break-system-packages
ENV PATH /home/newrelic-lambda-layers/.local/bin/:$PATH

# Ruby layer building depends on the shared `libBuild.sh` script but is
# otherwise independent. Copy over only what we need to build Ruby layers.
COPY --chown=newrelic-lambda-layers libBuild.sh .
COPY --chown=newrelic-lambda-layers ruby ruby/

WORKDIR ruby

# Run ruby/bin/clean just in case Docker is being ran from a developer's
# workstation and their git clone directory has some stray files that could
# conflict.
RUN ./bin/clean

CMD ./publish-layers.sh ruby3.2
28 changes: 28 additions & 0 deletions dockerfiles/Dockerfile.ruby33
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ruby:3.3

RUN apt update

# curl - downloads the prebuilt NR Lambda extension
# python3/pip3 - for the AWS CLI
# zip/unzip - for building AWS Lambda layers .zip files
RUN apt install -y curl python3 python3-pip unzip zip

RUN useradd -m newrelic-lambda-layers
USER newrelic-lambda-layers
WORKDIR /home/newrelic-lambda-layers
RUN pip3 install -U awscli --user --no-cache-dir --break-system-packages
ENV PATH /home/newrelic-lambda-layers/.local/bin/:$PATH

# Ruby layer building depends on the shared `libBuild.sh` script but is
# otherwise independent. Copy over only what we need to build Ruby layers.
COPY --chown=newrelic-lambda-layers libBuild.sh .
COPY --chown=newrelic-lambda-layers ruby ruby/

WORKDIR ruby

# Run ruby/bin/clean just in case Docker is being ran from a developer's
# workstation and their git clone directory has some stray files that could
# conflict.
RUN ./bin/clean

CMD ./publish-layers.sh ruby3.3
9 changes: 9 additions & 0 deletions libBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ function layer_name_str() {
"nodejs20.x")
rt_part="NodeJS20X"
;;
"ruby3.2")
rt_part="Ruby32"
;;
"ruby3.3")
rt_part="Ruby33"
;;
esac

case $2 in
Expand Down Expand Up @@ -179,6 +185,9 @@ function s3_prefix() {
"nodejs20.x")
name="nr-nodejs20.x"
;;
"ruby3.3")
name="nr-ruby3.3"
;;
esac

echo $name
Expand Down
6 changes: 6 additions & 0 deletions ruby/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.bundle/
dist/
log/
support/node_modules/
support/log/
Gemfile.lock
fallwith marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AllCops:
NewCops: enable
TargetRubyVersion: 3.2
Exclude:
- 'test/support/node_modules/**/*'

Lint/UnusedMethodArgument:
Exclude:
- 'test/support/src/handler.rb'
11 changes: 11 additions & 0 deletions ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'newrelic_rpm'

group :development do
gem 'minitest', '~> 5.22'
gem 'rake'
gem 'rubocop', '~> 1.60'
end
58 changes: 58 additions & 0 deletions ruby/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# New Relic AWS Lambda layer for wrapping Ruby Lambda functions

## Overview

This 'ruby' subdirectory contains content for building and publishing a
New Relic's AWS Lambda layer for use with Ruby Lambda functions.

The layer will include the latest stable version of the New Relic Ruby agent gem,
`newrelic_rpm`, the latest New Relic Lambda
[extension](https://github.com/newrelic/newrelic-lambda-extension),
and the lightweight `newrelic_lambda_wrapper.rb` that wraps untouched customer
Lambda functions for observability.

A layer is created for every region, architecture, and Ruby runtime combination.


## Layer building and publishing

With Ruby v3.2 or v3.3 `bundle` binary in your path:

```shell
./publish_layers.sh ruby3.2

# or

./publish_layers.sh ruby3.3
```


## Developer instructions

- Clone the repository and change to the 'ruby' directory
- Run `bin/setup`
- Run `bundle exec rake test` to run the unit tests

NOTES:

- To test Ruby agent changes that are available locally or on GitHub, alter
`Gemfile` accordingly.
- `Gemfile.lock` is Git ignored so that the latest stable agent version is
always fetched
- For alignment with the Node.js and Python content in this repository, the
[Serverless](https://www.serverless.com/) Node.js module and the
[serverless-offline](https://github.com/dherault/serverless-offline) plugin
are used for simulated AWS Lambda testing.
- All Serverless related content can be found at `test/support`
- A simple representation of a customer Lambda function is available at
`test/support/src/handler.rb`.
- The customer Lambda function is referenced via the `NEW_RELIC_LAMBDA_HANDLER`
environment variable defined in `test/support/serverless.yml. That variable
is formatted as `<PATH_TO_RUBY_FILE>.<LAMBDA_HANDLER_RUBY_METHOD_NAME>`,
with the path part of the string optionally including the `.rb` file extension
part of the path.
- While it is recommended that the system building new layers be set up to run
the same Ruby version as the layer is targetting, a simple `mv` hack currently
exists in `publish-layers.sh` that would allow say an instance of Ruby 3.3 to
build a Ruby 3.2 layer.
- By default, the `ruby/publish-layers.sh` script will use the prebuilt extension version defined at `libBuild.sh` for the `EXTENSION_VERSION` variable. That variable can be changed to use other extension versions. To instead build a new extension from scratch, edit `ruby/publish-layers.sh` and point to a local git clone of the extension.
10 changes: 10 additions & 0 deletions ruby/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'minitest/test_task'

Minitest::TestTask.create(:test) do |t|
t.libs << 'test'
t.test_globs = ['test/**/*_test.rb']
end

task default: :test
6 changes: 6 additions & 0 deletions ruby/bin/clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -Eeuo pipefail

# for cleanup when conducting manual .zip file creation

rm -rf .bundle dist ruby Gemfile.lock extensions preview-extensions*
17 changes: 17 additions & 0 deletions ruby/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -Eeuo pipefail

bin/clean

if (command -v bundle >/dev/null); then
rm -rf .bundle
bundle install
else
echo "'bundle' command not found!"
exit -1
fi

cd test/support
npm install

echo 'Setup complete'
Loading