-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd86aba
commit 7d2c443
Showing
12 changed files
with
645 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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 | ||
secrets: | ||
GITHUB_TOKEN: | ||
required: true | ||
LAMBDA_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 | ||
- 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 | ||
strategy: | ||
matrix: | ||
region: | ||
- 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: ${{ secrets.LAMBDA_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 | ||
run: | | ||
LAYER_ARN=$( | ||
aws lambda publish-layer-version \ | ||
--layer-name $LAYER_NAME \ | ||
--license-info "Apache 2.0" \ | ||
--compatible-architectures x86_64 arm64 \ | ||
--compatible-runtimes nodejs20.x nodejs16.x nodejs18.x \ | ||
--zip-file fileb://layer.zip \ | ||
--query 'LayerVersionArn' \ | ||
--output text | ||
) | ||
echo "::notice::$LAYER_ARN" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
layer.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
nodeLinker: node-modules | ||
supportedArchitectures: | ||
os: | ||
- linux | ||
cpu: | ||
- arm64 | ||
- x64 | ||
libc: | ||
- glibc | ||
npmScopes: | ||
solarwinds: | ||
npmRegistryServer: https://npm.pkg.github.com | ||
npmAuthToken: ${GITHUB_TOKEN:-GITHUB_TOKEN} | ||
npmAlwaysAuth: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@solarwinds-apm/lambda-shim", | ||
"private": true, | ||
"packageManager": "yarn@4.0.2", | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.3.0", | ||
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.46.0", | ||
"@opentelemetry/exporter-trace-otlp-grpc": "^0.46.0", | ||
"{{name}}": "{{version}}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require("{{name}}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/solarwinds-apm/shim.cjs" | ||
export OTEL_EXPORTER_OTLP_PROTOCOL="grpc" | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
Copyright 2023-2024 SolarWinds Worldwide, LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
const { execSync } = require("node:child_process") | ||
const { | ||
cpSync, | ||
createWriteStream, | ||
readdirSync, | ||
readFileSync, | ||
rmSync, | ||
writeFileSync, | ||
} = require("node:fs") | ||
const { argv } = require("node:process") | ||
const archiver = require("archiver") | ||
const ora = require("ora") | ||
|
||
const [name, version] = argv.slice(2) | ||
|
||
const rm = (...args) => { | ||
try { | ||
rmSync(...args) | ||
} catch { | ||
// ignore | ||
} | ||
} | ||
|
||
const replace = (file) => { | ||
let contents = readFileSync(file, { encoding: "utf-8" }) | ||
contents = contents.replace("{{name}}", name).replace("{{version}}", version) | ||
writeFileSync(file, contents) | ||
} | ||
|
||
rm("lambda/layer.zip") | ||
rm("node_modules/.lambda", { recursive: true }) | ||
cpSync("lambda", "node_modules/.lambda", { recursive: true }) | ||
replace("node_modules/.lambda/package.json") | ||
replace("node_modules/.lambda/shim.cjs") | ||
|
||
execSync("touch yarn.lock && yarn install", { | ||
cwd: "node_modules/.lambda", | ||
env: { ...process.env, NODE_ENV: "production" }, | ||
stdio: "inherit", | ||
}) | ||
|
||
const scope = `node_modules/.lambda/node_modules/${ | ||
name === "solarwinds-apm" ? "@solarwinds-apm" : "@solarwinds" | ||
}` | ||
for (const entry of readdirSync(scope)) { | ||
if (entry.includes("bindings-") && !entry.includes("serverless")) { | ||
rmSync(`${scope}/${entry}`, { recursive: true }) | ||
} | ||
} | ||
|
||
const spinner = ora("building layer") | ||
|
||
const archive = archiver("zip", { zlib: { level: 9 } }) | ||
archive | ||
.on("error", (err) => { | ||
spinner.fail(err.message) | ||
throw err | ||
}) | ||
.on("warning", (warn) => { | ||
spinner.fail(warn.message) | ||
throw warn | ||
}) | ||
.on("entry", (e) => { | ||
spinner.text = e.name | ||
spinner.render() | ||
}) | ||
|
||
const out = createWriteStream("lambda/layer.zip") | ||
out.on("error", (err) => { | ||
spinner.fail(err.message) | ||
throw err | ||
}) | ||
archive.pipe(out) | ||
|
||
archive.directory( | ||
"node_modules/.lambda/node_modules/", | ||
"solarwinds-apm/node_modules/", | ||
) | ||
archive.file("node_modules/.lambda/shim.cjs", { | ||
name: "solarwinds-apm/shim.cjs", | ||
}) | ||
archive.file("node_modules/.lambda/wrapper", { | ||
name: "solarwinds-apm/wrapper", | ||
mode: 0o755, | ||
}) | ||
|
||
archive.finalize().then(() => spinner.succeed("layer built")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.