Skip to content

Commit

Permalink
Adjust scripts for release
Browse files Browse the repository at this point in the history
  • Loading branch information
reakaleek committed Jan 24, 2023
1 parent ae175a7 commit fc84cb2
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 5 deletions.
59 changes: 59 additions & 0 deletions .ci/publish-aws.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail

export AWS_FOLDER=${AWS_FOLDER:-.aws}
export SUFFIX_ARN_FILE=${SUFFIX_ARN_FILE:-arn-file.md}

GOOS=${GOOS:?Pleas provide GOOS environment variable.}
GOARCH=${GOARCH:?Please provide GOARCH environment variable.}
ELASTIC_LAYER_NAME=${ELASTIC_LAYER_NAME:?Please provide ELASTIC_LAYER_NAME environment variable.}
ARCHITECTURE=${ARCHITECTURE:?Please provide ARCHITECTURE environment variable.}
VERSION=${VERSION:?Please provide VERSION environment variable. e.g. current git tag}

FULL_LAYER_NAME="${ELASTIC_LAYER_NAME}-${ARCHITECTURE}"

ALL_AWS_REGIONS=$(aws ec2 describe-regions --output json --no-cli-pager | jq -r '.Regions[].RegionName')

rm -rf ${AWS_FOLDER}

# Delete previous layers
for region in $ALL_AWS_REGIONS; do
layer_versions=$(aws lambda list-layer-versions --region="${region}" --layer-name="${FULL_LAYER_NAME}" | jq '.LayerVersions[].Version')
echo "Found layer versions for ${FULL_LAYER_NAME} in ${region}: ${layer_versions:-none}"
for version_number in $layer_versions; do
echo "- Deleting ${FULL_LAYER_NAME}:${version_number} in ${region}"
aws lambda delete-layer-version \
--region="${region}" \
--layer-name="${FULL_LAYER_NAME}" \
--version-number="${version_number}"
done
done

mkdir -p "${AWS_FOLDER}"

for region in $ALL_AWS_REGIONS; do
echo "Publish ${FULL_LAYER_NAME} in ${region}"
publish_output=$(aws lambda \
--output json \
publish-layer-version \
--region="${region}" \
--layer-name="${FULL_LAYER_NAME}" \
--description="AWS Lambda Extension Layer for Elastic APM ${ARCHITECTURE}" \
--license="Apache-2.0" \
--zip-file="fileb://./dist/${VERSION}-${GOOS}-${GOARCH}.zip")
echo "${publish_output}" > "${AWS_FOLDER}/${region}"
layer_version=$(echo "${publish_output}" | jq '.Version')
echo "Grant public layer access ${FULL_LAYER_NAME}:${layer_version} in ${region}"
grant_access_output=$(aws lambda \
--output json \
add-layer-version-permission \
--region="${region}" \
--layer-name="${FULL_LAYER_NAME}" \
--action="lambda:GetLayerVersion" \
--principal='*' \
--statement-id="${FULL_LAYER_NAME}" \
--version-number="${layer_version}")
echo "${grant_access_output}" > "${AWS_FOLDER}/.${region}-public"
done

sh -c "./.ci/create-arn-table.sh"
18 changes: 18 additions & 0 deletions .ci/release-github.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail

export SUFFIX_ARN_FILE=${SUFFIX_ARN_FILE:-arn-file.md}
VERSION=${VERSION:?Please provide VERSION environment variable. e.g. current git tag}

rm -rf "${SUFFIX_ARN_FILE}"

cat ./*"-${SUFFIX_ARN_FILE}" >> "$SUFFIX_ARN_FILE"

gh release \
create "${VERSION}" \
--draft \
--title="${VERSION}" \
--generate-notes \
--notes-file="${SUFFIX_ARN_FILE}" \
./dist/${VERSION}*.zip

60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: release

on:
push:
tags:
- v*.*.*

env:
DOCKER_BUILDKIT: 1
DOCKER_REGISTRY: docker.elastic.co
DOCKER_IMAGE_NAME: observability/apm-lambda-extension

permissions:
contents: write
pull-requests: read

jobs:
build:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.artifacts.outputs.os }}
arch: ${{ steps.artifacts.outputs.arch }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- uses: docker/setup-qemu-action@v2
with:
platforms: linux/arm64, linux/amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: elastic/apm-pipeline-library/.github/actions/docker-login@current
with:
registry: docker.elastic.co
secret: secret/observability-team/ci/docker-registry/prod
url: ${{ secrets.VAULT_ADDR }}
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
- uses: hashicorp/vault-action@v2
with:
url: ${{ secrets.VAULT_ADDR }}
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: |
secret/observability-team/ci/service-account/apm-aws-lambda access_key_id | AWS_ACCESS_KEY_ID ;
secret/observability-team/ci/service-account/apm-aws-lambda secret_access_key | AWS_SECRET_ACCESS_KEY
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
args: release --rm-dist
- name: GitHub Release
run: make release-notes
env:
VERSION: ${{ github.ref_name }}


6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

# AWS regions file
.regions
.aws/
.aws-*/
*arn-file.md

bin/

# local docs
html_docs
html_docs
dist/
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
# https://github.com/docker-library/repo-info/tree/master/repos/alpine/remote
FROM alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad
ARG EXTENSION_FILE
COPY ${EXTENSION_FILE} /opt/elastic-apm-extension
COPY /NOTICE.txt /opt/NOTICE.txt
COPY /dependencies.asciidoc /opt/dependencies.asciidoc
COPY ${EXTENSION_FILE} NOTICE.txt dependencies.asciidoc /opt/
2 changes: 2 additions & 0 deletions apmproxy/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ func Test_handleInfoRequest(t *testing.T) {
req.Header.Add(name, value)
}

time.Sleep(5 * time.Second)

// Send the request to the extension
client := &http.Client{}
resp, err := client.Do(req)
Expand Down

0 comments on commit fc84cb2

Please sign in to comment.