Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8812080
ci: add release stage when a tag is created
v1v Jan 13, 2022
fbbf425
ci: add release dist
v1v Jan 13, 2022
e27ca64
chore: testing purposes
v1v Jan 13, 2022
0c89783
ci: stash is not needed when running a matrix
v1v Jan 13, 2022
f5ed12e
ci: add release-notes
v1v Jan 13, 2022
8602116
chore: for testing purposes
v1v Jan 13, 2022
ffa2caa
ci: enable aws login
v1v Jan 13, 2022
7f3e9d0
ci: publish in all the AWS regions
v1v Jan 13, 2022
019d6f0
chore: for testing purposes
v1v Jan 13, 2022
4d39efe
ci: fix post location
v1v Jan 13, 2022
620d8b0
fix: You must specify a region.
v1v Jan 13, 2022
9ec1143
makefile: report pipe errors
v1v Jan 13, 2022
3b9c99c
Use generate-cli-skeleton for dry-run
v1v Jan 13, 2022
97e47db
ci: create ARN table for each arch
v1v Jan 13, 2022
b597115
ci: remove duplicated stash
v1v Jan 13, 2022
1a43178
Support upload assets
v1v Jan 13, 2022
ccc7585
enable release notes with a draft
v1v Jan 13, 2022
5bc534a
remove duplication
v1v Jan 13, 2022
4d37792
makefile: refactor validation in goals
v1v Jan 13, 2022
e5b400c
chore: for testing purposes let's use the forked repo
v1v Jan 13, 2022
254c939
docs: update the automated release process
v1v Jan 13, 2022
7931507
make: mv once only
v1v Jan 13, 2022
f8d1173
ci: GOARCH is not defined when publishing but needed
v1v Jan 13, 2022
d051cbb
ci: use the workspace after the build stage
v1v Jan 13, 2022
323d959
Revert "ci: GOARCH is not defined when publishing but needed"
v1v Jan 14, 2022
d993397
make: dist is the one in charge to prepare the arch binary
v1v Jan 14, 2022
cb676e7
debug: for testing purposes
v1v Jan 14, 2022
fd7f857
ci: create-are requires the goarch
v1v Jan 14, 2022
5e563f4
debug: for testing purposes
v1v Jan 14, 2022
5deb100
publish goal does not require branch validation
v1v Jan 26, 2022
19c9bc2
Add license and description fields
v1v Jan 26, 2022
900d51f
use the LayerVersionArn field
v1v Jan 26, 2022
a8a5441
Use a different arch
v1v Jan 26, 2022
669105b
unrequired validation
v1v Jan 26, 2022
b93bc14
use suffix since it's the correct value
v1v Jan 26, 2022
63a925e
enable when tag is created
v1v Jan 26, 2022
65a7124
dry-run disabled
v1v Jan 26, 2022
f197135
no more debugging
v1v Jan 26, 2022
f5d4448
aws: no all regions support the aws lambda publising
v1v Jan 26, 2022
05919ed
enable --compatible-architectures
v1v Jan 26, 2022
1b1d08e
keep compatibility with the apm-lambda-extension/cli/build-and-publis…
v1v Jan 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pipeline {
REPO = 'apm-aws-lambda'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
PIPELINE_LOG_LEVEL = 'INFO'
SUFFIX_ARN_FILE = 'arn-file.md'
ELASTIC_LAYER_NAME = 'apm-lambda-extension'
}
options {
timeout(time: 1, unit: 'HOURS')
Expand Down Expand Up @@ -77,8 +79,6 @@ pipeline {
stage('Test') {
steps {
withGithubNotify(context: "Test-${GO_VERSION}-${PLATFORM}") {
deleteDir()
unstash 'source'
withGoEnv(){
dir("${BASE_DIR}/apm-lambda-extension"){
goTestJUnit(options: '-v ./...', output: 'junit-report.xml')
Expand All @@ -95,6 +95,75 @@ pipeline {
}
}
}
stage('Release') {
options { skipDefaultCheckout() }
when {
tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: 'REGEXP'
}
stages {
stage('BuildPublish') {
failFast false
matrix {
agent {label "${PLATFORM}"}
options { skipDefaultCheckout() }
axes {
axis {
name 'PLATFORM'
values 'arm', 'ubuntu-18 && immutable'
}
}
stages {
stage('Dist') {
steps {
withGithubNotify(context: "Dist-${PLATFORM}") {
deleteDir()
unstash 'source'
withGoEnv(){
dir("${BASE_DIR}/apm-lambda-extension"){
cmd(label: 'make dist', script: 'make dist')
}
}
}
}
}
stage('Publish') {
steps {
withGithubNotify(context: "Publish-${PLATFORM}") {
withGoEnv(){
withAWSEnv(secret: 'secret/observability-team/ci/service-account/apm-aws-lambda', forceInstallation: true, version: '2.4.10') {
dir("${BASE_DIR}/apm-lambda-extension"){
cmd(label: 'make publish-in-all-aws-regions', script: 'make publish-in-all-aws-regions')
stash(includes: "*${SUFFIX_ARN_FILE}", name: "arn-${isArm() ? 'arm' : 'amd'}")
stash(includes: "bin/${BRANCH_NAME}-*.zip", name: "dist-${isArm() ? 'arm' : 'amd'}")
}
}
}
}
}
post {
always {
archiveArtifacts(allowEmptyArchive: true, artifacts: "${BASE_DIR}/apm-lambda-extension/.regions")
}
}
}
}
}
}
stage('Release Notes') {
steps {
withGhEnv(forceInstallation: true, version: '2.4.0') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--generate-notes is supported from 2.4.0 -> https://github.com/cli/cli/releases/tag/v2.4.0

dir("${BASE_DIR}/apm-lambda-extension"){
unstash "arn-arm"
unstash "arn-amd"
Comment on lines +156 to +157
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the trick to converge the outcome from the publishing stage for the two supported architectures (ARM and AMD64)

unstash "dist-arm"
unstash "dist-amd"
cmd(label: 'make release-notes', script: 'make release-notes')
}
}
}
}
}
}
}
post {
cleanup {
Expand Down
22 changes: 22 additions & 0 deletions .ci/create-arn-table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eo 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
# - ARCHITECTURE - that's the supported architecture.
# - SUFFIX_ARN_FILE - that's the output file.
#

{
echo "### ARCH: ${ARCHITECTURE}"
echo ''
echo '|Region|Arch|ARN|'
echo '|------|----|---|'
for f in $(ls "${AWS_FOLDER}"); do
# TODO: identify what field to be used.
echo "|${f}|${ARCHITECTURE}|$(cat $AWS_FOLDER/${f} | jq -r .LayerVersionArn)|"
done
echo ''
} > ${ARCHITECTURE}-${SUFFIX_ARN_FILE}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# AWS regions file
.regions
.aws/
23 changes: 16 additions & 7 deletions apm-lambda-extension/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@

## Releasing

Releasing a version of the Lambda Extension is currently a three step manual process.

1. Tag the Release
2. Create the Build Artifacts
3. Add a Release via the Github UI
### :robot: Automatically

### Tag the Release
Releasing a version of the Lambda Extension requires a tag release.

First, tag the release via your preferred tagging method. Tagging a release (v0.0.2) via the command line looks something like this.
Tag the release via your preferred tagging method. Tagging a release (v0.0.2) via the command line looks something like this.

% git clone [email protected]:elastic/apm-aws-lambda.git
# ...
Expand All @@ -21,7 +17,20 @@ First, tag the release via your preferred tagging method. Tagging a release (v0
To github.com:elastic/apm-aws-lambda.git
* [new tag] v0.0.2 -> v0.0.2

This will trigger a build in the CI that will create the Build Artifacts
and a Release in the Github UI.

### :thumbsdown: Manually

Releasing a version of the Lambda Extension is currently a three step manual process.

1. Tag the Release
2. Create the Build Artifacts
3. Add a Release via the Github UI

### Tag the Release

See the above section regarding tagging a release.
### Create the Build Artifacts

Next, create the build artifacts for the release. These are go binaries of the Lambda Extension, built for both Intel and ARM architectures.
Expand Down
96 changes: 84 additions & 12 deletions apm-lambda-extension/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,103 @@
build:
SHELL = /bin/bash -eo pipefail

AWS_FOLDER = .aws

ifndef GOARCH
GOARCH=amd64
endif

# Transform GOARCH into the architecture of the extension layer
ifeq ($(GOARCH),amd64)
ARCHITECTURE=x86_64
else
ARCHITECTURE=arm64
endif

export AWS_FOLDER GOARCH ARCHITECTURE

build:
GOOS=linux go build -o bin/extensions/apm-lambda-extension main.go
chmod +x bin/extensions/apm-lambda-extension
build-and-publish:
ifndef AWS_DEFAULT_REGION
$(error AWS_DEFAULT_REGION is undefined)
endif
build-and-publish: validate-layer-name validate-aws-default-region
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate-* are the goals to avoid duplication of missing arguments/env-variables in some other Make goals

ifndef AWS_ACCESS_KEY_ID
$(error AWS_ACCESS_KEY_ID is undefined)
endif
ifndef AWS_SECRET_ACCESS_KEY
$(error AWS_SECRET_ACCESS_KEY is undefined)
endif
ifndef ELASTIC_LAYER_NAME
$(error ELASTIC_LAYER_NAME is undefined)
endif
GOARCH=${GOARCH} make build
GOARCH=${GOARCH} make zip
aws lambda publish-layer-version --layer-name "${ELASTIC_LAYER_NAME}" --zip-file "fileb://./bin/extension.zip"
$(MAKE) publish
zip:
cd bin && rm -f extension.zip || true && zip -r extension.zip extensions && cp extension.zip ${GOARCH}.zip
test:
go test extension/*.go -v
env:
ifndef GOARCH
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already defined above

export GOARCH=amd64
endif
env
dist: validate-branch-name build test zip
@cp ./bin/$(GOARCH).zip bin/$(BRANCH_NAME)-linux-$(GOARCH).zip

# List all the AWS regions
get-all-aws-regions:
@aws \
ec2 \
describe-regions \
--region us-east-1 \
--output json \
--no-cli-pager \
| jq -r '.Regions[].RegionName' > .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)
@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}; \
done <.regions
$(MAKE) create-arn-file

# Publish the given LAYER in the given AWS region
publish: validate-layer-name validate-aws-default-region
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goal is uses in two different places:

  • The traditional one when using ./elastic-lambda.js install
  • The one to rollout the ARN in all the AWS regions, see publish-in-all-aws-regions

I decided to refactor build-and-publish in favour of avoiding running aws lambda command in two different Make goals.

@aws lambda \
--output json \
publish-layer-version \
--layer-name "${ELASTIC_LAYER_NAME}" \
--description "AWS Lambda Extension Layer for Elastic APM" \
--license "Apache-2.0" \
--compatible-architectures "$(ARCHITECTURE)" \
--zip-file "fileb://./bin/extension.zip"

# Generate the file with the ARN entries
create-arn-file: validate-suffix-arn-file
@../.ci/create-arn-table.sh

release-notes: validate-branch-name validate-suffix-arn-file
@gh release list
cat *-$(SUFFIX_ARN_FILE) > $(SUFFIX_ARN_FILE)
@gh \
release \
create $(BRANCH_NAME) \
--title '$(BRANCH_NAME)' \
--generate-notes \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically generate title and notes for the release, it works in conjunction with --notes-file

--notes-file $(SUFFIX_ARN_FILE) \
./bin/$(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