Skip to content

Commit 54539c3

Browse files
authored
improve layer build for 7.0.0
1 parent d289c6e commit 54539c3

File tree

5 files changed

+84
-67
lines changed

5 files changed

+84
-67
lines changed

.github/workflows/build_publish_lambda_layer.yml

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ on:
2424
- staging
2525
- production
2626

27+
ruby-version:
28+
description: 'Supported ruby version for lambda layer'
29+
default: '3.2 3.3 3.4'
30+
2731
permissions:
2832
id-token: write # This is required for requesting the JWT
2933
contents: read # This is required for actions/checkout
@@ -32,12 +36,19 @@ jobs:
3236
# build layer on arm64 and amd64, then upload to artifacts
3337
# act -j build_layer --container-architecture linux/arm64
3438
build_layer:
35-
runs-on: ubuntu-latest
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
arch:
43+
- x86_64
44+
- arm64
45+
46+
runs-on: ${{ matrix.arch == 'arm64' && fromJSON('{"group":"apm-arm-runner"}') || 'ubuntu-latest' }}
3647

3748
steps:
3849
- uses: actions/checkout@v4
3950

40-
- name: Build ruby lambda layer
51+
- name: Build ruby lambda layer on ${{ matrix.arch }}
4152
run: |
4253
uname -a
4354
./build.sh
@@ -46,6 +57,9 @@ jobs:
4657
env:
4758
GITHUB_RUBY_TOKEN: ${{ secrets.PACKAGE_GITHUB_TOKEN }}
4859
SOLARWINDS_SOURCE: ${{ github.event.inputs.solarwinds-source }}
60+
PUBLISH_DEST: ${{ github.event.inputs.publish-dest }}
61+
ALLOWED_RUBY_VERSION: ${{ github.event.inputs.ruby-version }}
62+
ARCHITECTURE: ${{ matrix.arch }}
4963

5064
- name: Show directory contents
5165
run: |
@@ -55,30 +69,47 @@ jobs:
5569
- name: Upload to artifact
5670
uses: actions/upload-artifact@v4
5771
with:
58-
name: ruby-layer.zip
59-
path: lambda/build/ruby-layer.zip
72+
name: ruby-layer-${{ matrix.arch }}.zip
73+
path: lambda/build/ruby-layer-${{ matrix.arch }}.zip
6074

6175
# extract the built layer from artifacts, then scan it with reverselab
6276
reverselab_scan_layer:
6377
needs:
6478
- build_layer
65-
runs-on: ubuntu-latest
6679
strategy:
6780
fail-fast: false
81+
matrix:
82+
arch:
83+
- x86_64
84+
- arm64
85+
86+
runs-on: ubuntu-latest
87+
88+
outputs:
89+
apm_ruby_version: ${{ steps.version.outputs.SOLARWINDS_APM_VERSION }}
6890

6991
steps:
7092
- uses: actions/checkout@v4
7193

7294
- name: extract layer zip from artifacts
7395
uses: actions/download-artifact@v4
7496
with:
75-
name: ruby-layer.zip
97+
name: ruby-layer-${{ matrix.arch }}.zip
7698
path: lambda
7799

78100
- name: extract current solarwinds_apm version
101+
id: version
79102
run: |
80-
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/otel/layer/Gemfile | awk -F"'" '{print $4}')
103+
if [ $SOLARWINDS_SOURCE = 'Local' ]; then \
104+
APM_VERSION=$(ruby -r './lib/solarwinds_apm/version.rb' -e 'puts SolarWindsAPM::Version::STRING'); \
105+
else \
106+
apt-get update && apt-get install -y jq curl; \
107+
APM_VERSION=$(curl -s https://rubygems.org/api/v1/gems/solarwinds_apm.json | jq -r .version); \
108+
fi
81109
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_ENV
110+
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_OUTPUT
111+
env:
112+
SOLARWINDS_SOURCE: ${{ github.event.inputs.solarwinds-source }}
82113

83114
- name: Scan build artifact on the Portal
84115
id: rl-scan
@@ -88,12 +119,12 @@ jobs:
88119

89120
uses: reversinglabs/gh-action-rl-scanner-cloud-only@v1
90121
with:
91-
artifact-to-scan: ./lambda/ruby-layer.zip
122+
artifact-to-scan: ./lambda/ruby-layer-${{ matrix.arch }}.zip
92123
rl-verbose: true
93124
rl-portal-server: solarwinds
94125
rl-portal-org: SolarWinds
95126
rl-portal-group: SaaS-Agents-SWO
96-
rl-package-url: solarwinds-apm-ruby/apm-ruby-lambda-layer@${{ env.SOLARWINDS_APM_VERSION }}
127+
rl-package-url: solarwinds-apm-ruby/apm-ruby-lambda-layer-${{ matrix.arch }}@${{ env.SOLARWINDS_APM_VERSION }}
97128

98129
- name: report the scan status
99130
if: success() || failure()
@@ -104,9 +135,9 @@ jobs:
104135
# extract the built layer from artifacts, then publish it based on region
105136
publish_layer:
106137
needs:
107-
- build_layer
108-
runs-on: ubuntu-latest
138+
- reverselab_scan_layer
109139
strategy:
140+
fail-fast: false
110141
matrix:
111142
aws_region:
112143
- ap-northeast-1
@@ -125,6 +156,11 @@ jobs:
125156
- us-east-2
126157
- us-west-1
127158
- us-west-2
159+
arch:
160+
- x86_64
161+
- arm64
162+
163+
runs-on: ubuntu-latest
128164

129165
steps:
130166
- uses: actions/checkout@v4
@@ -138,30 +174,33 @@ jobs:
138174
- name: extract layer zip from artifacts
139175
uses: actions/download-artifact@v4
140176
with:
141-
name: ruby-layer.zip
177+
name: ruby-layer-${{ matrix.arch }}.zip
142178
path: lambda
143179

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

150189
- name: publish lambda layer
151190
run: |
152191
cd lambda/
153192
aws lambda publish-layer-version \
154-
--layer-name solarwinds-apm-ruby-${{ env.SOLARWINDS_APM_VERSION }} \
193+
--layer-name solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }} \
155194
--license-info "Apache 2.0" \
156-
--compatible-architectures x86_64 arm64 \
157-
--compatible-runtimes ruby3.2 ruby3.3 ruby3.4 \
158-
--zip-file fileb://ruby-layer.zip \
195+
--compatible-architectures ${{ matrix.arch }} \
196+
--compatible-runtimes ${{ env.LAMBDA_RUBY_VERSION }} \
197+
--zip-file fileb://ruby-layer-${{ matrix.arch }}.zip \
159198
--query 'LayerVersionArn' \
160199
--output text
161200
162201
- name: grant permissions to public for the published layer
163202
run: |
164-
layer_name=solarwinds-apm-ruby-${{ env.SOLARWINDS_APM_VERSION }}
203+
layer_name=solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }}
165204
latest_version=$(aws lambda list-layer-versions --layer-name $layer_name | jq -r '.LayerVersions | max_by(.Version) | .Version')
166205
aws lambda add-layer-version-permission \
167206
--layer-name $layer_name \

.github/workflows/run_unit_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
paths-ignore:
1111
- 'test/Dockerfile'
1212
- '.github/*'
13+
- 'lambda/*'
1314
workflow_dispatch:
1415

1516
jobs:

lambda/build.sh

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#!/bin/sh
2-
set -e
2+
set -xe
33

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

1617
mkdir -p build
1718

18-
for ruby_version in 3.2 3.3 3.4; do
19+
for ruby_version in $ALLOWED_RUBY_VERSION; do
1920
docker build --no-cache \
2021
--build-arg RUBY_VERSION=${ruby_version} \
2122
--progress plain \
@@ -26,7 +27,12 @@ for ruby_version in 3.2 3.3 3.4; do
2627
done
2728

2829
cd build/
29-
mkdir solarwinds-apm && mkdir ruby && mkdir ruby/gems
30-
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/
30+
mkdir -p ruby/gems
31+
32+
for ruby_version in $ALLOWED_RUBY_VERSION; do
33+
unzip -q gems-$ruby_version.0.zip -d ruby/gems/
34+
done
35+
36+
mkdir solarwinds-apm
3137
cp ../otel/layer/otel_wrapper.rb . && cp ../otel/layer/wrapper solarwinds-apm/
32-
zip -qr ruby-layer.zip ruby/ solarwinds-apm/ otel_wrapper.rb
38+
zip -qr ruby-layer-${ARCHITECTURE}.zip ruby/ solarwinds-apm/ otel_wrapper.rb

lambda/otel/Dockerfile

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,15 @@ FROM public.ecr.aws/sam/build-ruby${RUBY_VERSION}:latest
44
ARG RUBY_VERSION
55
ENV RUBY_VERSION=${RUBY_VERSION}
66

7-
RUN mkdir /build
8-
COPY . /build
9-
107
WORKDIR /build/layer
11-
RUN bundle config set --local path 'ruby'
8+
COPY . /build
9+
RUN mkdir -p ruby/ruby/${RUBY_VERSION}.0
1210

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

16-
# Install dependencies
17-
RUN bundle update
18-
19-
# Install wget
20-
RUN sh -c '(command -v dnf && dnf install -y wget) || (command -v yum && yum install -y wget)'
21-
22-
# Install aarch64 version of protobuf gem
23-
ENV ARCH=aarch64
24-
RUN PROTOBUF_VERSION=$(bundle exec ruby -e 'puts Gem.loaded_specs["google-protobuf"].version.to_s') && \
25-
wget "https://rubygems.org/downloads/google-protobuf-${PROTOBUF_VERSION}-${ARCH}-linux-gnu.gem" && \
26-
bundle exec gem install "google-protobuf-${PROTOBUF_VERSION}-${ARCH}-linux-gnu.gem"
27-
28-
# Install solarwinds_apm gem (from file, if exists; for local build only)
29-
RUN gem_file=$(cat gem_file.txt) && \
30-
if [ -f "$gem_file" ]; then \
31-
gem install $gem_file; \
32-
bundle exec gem uninstall solarwinds_apm; \
33-
mv /var/lang/lib/ruby/gems/${RUBY_VERSION}.0/gems/solarwinds_apm-*/ /build/layer/ruby/ruby/${RUBY_VERSION}.0/gems/; \
34-
mv /var/lang/lib/ruby/gems/${RUBY_VERSION}.0/specifications/solarwinds_apm-* /build/layer/ruby/ruby/${RUBY_VERSION}.0/specifications/; \
35-
fi
14+
RUN gem_file=$(ls | grep solarwinds_apm-*.gem 2>/dev/null || true) && \
15+
gem install ${gem_file:-solarwinds_apm} --install-dir ruby/ruby/${RUBY_VERSION}.0 --no-document
3616

3717
# Clean up cache and docs
3818
RUN rm -rf /build/layer/ruby/ruby/${RUBY_VERSION}.0/cache/* && \

lambda/otel/layer/Gemfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)