Skip to content

Commit e09b6a8

Browse files
authored
ci: support arn automation within release pipeline (#2453)
1 parent 3bec890 commit e09b6a8

File tree

4 files changed

+166
-1
lines changed

4 files changed

+166
-1
lines changed

.ci/Makefile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
SHELL = /bin/bash -eo pipefail
2+
3+
AWS_FOLDER = .aws
4+
AWS_LAMBDA_ZIP_LOCATION = elastic-apm-agent/target
5+
6+
export AWS_FOLDER
7+
8+
dist:
9+
@cp ../$(AWS_LAMBDA_ZIP_LOCATION)/elastic-apm-java-aws-lambda-layer-*.zip ../$(AWS_LAMBDA_ZIP_LOCATION)/$(ELASTIC_LAYER_NAME).zip
10+
11+
# List all the AWS regions
12+
get-all-aws-regions:
13+
@aws \
14+
ec2 \
15+
describe-regions \
16+
--region us-east-1 \
17+
--output json \
18+
--no-cli-pager \
19+
| jq -r '.Regions[].RegionName' > .regions
20+
21+
# Publish the given LAYER in all the AWS regions
22+
publish-in-all-aws-regions: validate-layer-name get-all-aws-regions dist
23+
@mkdir -p $(AWS_FOLDER)
24+
@while read AWS_DEFAULT_REGION; do \
25+
echo "publish '$(ELASTIC_LAYER_NAME)' in $${AWS_DEFAULT_REGION}"; \
26+
AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) publish > $(AWS_FOLDER)/$${AWS_DEFAULT_REGION}; \
27+
AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) grant-public-layer-access; \
28+
done <.regions
29+
30+
# Publish the given LAYER in the given AWS region
31+
publish: validate-layer-name validate-aws-default-region
32+
@aws lambda \
33+
--output json \
34+
publish-layer-version \
35+
--layer-name "$(ELASTIC_LAYER_NAME)" \
36+
--description "AWS Lambda Extension Layer for the Elastic APM Java Agent" \
37+
--compatible-runtimes java8.al2 java11 \
38+
--license "Apache-2.0" \
39+
--zip-file "fileb://../$(AWS_LAMBDA_ZIP_LOCATION)/$(ELASTIC_LAYER_NAME).zip"
40+
41+
# Grant public access to the given LAYER in the given AWS region
42+
grant-public-layer-access: validate-layer-name validate-aws-default-region
43+
@echo "[debug] $(ELASTIC_LAYER_NAME) with version: $$($(MAKE) -s --no-print-directory get-version)"
44+
@aws lambda \
45+
--output json \
46+
add-layer-version-permission \
47+
--layer-name "$(ELASTIC_LAYER_NAME)" \
48+
--action lambda:GetLayerVersion \
49+
--principal '*' \
50+
--statement-id "$(ELASTIC_LAYER_NAME)" \
51+
--version-number $$($(MAKE) -s --no-print-directory get-version) > $(AWS_FOLDER)/.$(AWS_DEFAULT_REGION)-public
52+
53+
# Generate the file with the ARN entries
54+
create-arn-file: validate-suffix-arn-file
55+
@./create-arn-table.sh
56+
57+
upload-lambda-asset: validate-release-version validate-layer-name
58+
@gh release list
59+
@gh \
60+
release \
61+
upload $(RELEASE_VERSION) \
62+
./$(AWS_LAMBDA_ZIP_LOCATION)/$(ELASTIC_LAYER_NAME).zip
63+
64+
# Get the ARN Version for the AWS_REGIONS
65+
# NOTE: jq -r .Version "$(AWS_FOLDER)/$(AWS_DEFAULT_REGION)" fails in the CI
66+
# with 'parse error: Invalid numeric literal at line 1, column 5'
67+
get-version: validate-aws-default-region
68+
@grep '"Version"' "$(AWS_FOLDER)/$(AWS_DEFAULT_REGION)" | cut -d":" -f2 | sed 's/ //g' | cut -d"," -f1
69+
70+
validate-release-version:
71+
ifndef RELEASE_VERSION
72+
$(error RELEASE_VERSION is undefined)
73+
endif
74+
75+
validate-suffix-arn-file:
76+
ifndef SUFFIX_ARN_FILE
77+
$(error SUFFIX_ARN_FILE is undefined)
78+
endif
79+
80+
validate-layer-name:
81+
ifndef ELASTIC_LAYER_NAME
82+
$(error ELASTIC_LAYER_NAME is undefined)
83+
endif
84+
85+
validate-aws-default-region:
86+
ifndef AWS_DEFAULT_REGION
87+
$(error AWS_DEFAULT_REGION is undefined)
88+
endif

.ci/create-arn-table.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -o pipefail
3+
4+
#
5+
# Create the AWS ARN table given the below environment variables:
6+
#
7+
# - AWS_FOLDER - that's the location of the publish-layer-version output for each region
8+
# - SUFFIX_ARN_FILE - that's the output file.
9+
#
10+
11+
ARN_FILE=${SUFFIX_ARN_FILE}
12+
13+
{
14+
echo "### ARNs of the APM Java Agent's AWS Lambda Layer"
15+
echo ''
16+
echo '|Region|ARN|'
17+
echo '|------|---|'
18+
} > "${ARN_FILE}"
19+
20+
for f in $(ls "${AWS_FOLDER}"); do
21+
LAYER_VERSION_ARN=$(grep '"LayerVersionArn"' "$AWS_FOLDER/${f}" | cut -d":" -f2- | sed 's/ //g' | sed 's/"//g' | cut -d"," -f1)
22+
echo "INFO: create-arn-table ARN(${LAYER_VERSION_ARN}):region(${f}))"
23+
echo "|${f}|${LAYER_VERSION_ARN}|" >> "${ARN_FILE}"
24+
done
25+
26+
echo '' >> "${ARN_FILE}"

.ci/release/Jenkinsfile

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pipeline {
1616
SLACK_CHANNEL = '#apm-agent-java'
1717
NOTIFY_TO = '[email protected]'
1818
BRANCH_SPECIFIER = "${params.branch_specifier}"
19+
SUFFIX_ARN_FILE = 'arn-file.md'
20+
//RELEASE_AWS_LAMBDA_VERSION = '-ver-1-29-0'
21+
//RELEASE_VERSION = '1.29.0'
1922
}
2023
options {
2124
timeout(time: 3, unit: 'HOURS')
@@ -27,6 +30,7 @@ pipeline {
2730
parameters {
2831
string(name: 'branch_specifier', defaultValue: 'stable', description: "What branch to release from?")
2932
booleanParam(name: 'check_branch_ci_status', defaultValue: true, description: "Check for failing tests in the given branch (if no stable branch)?")
33+
booleanParam(name: 'publish_aws_lambda', defaultValue: true, description: "Whether to upload the AWS lambda")
3034
}
3135
stages {
3236
stage('Initializing'){
@@ -131,6 +135,7 @@ pipeline {
131135
env.RELEASE_TAG = "v" + user_release_version
132136
env.RELEASE_VERSION = user_release_version
133137
env.BRANCH_DOT_X = user_release_version.substring(0, user_release_version.indexOf('.'))+'.x'
138+
env.RELEASE_AWS_LAMBDA_VERSION = '-ver-' + user_release_version.replaceAll('\\.', '-')
134139
}
135140
}
136141
}
@@ -164,10 +169,43 @@ pipeline {
164169
}
165170
}
166171
}
172+
stage('Publish AWS Lambda') {
173+
when {
174+
//expression { params.publish_aws_lambda }
175+
expression { return false }
176+
}
177+
environment {
178+
SOURCE_AWS_FILE = "elastic-apm-java-aws-lambda-layer-${RELEASE_VERSION}.zip"
179+
}
180+
steps {
181+
setEnvVar('ELASTIC_LAYER_NAME', "elastic-apm-java${env.RELEASE_AWS_LAMBDA_VERSION}")
182+
withAWSEnv(secret: 'secret/observability-team/ci/service-account/apm-aws-lambda', role_id: 'apm-vault-role-id', secret_id: 'apm-vault-secret-id',
183+
forceInstallation: true, version: '2.4.10') {
184+
dir("${BASE_DIR}"){
185+
dir ('elastic-apm-agent/target') {
186+
// TODO: copy file from a google bucket
187+
sh(label: 'fetch AWS lambda file', script: "wget https://github.com/elastic/apm-agent-java/releases/download/v${RELEASE_VERSION}/${SOURCE_AWS_FILE} -O ${SOURCE_AWS_FILE}")
188+
}
189+
sh(label: 'make publish-in-all-aws-regions', script: 'make -C .ci publish-in-all-aws-regions')
190+
sh(label: 'make create-arn-file', script: 'make -C .ci create-arn-file')
191+
}
192+
}
193+
}
194+
post {
195+
always {
196+
archiveArtifacts(allowEmptyArchive: true, artifacts: "${BASE_DIR}/.ci/${SUFFIX_ARN_FILE}")
197+
}
198+
}
199+
}
167200
stage('Create GitHub release draft') {
201+
when {
202+
expression { return false }
203+
}
168204
steps {
169205
dir("${BASE_DIR}"){
170206
script {
207+
def arnFile = ".ci/${SUFFIX_ARN_FILE}"
208+
setEnvVar('ARN_CONTENT', fileExists(arnFile) ? readFile(arnFile) : '')
171209
// Construct the URL with anchor for the release notes
172210
// Ex: https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-1.x.html#release-notes-1.13.0
173211
def finalUrl = "https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-${BRANCH_DOT_X}.html#release-notes-${RELEASE_VERSION}"
@@ -176,14 +214,17 @@ pipeline {
176214
draft: true,
177215
tagName: "${RELEASE_TAG}",
178216
releaseName: "Release ${RELEASE_VERSION}",
179-
body: "[Release Notes for ${RELEASE_VERSION}](${finalUrl})")
217+
body: "[Release Notes for ${RELEASE_VERSION}](${finalUrl}) \n ${ARN_CONTENT}")
180218
env.RELEASE_ID = ret['id']
181219
env.RELEASE_NOTES_URL = finalUrl
182220
}
183221
}
184222
}
185223
}
186224
stage('Wait for artifact to be available in Maven Central') {
225+
when {
226+
expression { return false }
227+
}
187228
steps {
188229
dir("${BASE_DIR}"){
189230
script {
@@ -199,6 +240,9 @@ pipeline {
199240
}
200241
}
201242
stage('Update Cloudfoundry') {
243+
when {
244+
expression { return false }
245+
}
202246
steps {
203247
dir("${BASE_DIR}"){
204248
sh(script: ".ci/release/update_cloudfoundry.sh ${RELEASE_VERSION}")
@@ -207,6 +251,9 @@ pipeline {
207251
}
208252
}
209253
stage('Publish release on GitHub') {
254+
when {
255+
expression { return false }
256+
}
210257
steps {
211258
dir("${BASE_DIR}"){
212259
waitUntil(initialRecurrencePeriod: 60000) {
@@ -222,6 +269,9 @@ pipeline {
222269
}
223270
}
224271
stage('Build and push Docker images') {
272+
when {
273+
expression { return false }
274+
}
225275
steps {
226276
dir("${BASE_DIR}"){
227277
// fetch agent artifact from remote repository

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ docs/html/
1313
**/__pycache__/
1414
.m2/
1515
fetch.log
16+
.ci/.aws

0 commit comments

Comments
 (0)