Skip to content

Commit

Permalink
Merge pull request #138 from solarwinds/lambda-build-with-checkout
Browse files Browse the repository at this point in the history
Lambda build with checkout
  • Loading branch information
xuan-cao-swi authored Jul 31, 2024
2 parents 86de3f7 + 663d4b7 commit d77ad9b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build_publish_lambda_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ name: Build publish lambda layer

on:
workflow_dispatch:
inputs:
solarwinds-source:
required: true
description: 'solarwinds_apm source for build layers, e.g. RubyGem, Local'
type: choice
default: 'RubyGem'
options:
- RubyGem
- Local

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
# build layer on arm64 and amd64, then upload to artifacts
# act -j build_layer --container-architecture linux/arm64
build_layer:
strategy:
fail-fast: false
Expand All @@ -34,6 +44,7 @@ jobs:
env:
GITHUB_RUBY_TOKEN: ${{ secrets.PACKAGE_GITHUB_TOKEN }}
MATRIX_ARCH: ${{ matrix.arch }}
SOLARWINDS_SOURCE: ${{ github.event.inputs.solarwinds-source }}

- name: Show directory contents
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
type: choice
default: 'RubyGem'
options:
- RubyGem
- GitHub
- RubyGem
- GitHub

solarwinds-version:
required: true
Expand Down
23 changes: 19 additions & 4 deletions lambda/build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
#!/bin/sh
set -e

if [ $SOLARWINDS_SOURCE = 'Local' ]; then
cd ../
sudo apt-get update && sudo apt-get install -y --no-install-recommends ruby ruby-dev g++ make swig bison
sudo gem install bundler
sudo echo 'gem: --no-document' >> ~/.gemrc
sudo bundle install --without development --without test
sudo bundle exec rake fetch_oboe_file["prod"]
sudo gem build solarwinds_apm.gemspec
CURRENT_GEM=$(ls | grep solarwinds_apm-*.gem)
mv $CURRENT_GEM lambda/otel/layer/
cd -
fi

mkdir -p build

docker build --build-arg BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${GITHUB_RUBY_TOKEN} \
docker build --no-cache \
--build-arg BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${GITHUB_RUBY_TOKEN} \
--progress plain \
-f otel/Dockerfile_3_2 \
-t sw-lambda-ruby-layer-3-2 otel

docker run --rm -v "$(pwd)/build:/out" sw-lambda-ruby-layer-3-2

docker build --build-arg BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${GITHUB_RUBY_TOKEN} \
docker build --no-cache \
--build-arg BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${GITHUB_RUBY_TOKEN} \
--progress plain \
-f otel/Dockerfile_3_3 \
-t sw-lambda-ruby-layer-3-3 otel
Expand All @@ -19,6 +34,6 @@ docker run --rm -v "$(pwd)/build:/out" sw-lambda-ruby-layer-3-3

cd build/
mkdir solarwinds-apm && mkdir ruby && mkdir ruby/gems
unzip gems-3.2.0.zip -d ruby/gems/ && unzip gems-3.3.0.zip -d ruby/gems/
unzip -q gems-3.2.0.zip -d ruby/gems/ && unzip -q gems-3.3.0.zip -d ruby/gems/
cp ../otel/layer/otel_wrapper.rb . && cp ../otel/layer/wrapper solarwinds-apm/
zip -r ruby-layer-$MATRIX_ARCH.zip ruby/ solarwinds-apm/ otel_wrapper.rb
zip -qr ruby-layer-$MATRIX_ARCH.zip ruby/ solarwinds-apm/ otel_wrapper.rb
16 changes: 14 additions & 2 deletions lambda/otel/Dockerfile_3_2
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ COPY . /build

WORKDIR /build/layer
RUN bundle config set --local path 'ruby'
RUN bundle update

RUN ls | grep solarwinds_apm-*.gem > gem_file.txt 2>/dev/null || true
RUN export gem_file=$(cat gem_file.txt) && \
if [ -f "$gem_file" ]; then \
echo "$gem_file exists."; \
sed -i '$ s/^/#/' /build/layer/Gemfile; \
bundle update; \
bundle exec gem install $gem_file; \
else \
bundle update; \
fi

RUN rm /build/layer/ruby/ruby/3.2.0/cache/*

WORKDIR /build/layer/ruby/ruby
RUN zip -r gems-3.2.0.zip 3.2.0/
RUN zip -qr gems-3.2.0.zip 3.2.0/

CMD cp /build/layer/ruby/ruby/gems-3.2.0.zip /out/gems-3.2.0.zip
16 changes: 14 additions & 2 deletions lambda/otel/Dockerfile_3_3
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ COPY . /build

WORKDIR /build/layer
RUN bundle config set --local path 'ruby'
RUN bundle update

RUN ls | grep solarwinds_apm-*.gem > gem_file.txt 2>/dev/null || true
RUN export gem_file=$(cat gem_file.txt) && \
if [ -f "$gem_file" ]; then \
echo "$gem_file exists."; \
sed -i '$ s/^/#/' /build/layer/Gemfile; \
bundle update; \
bundle exec gem install $gem_file; \
else \
bundle update; \
fi

RUN rm /build/layer/ruby/ruby/3.3.0/cache/*

WORKDIR /build/layer/ruby/ruby
RUN zip -r gems-3.3.0.zip 3.3.0/
RUN zip -qr gems-3.3.0.zip 3.3.0/

CMD cp /build/layer/ruby/ruby/gems-3.3.0.zip /out/gems-3.3.0.zip
2 changes: 1 addition & 1 deletion lambda/otel/layer/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ source 'https://rubygems.pkg.github.com/solarwinds' do
gem 'opentelemetry-metrics-sdk', '0.0.1'
end

gem 'solarwinds_apm', '6.0.1'
gem 'solarwinds_apm', '6.0.2'

0 comments on commit d77ad9b

Please sign in to comment.