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

feat: allow ruby layer contains multiple runtimes (3.2 and 3.3) #1376

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
31 changes: 8 additions & 23 deletions .github/workflows/release-layer-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2.0'

- name: Install SAM
run: |
sudo apt-get update && sudo apt-get install wget unzip make -y
wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
sudo ./sam-installation/install --update

- name: Build
id: save-ruby-sdk-version
run: |
sam build -u -t template.yml
export GEM_PATH=$PWD/.aws-sam/build/OTelLayer/ruby/gems/3.2.0/
RUBY_SDK_VERSION=$(ruby -e 'require "opentelemetry-sdk"; puts OpenTelemetry::SDK::VERSION')
echo "RUBY_SDK_VERSION=$RUBY_SDK_VERSION" >> $GITHUB_OUTPUT
./build.sh
shell: bash
working-directory: ruby/src

- name: Zip the layer file
- name: Show directory contents
run: |
echo ${{ steps.save-ruby-sdk-version.outputs.RUBY_SDK_VERSION}}
./zip_ruby_layer.sh
working-directory: ruby/src
shell: bash
ls -al
working-directory: ruby/src/build

- uses: actions/upload-artifact@v4
name: Save assembled layer to build
with:
name: opentelemetry-ruby-layer.zip
path: ruby/src/opentelemetry-ruby-layer.zip
path: ruby/src/build/opentelemetry-ruby-layer.zip

publish-layer:
uses: ./.github/workflows/layer-publish.yml
Expand Down Expand Up @@ -77,7 +62,7 @@ jobs:
artifact-name: opentelemetry-ruby-layer.zip
layer-name: opentelemetry-ruby
component-version: ${{needs.build-layer.outputs.RUBY_SDK_VERSION}}
runtimes: ruby3.2
release-group: prod
runtimes: ruby3.2 ruby3.3
release-group: dev
aws_region: ${{ matrix.aws_region }}
secrets: inherit
2 changes: 1 addition & 1 deletion ruby/sample-apps/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
Properties:
LayerName: !Ref LayerName
Description: Opentelemetry Ruby layer
ContentUri: ./../src/layer
ContentUri: ./../src/otel/layer
CompatibleRuntimes:
- ruby3.2
Metadata:
Expand Down
7 changes: 7 additions & 0 deletions ruby/src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

mkdir -p build

docker build --progress plain -t aws-otel-lambda-ruby-layer otel
docker run --rm -v "$(pwd)/build:/out" aws-otel-lambda-ruby-layer
51 changes: 51 additions & 0 deletions ruby/src/otel/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM ubuntu:latest

RUN mkdir /build

COPY . /build

RUN apt-get update && apt-get install -y git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev zip

RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv \
&& git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build \
&& git clone https://github.com/rbenv/rbenv-default-gems.git ~/.rbenv/plugins/rbenv-default-gems \
&& echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile \
&& echo 'eval "$(rbenv init -)"' >> ~/.profile \
&& echo 'eval "$(rbenv init -)"' >> ~/.bashrc \
&& echo 'bundler' > ~/.rbenv/default-gems

RUN echo 'alias be="bundle exec"' >> ~/.bashrc
RUN echo 'alias be="bundle exec"' >> ~/.profile

# install rubies to build our gem against Gemfile
RUN . ~/.profile \
&& cd /root/.rbenv/plugins/ruby-build && git pull && cd - \
&& rbenv install 3.2.0 \
&& rbenv install 3.3.0

WORKDIR /build/layer

RUN . ~/.profile && rbenv local 3.2.0 && bundle install
RUN . ~/.profile && rbenv local 3.3.0 && bundle install

WORKDIR /root/.rbenv/versions/3.2.0/lib/ruby/gems/
RUN zip -r gems-3.2.0.zip 3.2.0/

WORKDIR /root/.rbenv/versions/3.3.0/lib/ruby/gems/
RUN zip -r gems-3.3.0.zip 3.3.0/

RUN ls -al /root/.rbenv/versions/3.2.0/lib/ruby/gems && ls -al /root/.rbenv/versions/3.3.0/lib/ruby/gems

# copy gems to /build/ruby/gems for zipping
RUN mkdir /build/ruby && mkdir /build/ruby/gems
WORKDIR /build/ruby/gems
RUN cp /root/.rbenv/versions/3.2.0/lib/ruby/gems/gems-3.2.0.zip . && unzip gems-3.2.0.zip && rm gems-3.2.0.zip
RUN cp /root/.rbenv/versions/3.3.0/lib/ruby/gems/gems-3.3.0.zip . && unzip gems-3.3.0.zip && rm gems-3.3.0.zip
RUN ls -al /build/ruby/gems

# zip all the gems
WORKDIR /build
RUN cp layer/otel-handler . && cp layer/wrapper.rb .
RUN zip -r opentelemetry-ruby-layer.zip ruby/ otel-handler wrapper.rb

CMD cp /build/opentelemetry-ruby-layer.zip /out/opentelemetry-ruby-layer.zip
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ -z "${OTEL_RUBY_INSTRUMENTATION_NET_HTTP_ENABLED}" ]; then
export OTEL_RUBY_INSTRUMENTATION_NET_HTTP_ENABLED=false;
fi

export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION";
export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME";
if [ -z "${OTEL_RESOURCE_ATTRIBUTES}" ]; then
export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES";
else
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ruby/src/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Resources:
Properties:
LayerName: !Ref LayerName
Description: Opentelemetry Ruby layer
ContentUri: ./layer
ContentUri: ./otel/layer
CompatibleRuntimes:
- ruby3.2
Metadata:
Expand Down
Loading