-
Notifications
You must be signed in to change notification settings - Fork 1
140 lines (132 loc) · 4.01 KB
/
lambda.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Build & Publish Layer
on:
workflow_dispatch:
inputs:
type:
type: choice
description: Type of package to use
options:
- production
- testing
required: true
version:
type: string
description: Version of the package to use
required: true
workflow_call:
inputs:
type:
type: string
description: Type of package to use
required: true
version:
type: string
description: Version of the package to use
required: true
outputs:
arn:
description: Layer ARN
value: ${{ jobs.publish.outputs.arn }}
secrets:
LAMBDA_PROD_PUBLISHER_ARN:
required: true
LAMBDA_STAGE_PUBLISHER_ARN:
required: true
jobs:
build:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PACKAGE_NAME: ${{ inputs.type == 'production' && 'solarwinds-apm' || '@solarwinds/solarwinds-apm' }}
PACKAGE_VERSION: ${{ inputs.version }}
YARN_ENABLE_IMMUTABLE_INSTALLS: false
steps:
- uses: actions/checkout@v4
with:
lfs: true
submodules: true
- uses: actions/setup-node@v4
with:
node-version: 20
- run: corepack enable
- run: yarn install
- run: yarn lambda $PACKAGE_NAME $PACKAGE_VERSION
- uses: actions/upload-artifact@v4
with:
name: layer.zip
path: lambda/layer.zip
publish:
needs: build
permissions:
id-token: write
outputs:
arn: ${{ steps.publish.outputs.arn }}
strategy:
matrix:
region: |-
${{
inputs.type == 'production' && fromJSON('[
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"eu-central-1",
"eu-north-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"sa-east-1",
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2"
]') || fromJSON('["us-east-1"]')
}}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: layer.zip
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.type == 'production' && secrets.LAMBDA_PROD_PUBLISHER_ARN || secrets.LAMBDA_STAGE_PUBLISHER_ARN }}
aws-region: ${{ matrix.region }}
- name: Calculate layer name
run: |
LAYER_NAME="solarwinds-apm-js"
if [[ "${{ inputs.type }}" != "production" ]]; then
LAYER_NAME="${LAYER_NAME}-${{ inputs.type }}"
else
LAYER_NAME="${LAYER_NAME}-$(echo '${{ inputs.version }}' | sed -r 's/\./_/g')"
fi
echo "LAYER_NAME=$LAYER_NAME" >> $GITHUB_ENV
- name: Publish
id: publish
run: |
LAYER_ARN=$(
aws lambda publish-layer-version \
--layer-name $LAYER_NAME \
--license-info "Apache 2.0" \
--compatible-runtimes nodejs22.x nodejs20.x nodejs18.x \
--zip-file fileb://layer.zip \
--query 'LayerVersionArn' \
--output text
)
echo "::notice::$LAYER_ARN"
echo "arn=$(echo $LAYER_ARN | sed 's/${{ matrix.region }}/<region>/')" >> $GITHUB_OUTPUT
- name: Make public
if: inputs.type == 'production'
run: |
LAYER_VERSION=$(
aws lambda list-layer-versions \
--layer-name $LAYER_NAME \
--query 'max_by(LayerVersions, &Version).Version'
)
aws lambda add-layer-version-permission \
--layer-name $LAYER_NAME \
--version-number $LAYER_VERSION \
--principal '*' \
--action lambda:GetLayerVersion \
--statement-id apm-js-add-permission