Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Mar 7, 2024
1 parent f61fa3e commit e33da23
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
70 changes: 67 additions & 3 deletions .github/workflows/build_publish_lambda_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,49 @@ permissions:
contents: read # This is required for actions/checkout

jobs:
# create one arm64 ec2 instance on aws as our runner
start_arm64_runner:
outputs:
matrix: ${{ steps.launch.outputs.matrix }} # this will be a json object mapping identifiers to labels and instance ids
runs-on: ubuntu-latest
steps:
- uses: getsentry/action-github-app-token@v3
id: github-token
with:
app_id: ${{ vars.APPLICATION_ID }}
private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}

- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.EC2_RUNNER_ARN }}
aws-region: us-east-1

- id: launch
uses: solarwindscloud/ec2-runner-action@main
with:
action: launch
matrix: | # one identifier per line
ubuntu:22.04
github-token: ${{ steps.github-token.outputs.token }}
runner-user: github
runner-directory: /gh
instance-type: t4g.medium
ami-name: gha-arm64-ubuntu22-.*
ami-owner: "858939916050"
subnet-id: subnet-0fd499f8a50e41807
security-group-ids: sg-0fd8d8cd6effda4a5
tags: |
Name=xuan-cao-ec2-runner
# build layer on arm64 and amd64, then upload to artifacts
# act -j build_layer --container-architecture linux/arm64 --secret-file act.secrets
build_layer:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch:
- x86_64
- arm64
steps:
- uses: actions/checkout@v3
- uses: aws-actions/setup-sam@v2
Expand Down Expand Up @@ -57,10 +91,11 @@ jobs:
- us-east-1
arch:
- x86_64
- arm64
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.STAGING_LAMBDA_PUSH_ARN }}
role-to-assume: ${{ secrets.LAMBDA_PUBLISHER_ARN }}
aws-region: ${{ matrix.aws_region }}

- name: extract layer zip from artifacts
Expand All @@ -69,11 +104,16 @@ jobs:
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda

- name: extract current solarwinds_apm version
run: |
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/layer/Gemfile | awk -F"'" '{print $4}')
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_ENV
- name: publish lambda layer
run: |
cd lambda/
aws lambda publish-layer-version \
--layer-name solarwinds-ruby-layer-${{ matrix.arch }} \
--layer-name solarwinds-ruby-layer-$SOLARWINDS_APM_VERSION-${{ matrix.arch }} \
--license-info "Apache 2.0" \
--compatible-architectures ${{ matrix.arch }} \
--compatible-runtimes ruby3.2 \
Expand All @@ -93,3 +133,27 @@ jobs:
--principal '*' \
--version-number $latest_version \
--output text
terminate_arm64_runner:
if: ${{ always() }}
needs:
- start_arm64_runner
- build_layer
- publish_layer
runs-on: ubuntu-latest
steps:
- uses: getsentry/action-github-app-token@v3
id: github-token
with:
app_id: ${{ vars.APPLICATION_ID }}
private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}

- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.EC2_RUNNER_ARN }}
aws-region: us-east-1
- uses: solarwindscloud/ec2-runner-action@main
with:
action: terminate
github-token: ${{ steps.github-token.outputs.token }}
matrix: ${{ needs.start_arm64_runner.outputs.matrix }} # passing a matrix will terminate all runners, not just one
15 changes: 7 additions & 8 deletions lambda/layer/Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
source 'https://rubygems.org'

gem 'rack'
# gem 'solarwinds_apm', '6.0.0.prev6'
gem 'solarwinds_apm', '6.0.0.prev6'

# source 'https://rubygems.pkg.github.com/solarwinds' do
# gem 'opentelemetry-metrics-api', '0.0.1'
# gem 'opentelemetry-metrics-sdk', '0.0.1'
# gem 'opentelemetry-exporter-otlp', '0.26.1'
# gem 'opentelemetry-instrumentation-aws_lambda', '0.0.1'
# end
source 'https://rubygems.pkg.github.com/solarwinds' do
gem 'opentelemetry-metrics-api', '0.0.1'
gem 'opentelemetry-metrics-sdk', '0.0.1'
gem 'opentelemetry-exporter-otlp', '0.26.1'
gem 'opentelemetry-instrumentation-aws_lambda', '0.0.1'
end
1 change: 0 additions & 1 deletion lambda/layer/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

build-OTelLayer:
mkdir -p $(ARTIFACTS_DIR)/ruby/gems/3.2.0
mkdir -p $(ARTIFACTS_DIR)/ruby/lib/
mkdir -p $(ARTIFACTS_DIR)/solarwinds-apm/
bundle config set --global silence_root_warning 1
bundle config set --local path 'ruby'
Expand Down
5 changes: 2 additions & 3 deletions lambda/zip_layer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ main() {
esac
done

cd .aws-sam/build/
zip -qr ../../"$layerName".zip OTelLayer/
cd -
(cd .aws-sam/build/OTelLayer/ && zip -qr ../"$layerName".zip .)
mv .aws-sam/build/"$layerName".zip .
}

main "$@"

0 comments on commit e33da23

Please sign in to comment.