Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7b28f25
improve layer build
xuan-cao-swi Jul 24, 2025
c27a5d4
update version extract
xuan-cao-swi Jul 24, 2025
fced5e2
Update Gemfile
xuan-cao-swi Jul 24, 2025
703ba77
gem install to directory
xuan-cao-swi Jul 25, 2025
c2754d3
Merge branch 'lambda-fix' of github.com:solarwinds/apm-ruby into lamb…
xuan-cao-swi Jul 25, 2025
c756a6b
update version extraction for uploading layer
xuan-cao-swi Jul 25, 2025
ed8a9dc
Merge branch 'main' into lambda-fix
cheempz Jul 25, 2025
e3ba115
fix the layer name
xuan-cao-swi Jul 25, 2025
cc8e834
refactor
xuan-cao-swi Jul 28, 2025
71d43ef
refactor
xuan-cao-swi Jul 28, 2025
81a2621
refactor
xuan-cao-swi Jul 28, 2025
9b97dbb
refactor
xuan-cao-swi Jul 28, 2025
67db14c
remove gemfile
xuan-cao-swi Jul 28, 2025
26a7060
fix arch
xuan-cao-swi Jul 29, 2025
fe3e12c
test
xuan-cao-swi Jul 30, 2025
338f315
update
xuan-cao-swi Jul 30, 2025
cbcbc07
update
xuan-cao-swi Jul 30, 2025
423c956
update
xuan-cao-swi Jul 30, 2025
09bde6c
update
xuan-cao-swi Jul 30, 2025
794e39a
update
xuan-cao-swi Jul 30, 2025
c8abc5e
update
xuan-cao-swi Jul 30, 2025
fc8a540
try qemu
xuan-cao-swi Jul 30, 2025
33448e3
update
xuan-cao-swi Jul 30, 2025
a33a788
update
xuan-cao-swi Jul 30, 2025
3ec7bc7
update
xuan-cao-swi Jul 30, 2025
78a4d1e
update
xuan-cao-swi Jul 30, 2025
b4e6faf
update
xuan-cao-swi Jul 31, 2025
f5eff75
update
xuan-cao-swi Jul 31, 2025
0e78ba3
update
xuan-cao-swi Jul 31, 2025
c8ddc2c
update
xuan-cao-swi Jul 31, 2025
1d79e97
update
xuan-cao-swi Jul 31, 2025
a59e9b1
update
xuan-cao-swi Jul 31, 2025
b93d019
arm64 for all ruby version big decimal
xuan-cao-swi Jul 31, 2025
28f9225
Revert "arm64 for all ruby version big decimal"
xuan-cao-swi Jul 31, 2025
33e06c5
update
xuan-cao-swi Aug 1, 2025
d625ddb
update
xuan-cao-swi Aug 1, 2025
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
79 changes: 59 additions & 20 deletions .github/workflows/build_publish_lambda_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ on:
- staging
- production

ruby-version:
description: 'Supported ruby version for lambda layer'
default: '3.2 3.3 3.4'

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
Expand All @@ -32,12 +36,19 @@ jobs:
# build layer on arm64 and amd64, then upload to artifacts
# act -j build_layer --container-architecture linux/arm64
build_layer:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch:
- x86_64
- arm64

runs-on: ${{ matrix.arch == 'arm64' && fromJSON('{"group":"apm-arm-runner"}') || 'ubuntu-latest' }}

steps:
- uses: actions/checkout@v4

- name: Build ruby lambda layer
- name: Build ruby lambda layer on ${{ matrix.arch }}
run: |
uname -a
./build.sh
Expand All @@ -46,6 +57,9 @@ jobs:
env:
GITHUB_RUBY_TOKEN: ${{ secrets.PACKAGE_GITHUB_TOKEN }}
SOLARWINDS_SOURCE: ${{ github.event.inputs.solarwinds-source }}
PUBLISH_DEST: ${{ github.event.inputs.publish-dest }}
ALLOWED_RUBY_VERSION: ${{ github.event.inputs.ruby-version }}
ARCHITECTURE: ${{ matrix.arch }}

- name: Show directory contents
run: |
Expand All @@ -55,30 +69,47 @@ jobs:
- name: Upload to artifact
uses: actions/upload-artifact@v4
with:
name: ruby-layer.zip
path: lambda/build/ruby-layer.zip
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda/build/ruby-layer-${{ matrix.arch }}.zip

# extract the built layer from artifacts, then scan it with reverselab
reverselab_scan_layer:
needs:
- build_layer
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch:
- x86_64
- arm64

runs-on: ubuntu-latest

outputs:
apm_ruby_version: ${{ steps.version.outputs.SOLARWINDS_APM_VERSION }}

steps:
- uses: actions/checkout@v4

- name: extract layer zip from artifacts
uses: actions/download-artifact@v4
with:
name: ruby-layer.zip
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda

- name: extract current solarwinds_apm version
id: version
run: |
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/otel/layer/Gemfile | awk -F"'" '{print $4}')
if [ $SOLARWINDS_SOURCE = 'Local' ]; then \
APM_VERSION=$(ruby -r './lib/solarwinds_apm/version.rb' -e 'puts SolarWindsAPM::Version::STRING'); \
else \
apt-get update && apt-get install -y jq curl; \
APM_VERSION=$(curl -s https://rubygems.org/api/v1/gems/solarwinds_apm.json | jq -r .version); \
fi
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_ENV
Comment thread
cheempz marked this conversation as resolved.
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_OUTPUT
env:
SOLARWINDS_SOURCE: ${{ github.event.inputs.solarwinds-source }}

- name: Scan build artifact on the Portal
id: rl-scan
Expand All @@ -88,12 +119,12 @@ jobs:

uses: reversinglabs/gh-action-rl-scanner-cloud-only@v1
with:
artifact-to-scan: ./lambda/ruby-layer.zip
artifact-to-scan: ./lambda/ruby-layer-${{ matrix.arch }}.zip
rl-verbose: true
rl-portal-server: solarwinds
rl-portal-org: SolarWinds
rl-portal-group: SaaS-Agents-SWO
rl-package-url: solarwinds-apm-ruby/apm-ruby-lambda-layer@${{ env.SOLARWINDS_APM_VERSION }}
rl-package-url: solarwinds-apm-ruby/apm-ruby-lambda-layer-${{ matrix.arch }}@${{ env.SOLARWINDS_APM_VERSION }}

- name: report the scan status
if: success() || failure()
Expand All @@ -104,9 +135,9 @@ jobs:
# extract the built layer from artifacts, then publish it based on region
publish_layer:
needs:
- build_layer
runs-on: ubuntu-latest
- reverselab_scan_layer
strategy:
fail-fast: false
matrix:
aws_region:
- ap-northeast-1
Expand All @@ -125,6 +156,11 @@ jobs:
- us-east-2
- us-west-1
- us-west-2
arch:
- x86_64
- arm64

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
Expand All @@ -138,30 +174,33 @@ jobs:
- name: extract layer zip from artifacts
uses: actions/download-artifact@v4
with:
name: ruby-layer.zip
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda

- name: extract current solarwinds_apm version
- name: format version for aws lambda and define lambda ruby version
run: |
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/otel/layer/Gemfile | awk -F"'" '{print $4}')
APM_VERSION="${APM_VERSION//./_}"
APM_VERSION=$(echo "$APM_VERSION" | tr '.' '_')
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_ENV
echo "LAMBDA_RUBY_VERSION=$(echo $ALLOWED_RUBY_VERSION | sed 's/\([0-9]\+\.[0-9]\+\)/ruby\1/g')" >> $GITHUB_ENV
env:
APM_VERSION: ${{needs.reverselab_scan_layer.outputs.apm_ruby_version}}
ALLOWED_RUBY_VERSION: ${{ github.event.inputs.ruby-version }}

- name: publish lambda layer
run: |
cd lambda/
aws lambda publish-layer-version \
--layer-name solarwinds-apm-ruby-${{ env.SOLARWINDS_APM_VERSION }} \
--layer-name solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }} \
--license-info "Apache 2.0" \
--compatible-architectures x86_64 arm64 \
--compatible-runtimes ruby3.2 ruby3.3 ruby3.4 \
--zip-file fileb://ruby-layer.zip \
--compatible-architectures ${{ matrix.arch }} \
--compatible-runtimes ${{ env.LAMBDA_RUBY_VERSION }} \
--zip-file fileb://ruby-layer-${{ matrix.arch }}.zip \
--query 'LayerVersionArn' \
--output text

- name: grant permissions to public for the published layer
run: |
layer_name=solarwinds-apm-ruby-${{ env.SOLARWINDS_APM_VERSION }}
layer_name=solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }}
latest_version=$(aws lambda list-layer-versions --layer-name $layer_name | jq -r '.LayerVersions | max_by(.Version) | .Version')
aws lambda add-layer-version-permission \
--layer-name $layer_name \
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
paths-ignore:
- 'test/Dockerfile'
- '.github/*'
- 'lambda/*'
workflow_dispatch:

jobs:
Expand Down
34 changes: 20 additions & 14 deletions lambda/build.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/bin/sh
set -e
set -xe

echo "Build from source: $SOLARWINDS_SOURCE. Publish to $PUBLISH_DEST."
if [ $SOLARWINDS_SOURCE = 'Local' ]; then
cd ../
sudo apt-get update && sudo apt-get install -y --no-install-recommends ruby ruby-dev g++ make
sudo gem install bundler
sudo echo 'gem: --no-document' >> ~/.gemrc
sudo bundle config set --local without 'test development'
sudo gem build solarwinds_apm.gemspec
CURRENT_GEM=$(ls | grep solarwinds_apm-*.gem)
mv $CURRENT_GEM lambda/otel/layer/
cd -
cd ../
sudo apt-get update && sudo apt-get install -y --no-install-recommends ruby ruby-dev g++ make
sudo gem install bundler
sudo echo 'gem: --no-document' >> ~/.gemrc
sudo bundle config set --local without 'test development'
sudo gem build solarwinds_apm.gemspec
CURRENT_GEM=$(ls | grep solarwinds_apm-*.gem)
mv $CURRENT_GEM lambda/otel/layer/
cd -
fi

mkdir -p build

for ruby_version in 3.2 3.3 3.4; do
for ruby_version in $ALLOWED_RUBY_VERSION; do
docker build --no-cache \
--build-arg RUBY_VERSION=${ruby_version} \
--progress plain \
Expand All @@ -26,7 +27,12 @@ for ruby_version in 3.2 3.3 3.4; do
done

cd build/
mkdir solarwinds-apm && mkdir ruby && mkdir ruby/gems
unzip -q gems-3.2.0.zip -d ruby/gems/ && unzip -q gems-3.3.0.zip -d ruby/gems/ && unzip -q gems-3.4.0.zip -d ruby/gems/
mkdir -p ruby/gems

for ruby_version in $ALLOWED_RUBY_VERSION; do
unzip -q gems-$ruby_version.0.zip -d ruby/gems/
done

mkdir solarwinds-apm
cp ../otel/layer/otel_wrapper.rb . && cp ../otel/layer/wrapper solarwinds-apm/
zip -qr ruby-layer.zip ruby/ solarwinds-apm/ otel_wrapper.rb
zip -qr ruby-layer-${ARCHITECTURE}.zip ruby/ solarwinds-apm/ otel_wrapper.rb
28 changes: 4 additions & 24 deletions lambda/otel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,15 @@ FROM public.ecr.aws/sam/build-ruby${RUBY_VERSION}:latest
ARG RUBY_VERSION
ENV RUBY_VERSION=${RUBY_VERSION}

RUN mkdir /build
COPY . /build

WORKDIR /build/layer
RUN bundle config set --local path 'ruby'
COPY . /build
RUN mkdir -p ruby/ruby/${RUBY_VERSION}.0

# Save gem filename if present
RUN ls | grep solarwinds_apm-*.gem > gem_file.txt 2>/dev/null || true

# Install dependencies
RUN bundle update

# Install wget
RUN sh -c '(command -v dnf && dnf install -y wget) || (command -v yum && yum install -y wget)'

# Install aarch64 version of protobuf gem
ENV ARCH=aarch64
RUN PROTOBUF_VERSION=$(bundle exec ruby -e 'puts Gem.loaded_specs["google-protobuf"].version.to_s') && \
wget "https://rubygems.org/downloads/google-protobuf-${PROTOBUF_VERSION}-${ARCH}-linux-gnu.gem" && \
bundle exec gem install "google-protobuf-${PROTOBUF_VERSION}-${ARCH}-linux-gnu.gem"

# Install solarwinds_apm gem (from file, if exists; for local build only)
RUN gem_file=$(cat gem_file.txt) && \
if [ -f "$gem_file" ]; then \
gem install $gem_file; \
bundle exec gem uninstall solarwinds_apm; \
mv /var/lang/lib/ruby/gems/${RUBY_VERSION}.0/gems/solarwinds_apm-*/ /build/layer/ruby/ruby/${RUBY_VERSION}.0/gems/; \
mv /var/lang/lib/ruby/gems/${RUBY_VERSION}.0/specifications/solarwinds_apm-* /build/layer/ruby/ruby/${RUBY_VERSION}.0/specifications/; \
fi
RUN gem_file=$(ls | grep solarwinds_apm-*.gem 2>/dev/null || true) && \
gem install ${gem_file:-solarwinds_apm} --install-dir ruby/ruby/${RUBY_VERSION}.0 --no-document

# Clean up cache and docs
RUN rm -rf /build/layer/ruby/ruby/${RUBY_VERSION}.0/cache/* && \
Expand Down
9 changes: 0 additions & 9 deletions lambda/otel/layer/Gemfile

This file was deleted.

Loading