-
Notifications
You must be signed in to change notification settings - Fork 240
ci: support AWS lambda when a tag release is created #2585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4f7d913
ci: support AWS lambda when a tag release
v1v 440a4a8
we play safe in a subfolder
v1v 50c6a5b
Use makefile to drive the AWS publish lambda
v1v 446b82d
Use a no dot folder otherwise npm does not work
v1v 42a8188
support release notes and ARN
v1v b89c3b1
remove the need for draft
v1v e66dd91
use -C instead
v1v a9b0dc3
publish: use top-level build-aws folder
v1v 9ed5b38
don't use quotes
v1v 3536616
ci: store the build-aws folder only
v1v 9c09f42
publish: use build-aws for all the files
v1v 6bfeeb6
publish: mkdir
v1v 4e5485c
publish: use ext to filter
v1v 7ee7170
publish: remove auto-generate release notes
v1v edf6bff
publish: add release notes URL
v1v 24a7a48
chore: use e.g rather than f.i
v1v 91b554a
publish: fix the filename
v1v c655ffc
ci: use the right slack
v1v 4de1525
ci: move post within the release meta-stage
v1v c8f562e
ci: report if a failure
v1v ea6d9cf
Update .ci/scripts/create-arn-table.sh
v1v 887962b
use build/aws folder
v1v 87ab753
release: f is a relative path
v1v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,107 @@ | ||
| SHELL = /bin/bash -eo pipefail | ||
|
|
||
| AWS_FOLDER = ../build/aws | ||
|
|
||
| export AWS_FOLDER | ||
|
|
||
| build: | ||
| rm -rf $(AWS_FOLDER) || true | ||
| mkdir -p $(AWS_FOLDER) | ||
| cd $(AWS_FOLDER); \ | ||
| npm init -y; \ | ||
| npm install --global-style https://github.com/elastic/apm-agent-nodejs#$(BRANCH_NAME); \ | ||
| mkdir nodejs; \ | ||
| mv node_modules nodejs | ||
| env: | ||
| env | ||
| dist: validate-branch-name build | ||
| rm -f $(BRANCH_NAME).zip || true | ||
| cd $(AWS_FOLDER) ; \ | ||
| zip -r $(BRANCH_NAME).zip nodejs | ||
|
|
||
| # List all the AWS regions | ||
| get-all-aws-regions: | ||
| @mkdir -p $(AWS_FOLDER) | ||
| @aws \ | ||
| ec2 \ | ||
| describe-regions \ | ||
| --region us-east-1 \ | ||
| --output json \ | ||
| --no-cli-pager \ | ||
| | jq -r '.Regions[].RegionName' > $(AWS_FOLDER)/.regions | ||
|
|
||
| # Publish the given LAYER in all the AWS regions | ||
| publish-in-all-aws-regions: validate-layer-name get-all-aws-regions | ||
| @mkdir -p $(AWS_FOLDER) | ||
v1v marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @while read AWS_DEFAULT_REGION; do \ | ||
| echo "publish '$(ELASTIC_LAYER_NAME)' in $${AWS_DEFAULT_REGION}"; \ | ||
| AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) publish > $(AWS_FOLDER)/$${AWS_DEFAULT_REGION}.publish; \ | ||
| AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) grant-public-layer-access; \ | ||
| done < $(AWS_FOLDER)/.regions | ||
|
|
||
| # Publish the given LAYER in the given AWS region | ||
| publish: validate-layer-name validate-aws-default-region | ||
| @aws lambda \ | ||
| --output json \ | ||
| publish-layer-version \ | ||
| --layer-name "$(ELASTIC_LAYER_NAME)" \ | ||
| --description "AWS Lambda Extension Layer for the Elastic APM Node.js Agent" \ | ||
| --license "Apache-2.0" \ | ||
| --compatible-runtimes nodejs14.x nodejs12.x nodejs10.x \ | ||
| --zip-file "fileb://./$(AWS_FOLDER)/$(BRANCH_NAME).zip" | ||
|
|
||
| # Grant public access to the given LAYER in the given AWS region | ||
| grant-public-layer-access: validate-layer-name validate-aws-default-region | ||
| @echo "[debug] $(ELASTIC_LAYER_NAME) with version: $$($(MAKE) -s --no-print-directory get-version)" | ||
| @aws lambda \ | ||
| --output json \ | ||
| add-layer-version-permission \ | ||
| --layer-name "$(ELASTIC_LAYER_NAME)" \ | ||
| --action lambda:GetLayerVersion \ | ||
| --principal '*' \ | ||
| --statement-id "$(ELASTIC_LAYER_NAME)" \ | ||
| --version-number $$($(MAKE) -s --no-print-directory get-version) > $(AWS_FOLDER)/$(AWS_DEFAULT_REGION).public | ||
|
|
||
| # Get the ARN Version for the AWS_REGIONS | ||
| # NOTE: jq -r .Version "$(AWS_FOLDER)/$(AWS_DEFAULT_REGION)" fails in the CI | ||
| # with 'parse error: Invalid numeric literal at line 1, column 5' | ||
| get-version: validate-aws-default-region | ||
| @grep '"Version"' "$(AWS_FOLDER)/$(AWS_DEFAULT_REGION).publish" | cut -d":" -f2 | sed 's/ //g' | cut -d"," -f1 | ||
|
|
||
| # Generate the file with the ARN entries | ||
| create-arn-file: validate-suffix-arn-file validate-release-notes-url | ||
| @./scripts/create-arn-table.sh | ||
|
|
||
| release-notes: validate-branch-name validate-suffix-arn-file | ||
| @gh release list | ||
| @gh \ | ||
| release \ | ||
| create $(BRANCH_NAME) \ | ||
| --title '$(BRANCH_NAME)' \ | ||
| --notes-file $(AWS_FOLDER)/$(SUFFIX_ARN_FILE) \ | ||
| $(AWS_FOLDER)/$(BRANCH_NAME).zip | ||
|
|
||
| validate-branch-name: | ||
| ifndef BRANCH_NAME | ||
| $(error BRANCH_NAME is undefined) | ||
| endif | ||
|
|
||
| validate-suffix-arn-file: | ||
| ifndef SUFFIX_ARN_FILE | ||
| $(error SUFFIX_ARN_FILE is undefined) | ||
| endif | ||
|
|
||
| validate-layer-name: | ||
| ifndef ELASTIC_LAYER_NAME | ||
| $(error ELASTIC_LAYER_NAME is undefined) | ||
| endif | ||
|
|
||
| validate-aws-default-region: | ||
| ifndef AWS_DEFAULT_REGION | ||
| $(error AWS_DEFAULT_REGION is undefined) | ||
| endif | ||
|
|
||
| validate-release-notes-url: | ||
| ifndef RELEASE_NOTES_URL | ||
| $(error RELEASE_NOTES_URL is undefined) | ||
| endif | ||
This file contains hidden or 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,31 @@ | ||
| #!/usr/bin/env bash | ||
| set -o pipefail | ||
|
|
||
| # | ||
| # Create the AWS ARN table given the below environment variables: | ||
| # | ||
| # - AWS_FOLDER - that's the location of the publish-layer-version output for each region. | ||
| # - SUFFIX_ARN_FILE - that's the output file to be stored in the AWS_FOLDER. | ||
| # - RELEASE_NOTES_URL - that's the URL for the changelog in the elastic.co | ||
| # | ||
|
|
||
| ARN_FILE=${SUFFIX_ARN_FILE} | ||
|
|
||
| { | ||
| echo "For more information, please see the [changelog](${RELEASE_NOTES_URL})." | ||
| echo '' | ||
| echo "### Elastic APM Node.js agent layer ARNs" | ||
| echo '' | ||
| echo '|Region|ARN|' | ||
| echo '|------|---|' | ||
| } > "${AWS_FOLDER}/${ARN_FILE}" | ||
|
|
||
|
|
||
| for f in "${AWS_FOLDER}"/*.publish; do | ||
| LAYER_VERSION_ARN=$(grep '"LayerVersionArn"' "${f}" | cut -d":" -f2- | sed 's/ //g' | sed 's/"//g' | cut -d"," -f1) | ||
| FILENAME=$(basename /"${f}" .publish) | ||
| echo "INFO: create-arn-table ARN(${LAYER_VERSION_ARN}):region(${FILENAME}))" | ||
| echo "|${FILENAME}|${LAYER_VERSION_ARN}|" >> "${AWS_FOLDER}/${ARN_FILE}" | ||
| done | ||
|
|
||
| echo '' >> "${AWS_FOLDER}/${ARN_FILE}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Produces