-
Notifications
You must be signed in to change notification settings - Fork 3
116 lines (101 loc) · 3.62 KB
/
build_publish_lambda_layer.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) 2023 SolarWinds, LLC.
# All rights reserved.
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
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
run: |
uname -a
./build.sh
shell: bash
working-directory: lambda/
env:
GITHUB_RUBY_TOKEN: ${{ secrets.PACKAGE_GITHUB_TOKEN }}
MATRIX_ARCH: ${{ matrix.arch }}
SOLARWINDS_SOURCE: ${{ github.event.inputs.solarwinds-source }}
- name: Show directory contents
run: |
ls -al
working-directory: lambda/
- name: Upload to artifact
uses: actions/upload-artifact@v4
with:
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda/build/ruby-layer-${{ matrix.arch }}.zip
# extract the built layer from artifacts, then publish it based on region
publish_layer:
needs:
- build_layer
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
aws_region:
- us-east-1
arch:
- x86_64
- arm64
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.LAMBDA_PUBLISHER_ARN }}
aws-region: ${{ matrix.aws_region }}
- name: extract layer zip from artifacts
uses: actions/download-artifact@v4
with:
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda
- name: extract current solarwinds_apm version
run: |
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/otel/layer/Gemfile | awk -F"'" '{print $4}')
APM_VERSION="${APM_VERSION//./_}"
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_ENV
- name: publish lambda layer
run: |
cd lambda/
aws lambda publish-layer-version \
--layer-name solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }} \
--license-info "Apache 2.0" \
--compatible-architectures ${{ matrix.arch }} \
--compatible-runtimes ruby3.2 ruby3.3 \
--zip-file fileb://ruby-layer-${{ matrix.arch }}.zip \
--query 'LayerVersionArn' \
--compatible-architectures ${{ matrix.arch }} \
--output text
- name: grant permissions to public for the published layer
run: |
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 \
--statement-id apm-ruby-add-permission \
--action lambda:GetLayerVersion \
--principal '*' \
--version-number $latest_version \
--output text