From 205edaf0ab50dce92c3d86aced8071d97bea0d71 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:31:45 +0100 Subject: [PATCH 01/51] Create goreleaser config --- .goreleaser.yaml | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .goreleaser.yaml diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..28bb5c32 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,81 @@ +project_name: apm-lambda-extension + +before: + hooks: + # test + - 'sh -c "go test extension/*.go -v"' + # check-licenses + - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing . + - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .java . + - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . + # NOTICE.txt + - ./scripts/notice.sh + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + flags: + - -trimpath + ldflags: + - -s -w + binary: "extensions/{{ .ProjectName }}" + +archives: + - id: zip + format: zip + name_template: |- + {{ .Tag }}-{{ .Os }}-{{ .Arch }} + files: + - NOTICE.txt + - dependencies.asciidoc + rlcp: true # https://goreleaser.com/deprecations/#archivesrlcp + +dockers: + + - &default-docker-image + id: linux-amd64-image + use: buildx + goos: linux + goarch: amd64 + image_templates: + - 'docker.elastic.co/observability/{{ .ProjectName }}-x86_64:{{ trimprefix .Tag "v" }}' + - "docker.elastic.co/observability/{{ .ProjectName }}-x86_64:latest" + build_flag_templates: + - "--platform=linux/amd64" + - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" + extra_files: + - NOTICE.txt + - dependencies.asciidoc + + - <<: *default-docker-image + id: linux-arm64-image + goarch: arm64 + image_templates: + - 'docker.elastic.co/observability/{{ .ProjectName }}-arm64:{{ trimprefix .Tag "v" }}' + - "docker.elastic.co/observability/{{ .ProjectName }}-arm64:latest" + build_flag_templates: + - "--platform=linux/arm64" + - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" + +publishers: + - name: publish-aws + cmd: ./.ci/publish-aws.sh + env: + - AWS_ACCESS_KEY_ID={{ .Env.AWS_ACCESS_KEY_ID }} + - AWS_SECRET_ACCESS_KEY={{ .Env.AWS_SECRET_ACCESS_KEY }} + - AWS_SECURITY_TOKEN={{ .Env.AWS_SECURITY_TOKEN }} + - AWS_SESSION_TOKEN={{ .Env.AWS_SESSION_TOKEN }} + - ELASTIC_LAYER_NAME=elastic-apm-extension-ver-{{ replace (trimprefix .Tag "v") "." "-" }} + - VERSION={{ .Tag }} + - ARCHITECTURE={{ if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }} + - GOOS={{ .Os }} + - GOARCH={{ .Arch }} + - AWS_FOLDER=.aws-{{ .Os }}-{{ .Arch }} +release: + # Custom GitHub release + disable: true From 496d7bca1fc66a0940a7acdec3272bd231d9dc32 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:37:17 +0100 Subject: [PATCH 02/51] Add test workflow --- .github/workflows/test-reporter.yml | 20 ++++++++++ .github/workflows/test.yml | 61 +++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/test-reporter.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test-reporter.yml b/.github/workflows/test-reporter.yml new file mode 100644 index 00000000..33e13517 --- /dev/null +++ b/.github/workflows/test-reporter.yml @@ -0,0 +1,20 @@ +--- +## Workflow to process the JUnit test results and add a report to the checks. +name: test-reporter +on: + workflow_run: + workflows: + - test + types: + - completed + +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: elastic/apm-pipeline-library/.github/actions/test-report@current + with: + artifact: test-results # artifact name + name: JUnit Tests # Name of the check run which will be created + path: "*-junit-report.xml" # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..4365af82 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,61 @@ +name: test + +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +jobs: + test: + strategy: + fail-fast: false + matrix: + platform: + - "ubuntu-latest" + - "macos-latest" + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - name: Build + run: make build + - name: Test + run: | + go install gotest.tools/gotestsum@latest + gotestsum --format testname --junitfile ${{ matrix.platform }}-junit-report.xml + - uses: actions/upload-artifact@v3 + if: success() || failure() + with: + name: test-results + path: '*-junit-report.xml' + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - name: lint-prep + run: go mod tidy && git diff --exit-code + - name: lint-run + run: make lint + - name: Go vet + run: go vet + notice: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: notice + run: | + make NOTICE.txt + git diff --exit-code --quiet && exit 0 || echo "regenerate NOTICE.txt" && exit 1 + + + From ae175a7ff883d10757977b32c678367f562f7182 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:37:49 +0100 Subject: [PATCH 03/51] Adjust scripts --- Makefile | 226 +++------------------------------------------- scripts/notice.sh | 0 2 files changed, 13 insertions(+), 213 deletions(-) mode change 100644 => 100755 scripts/notice.sh diff --git a/Makefile b/Makefile index 5cf4d7bc..6fc5c1c3 100644 --- a/Makefile +++ b/Makefile @@ -1,223 +1,23 @@ SHELL = /bin/bash -eo pipefail - -AWS_FOLDER = .aws DOCKER_IMAGE_NAME = observability/apm-lambda-extension DOCKER_REGISTRY = docker.elastic.co -AGENT_VERSION = $(shell echo $${BRANCH_NAME} | cut -f 2 -d 'v') - -# Add support for SOURCE_DATE_EPOCH and reproducble buils -# See https://reproducible-builds.org/specs/source-date-epoch/ -SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) -DATE_FMT = +%Y%m%d%H%M.%S -# Fallback mechanism to support other systems: -# 1. 'date -d': Busybox and GNU coreutils. -# 2. 'date -r': BSD date. It does not support '-d'. -BUILD_DATE = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}") - -GO_BUILDFLAGS ?= -trimpath -ldflags="-s -w" -ifndef GOARCH - GOARCH=amd64 -endif +clean: + @rm -rf dist/ + @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs docker rmi --force -# Transform GOARCH into the architecture of the extension layer -ifeq ($(GOARCH),amd64) - ARCHITECTURE=x86_64 -else - ARCHITECTURE=arm64 -endif +dist: + @goreleaser release --snapshot --rm-dist -export AWS_FOLDER GOARCH ARCHITECTURE DOCKER_IMAGE_NAME DOCKER_REGISTRY +release: + @goreleaser release --rm-dist -.PHONY: all -all: build - -NOTICE.txt: go.mod - @bash ./scripts/notice.sh - -check-licenses: - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing . - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .java . - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . - -update-licenses: - go run github.com/elastic/go-licenser@v0.4.0 -exclude tf -exclude testing . - go run github.com/elastic/go-licenser@v0.4.0 -exclude tf -exclude testing -ext .java . - go run github.com/elastic/go-licenser@v0.4.0 -exclude tf -exclude testing -ext .js . +release-notes: + @./.ci/release-github.sh lint: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 run - -build: check-licenses NOTICE.txt - CGO_ENABLED=0 GOOS=linux go build ${GO_BUILDFLAGS} -o bin/extensions/apm-lambda-extension main.go - cp NOTICE.txt bin/NOTICE.txt - cp dependencies.asciidoc bin/dependencies.asciidoc - -build-and-publish: check-licenses validate-layer-name validate-aws-default-region -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 - GOARCH=${GOARCH} make build - GOARCH=${GOARCH} make zip - $(MAKE) publish - -zip: build - cd bin \ - && rm -f extension.zip \ - && find extensions NOTICE.txt dependencies.asciidoc | xargs touch -t ${BUILD_DATE} \ - && zip -X -r extension.zip extensions NOTICE.txt dependencies.asciidoc \ - && cp extension.zip ${GOARCH}.zip - -test: - go test extension/*.go -v - -env: - env - -dist: validate-branch-name test zip - @cp ./bin/$(GOARCH).zip bin/$(BRANCH_NAME)-linux-$(GOARCH).zip - -build-docker: validate-version - docker build -t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)-$(ARCHITECTURE):$(AGENT_VERSION) \ - --build-arg EXTENSION_FILE=bin/extensions/apm-lambda-extension . - -push-docker: build-docker - @./.ci/push_docker.sh $(DOCKER_REGISTRY) "$(DOCKER_IMAGE_NAME)-$(ARCHITECTURE)" $(AGENT_VERSION) - -# 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)-$(ARCHITECTURE)' in $${AWS_DEFAULT_REGION}"; \ - AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) publish > $(AWS_FOLDER)/$${AWS_DEFAULT_REGION}; \ - AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) grant-public-layer-access; \ - done <.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)-$(ARCHITECTURE)" \ - --description "AWS Lambda Extension Layer for Elastic APM $(ARCHITECTURE)" \ - --license "Apache-2.0" \ - --zip-file "fileb://./bin/extension.zip" + @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version + @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 run -# Delete the given LAYER in all the AWS regions -delete-in-all-aws-regions: validate-layer-name get-all-aws-regions - @mkdir -p $(AWS_FOLDER) - @while read AWS_DEFAULT_REGION; do \ - echo "delete '$(ELASTIC_LAYER_NAME)-$(ARCHITECTURE)' in $${AWS_DEFAULT_REGION}"; \ - AWS_DEFAULT_REGION="$${AWS_DEFAULT_REGION}" ELASTIC_LAYER_NAME=$(ELASTIC_LAYER_NAME) $(MAKE) delete; \ - done <.regions - -# Delete the given LAYER in the given AWS region, it won't fail -delete: validate-layer-name validate-aws-default-region - @aws lambda \ - delete-layer-version \ - --layer-name "$(ELASTIC_LAYER_NAME)-$(ARCHITECTURE)" \ - --version-number 1 || echo "delete-layer-version $(ELASTIC_LAYER_NAME)-$(ARCHITECTURE) for $${AWS_DEFAULT_REGION} could not be found" - -# 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)-$(ARCHITECTURE) with version: $$($(MAKE) -s --no-print-directory get-version)" - @aws lambda \ - --output json \ - add-layer-version-permission \ - --layer-name "$(ELASTIC_LAYER_NAME)-$(ARCHITECTURE)" \ - --action lambda:GetLayerVersion \ - --principal '*' \ - --statement-id "$(ELASTIC_LAYER_NAME)-$(ARCHITECTURE)" \ - --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)" | cut -d":" -f2 | sed 's/ //g' | cut -d"," -f1 - -# 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 \ - --notes-file $(SUFFIX_ARN_FILE) \ - ./bin/$(BRANCH_NAME)*.zip - -validate-version: -ifndef AGENT_VERSION - $(error AGENT_VERSION is undefined) -endif - -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 - -############################################################################## -# Smoke tests -- Basic smoke tests for the APM Lambda extension -############################################################################## - -SMOKETEST_VERSIONS ?= latest -SMOKETEST_DIRS = $$(find ./tf -mindepth 0 -maxdepth 0 -type d) - -.PHONY: smoketest/discover -smoketest/discover: - @echo "$(SMOKETEST_DIRS)" - -.PHONY: smoketest/run -smoketest/run: build - @ for version in $(shell echo $(SMOKETEST_VERSIONS) | tr ',' ' '); do \ - echo "-> Running $(TEST_DIR) smoke tests for version $${version}..."; \ - cd $(TEST_DIR) && ./test.sh $${version}; \ - done - -.PHONY: smoketest/cleanup -smoketest/cleanup: - @ cd $(TEST_DIR); \ - if [ -f "./cleanup.sh" ]; then \ - ./cleanup.sh; \ - fi - -.PHONY: smoketest/all -smoketest/all/cleanup: - @ for test_dir in $(SMOKETEST_DIRS); do \ - echo "-> Cleanup $${test_dir} smoke tests..."; \ - $(MAKE) smoketest/cleanup TEST_DIR=$${test_dir}; \ - done +NOTICE.txt: + @bash ./scripts/notice.sh diff --git a/scripts/notice.sh b/scripts/notice.sh old mode 100644 new mode 100755 From fc84cb20198142d83473af897f1426140f01fa8c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:38:17 +0100 Subject: [PATCH 04/51] Adjust scripts for release --- .ci/publish-aws.sh | 59 ++++++++++++++++++++++++++++++++++ .ci/release-github.sh | 18 +++++++++++ .github/workflows/release.yml | 60 +++++++++++++++++++++++++++++++++++ .gitignore | 6 ++-- Dockerfile | 4 +-- apmproxy/receiver_test.go | 2 ++ 6 files changed, 144 insertions(+), 5 deletions(-) create mode 100755 .ci/publish-aws.sh create mode 100755 .ci/release-github.sh create mode 100644 .github/workflows/release.yml diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh new file mode 100755 index 00000000..ed70c443 --- /dev/null +++ b/.ci/publish-aws.sh @@ -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" diff --git a/.ci/release-github.sh b/.ci/release-github.sh new file mode 100755 index 00000000..4da96003 --- /dev/null +++ b/.ci/release-github.sh @@ -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 + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..534d04b3 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} + + diff --git a/.gitignore b/.gitignore index c0f0ed29..2989719b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,9 +22,11 @@ # AWS regions file .regions -.aws/ +.aws-*/ +*arn-file.md bin/ # local docs -html_docs \ No newline at end of file +html_docs +dist/ diff --git a/Dockerfile b/Dockerfile index 3963dfbb..0258237f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/apmproxy/receiver_test.go b/apmproxy/receiver_test.go index f8828725..9cdc5567 100644 --- a/apmproxy/receiver_test.go +++ b/apmproxy/receiver_test.go @@ -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) From c875cba48f36a982d0587dcbd697499c883e03a7 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:42:05 +0100 Subject: [PATCH 05/51] Remove draft flag --- .ci/release-github.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/release-github.sh b/.ci/release-github.sh index 4da96003..4df7190b 100755 --- a/.ci/release-github.sh +++ b/.ci/release-github.sh @@ -10,7 +10,6 @@ cat ./*"-${SUFFIX_ARN_FILE}" >> "$SUFFIX_ARN_FILE" gh release \ create "${VERSION}" \ - --draft \ --title="${VERSION}" \ --generate-notes \ --notes-file="${SUFFIX_ARN_FILE}" \ From 483096f2de926f75ba2bfd48ee20df1bc9f147d3 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:42:34 +0100 Subject: [PATCH 06/51] Fix NOTICE.txt rule --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6fc5c1c3..e2bc9a14 100644 --- a/Makefile +++ b/Makefile @@ -19,5 +19,5 @@ lint: @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 run -NOTICE.txt: +NOTICE.txt: go.mod @bash ./scripts/notice.sh From 503d36d7cc4a8f2f8b16addd29f18f97e8eab4e1 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:43:42 +0100 Subject: [PATCH 07/51] Remove deprecated files --- .ci/Jenkinsfile | 248 -------------------------------- .ci/jobs/apm-aws-lambda-mbp.yml | 45 ------ .ci/push_docker.sh | 47 ------ 3 files changed, 340 deletions(-) delete mode 100644 .ci/Jenkinsfile delete mode 100644 .ci/jobs/apm-aws-lambda-mbp.yml delete mode 100755 .ci/push_docker.sh diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile deleted file mode 100644 index 0af60ca4..00000000 --- a/.ci/Jenkinsfile +++ /dev/null @@ -1,248 +0,0 @@ -#!/usr/bin/env groovy - -@Library('apm@current') _ - -pipeline { - agent { label 'ubuntu-18 && immutable' } - environment { - REPO = 'apm-aws-lambda' - GO_VERSION = '1.19' - BASE_DIR = "src/github.com/elastic/${env.REPO}" - PIPELINE_LOG_LEVEL = 'INFO' - SUFFIX_ARN_FILE = 'arn-file.md' - RELEASE_URL_MESSAGE = "()" - SLACK_CHANNEL = '#apm-serverless' - NOTIFY_TO = 'build-apm+apm-serverless@elastic.co' - DOCKER_REGISTRY = 'docker.elastic.co' - DOCKER_SECRET = 'secret/apm-team/ci/docker-registry/prod' - } - options { - timeout(time: 1, unit: 'HOURS') - buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30')) - timestamps() - ansiColor('xterm') - disableResume() - durabilityHint('PERFORMANCE_OPTIMIZED') - rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) - quietPeriod(10) - } - triggers { - issueCommentTrigger("${obltGitHubComments()}") - } - stages { - stage('Checkout') { - steps { - whenTrue(isTag()) { - notifyStatus(slackStatus: 'good', subject: "[${env.REPO}] Release tag *${env.TAG_NAME}* has been created", body: "Build: (<${env.RUN_DISPLAY_URL}|here>) for further details.") - } - deleteDir() - gitCheckout(basedir: "${BASE_DIR}") - stash allowEmpty: true, name: 'source', useDefaultExcludes: false - setEnvVar('ELASTIC_LAYER_NAME', "elastic-apm-extension${getVersion()}") - } - } - stage('Lint'){ - steps { - withGithubNotify(context: "Lint") { - withGoEnv(){ - dir("${BASE_DIR}"){ - sh(label: 'lint-prep', script: 'go mod tidy && git diff --exit-code') - sh(label: 'lint-run', script: 'make lint') - sh(label: 'Go vet', script: 'go vet') - } - } - } - withGithubNotify(context: "NOTICE.txt") { - withGoEnv(){ - dir("${BASE_DIR}"){ - sh(label: 'notice', script: ''' - make NOTICE.txt - git diff --exit-code --quiet && exit 0 || echo "regenerate NOTICE.txt" && exit 1 - ''') - } - } - } - } - } - stage('Test') { - failFast false - matrix { - agent {label "${PLATFORM}"} - options { skipDefaultCheckout() } - axes { - axis { - name 'PLATFORM' - values 'macosx && x86_64', 'ubuntu-18 && immutable' - } - } - stages { - stage('Build'){ - steps { - withGithubNotify(context: "Build-${GO_VERSION}-${PLATFORM}") { - deleteDir() - unstash 'source' - withGoEnv(){ - dir("${BASE_DIR}"){ - cmd(label: 'make build', script: 'make build') - } - } - } - } - } - stage('Test') { - steps { - withGithubNotify(context: "Test-${GO_VERSION}-${PLATFORM}") { - withGoEnv(){ - dir("${BASE_DIR}"){ - goTestJUnit(options: '-v ./...', output: 'junit-report.xml') - } - } - } - } - post { - always { - junit(allowEmptyResults: true, keepLongStdio: true, testResults: '**/junit-report.xml') - } - } - } - } - } - } - stage('Release') { - options { skipDefaultCheckout() } - when { - tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: 'REGEXP' - } - stages { - stage('BuildPublish') { - failFast false - matrix { - agent {label "${PLATFORM}"} - options { skipDefaultCheckout() } - environment { - HOME = "${env.WORKSPACE}" // required by "bash_standard_lib.sh" for "Push Docker Image" step - } - axes { - axis { - name 'PLATFORM' - values 'arm', 'ubuntu-18 && immutable' - } - } - stages { - stage('Dist') { - steps { - withGithubNotify(context: "Dist-${PLATFORM}") { - deleteDir() - unstash 'source' - withGoEnv(){ - dir("${BASE_DIR}"){ - cmd(label: 'make dist', script: 'make dist') - } - } - } - } - } - stage('PushDockerImage') { - steps { - withGithubNotify(context: "Push-Docker-${PLATFORM}") { - withGoEnv(){ - dir("${BASE_DIR}"){ - dockerLogin(secret: "${DOCKER_SECRET}", registry: "${DOCKER_REGISTRY}") - cmd(label: 'make push-docker', script: 'make push-docker') - } - } - } - } - } - stage('DeletePreviousLayer') { - steps { - withGithubNotify(context: "Delete-Layer-${PLATFORM}") { - withGoEnv(){ - withAWSEnv(secret: 'secret/observability-team/ci/service-account/apm-aws-lambda', forceInstallation: true, version: '2.4.10') { - dir("${BASE_DIR}"){ - cmd(label: 'make delete-in-all-aws-regions', script: 'make delete-in-all-aws-regions', returnStatus: true) - } - } - } - } - } - } - stage('PublishLayer') { - steps { - withGithubNotify(context: "Publish-Layer-${PLATFORM}") { - withGoEnv(){ - withAWSEnv(secret: 'secret/observability-team/ci/service-account/apm-aws-lambda', forceInstallation: true, version: '2.4.10') { - dir("${BASE_DIR}"){ - cmd(label: 'make publish-in-all-aws-regions', script: 'make publish-in-all-aws-regions') - cmd(label: 'make create-arn-file', script: 'make create-arn-file') - 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}/.regions") - archiveArtifacts(allowEmptyArchive: true, artifacts: "${BASE_DIR}/*${SUFFIX_ARN_FILE}") - archiveArtifacts(allowEmptyArchive: true, artifacts: "${BASE_DIR}/.aws") - } - } - } - } - } - } - stage('Release Notes') { - steps { - withGhEnv(forceInstallation: true, version: '2.4.0') { - dir("${BASE_DIR}"){ - unstash "arn-arm" - unstash "arn-amd" - unstash "dist-arm" - unstash "dist-amd" - cmd(label: 'make release-notes', script: 'make release-notes') - } - } - } - } - } - } - } - post { - cleanup { - notifyBuildResult(prComment: true) - } - success { - whenTrue(isTag()) { - notifyStatus(slackStatus: 'good', subject: "[${env.REPO}] Release *${env.TAG_NAME}* published", body: "Build: (<${env.RUN_DISPLAY_URL}|here>)\nRelease URL: ${env.RELEASE_URL_MESSAGE}") - } - } - unsuccessful { - whenTrue(isTag()) { - notifyStatus(slackStatus: 'warning', subject: "[${env.REPO}] Release *${env.TAG_NAME}* could not be published.", body: "Build: (<${env.RUN_DISPLAY_URL}|here>)") - } - } - } -} - -/** -* Transform TAG releases from v{major}.{minor}.{patch} to -* ver-{major}-{minor}-{patch}. f.i: given v1.2.3 then -* -ver-1-2-3. -*/ -def getVersion() { - if (env.BRANCH_NAME?.trim() && env.BRANCH_NAME.startsWith('v')) { - return env.BRANCH_NAME.replaceAll('v', '-ver-').replaceAll('\\.', '-') - } - return '' -} - -def notifyStatus(def args = [:]) { - releaseNotification(slackChannel: "${env.SLACK_CHANNEL}", - slackColor: args.slackStatus, - slackCredentialsId: 'jenkins-slack-integration-token', - to: "${env.NOTIFY_TO}", - subject: args.subject, - body: args.body) -} diff --git a/.ci/jobs/apm-aws-lambda-mbp.yml b/.ci/jobs/apm-aws-lambda-mbp.yml deleted file mode 100644 index 79d3b6e7..00000000 --- a/.ci/jobs/apm-aws-lambda-mbp.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -- job: - name: library/apm-aws-lambda-mbp - display-name: AWS Lambda extension - description: AWS Lambda extension MBP - project-type: multibranch - concurrent: true - script-path: .ci/Jenkinsfile - scm: - - github: - branch-discovery: no-pr - discover-pr-forks-strategy: merge-current - discover-pr-forks-trust: permission - discover-pr-origin: merge-current - discover-tags: true - head-filter-regex: '(main|PR-.*|v\d+\.\d+\.\d+.*)' - notification-context: 'apm-ci' - repo: apm-aws-lambda - repo-owner: elastic - credentials-id: 2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken - ssh-checkout: - credentials: f6c7695a-671e-4f4f-a331-acdce44ff9ba - build-strategies: - - tags: - ignore-tags-older-than: -1 - ignore-tags-newer-than: -1 - - regular-branches: true - - change-request: - ignore-target-only-changes: true - clean: - after: true - before: true - prune: true - shallow-clone: true - depth: 3 - do-not-fetch-tags: true - submodule: - disable: false - recursive: true - parent-credentials: true - timeout: 100 - timeout: '15' - use-author: true - wipe-workspace: 'True' - prune-dead-branches: true diff --git a/.ci/push_docker.sh b/.ci/push_docker.sh deleted file mode 100755 index 61f2083c..00000000 --- a/.ci/push_docker.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# This script is present on workers but may not be present in a development -# environment. - -if [ ${WORKSPACE+x} ] # We are on a CI worker -then - source /usr/local/bin/bash_standard_lib.sh -fi - -readonly RETRIES=3 - -readonly DOCKER_REGISTRY_URL="$1" - -readonly DOCKER_IMAGE_NAME="$2" - -readonly DOCKER_TAG="$3" - -readonly DOCKER_PUSH_IMAGE="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:$DOCKER_TAG" - -readonly DOCKER_PUSH_IMAGE_LATEST="$DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:latest" - -echo "INFO: Pushing image $DOCKER_PUSH_IMAGE to $DOCKER_REGISTRY_URL" - -if [ ${WORKERS+x} ] # We are on a CI worker -then - retry $RETRIES docker push $DOCKER_PUSH_IMAGE || echo "Push failed after $RETRIES retries" -else # We are in a local (non-CI) environment - docker push $DOCKER_PUSH_IMAGE || echo "You may need to run 'docker login' first and then re-run this script" -fi - -readonly LATEST_TAG=$(git tag --list --sort=version:refname "v*" | grep -v - | cut -c2- | tail -n1) - -if [ "$DOCKER_TAG" = "$LATEST_TAG" ] -then - echo "INFO: Current version ($DOCKER_TAG) is the latest version. Tagging and pushing $DOCKER_PUSH_IMAGE_LATEST ..." - docker tag $DOCKER_PUSH_IMAGE $DOCKER_PUSH_IMAGE_LATEST - - if [ ${WORKERS+x} ] # We are on a CI worker - then - retry $RETRIES docker push $DOCKER_PUSH_IMAGE_LATEST || echo "Push failed after $RETRIES retries" - else # We are in a local (non-CI) environment - docker push $DOCKER_PUSH_IMAGE_LATEST || echo "You may need to run 'docker login' first and then re-run this script" - fi -fi From 90a839076c68eb06c1844a4349a112505cee4e65 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 24 Jan 2023 18:48:08 +0100 Subject: [PATCH 08/51] Add smoke test rules again --- Makefile | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Makefile b/Makefile index e2bc9a14..b64394fa 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,36 @@ lint: NOTICE.txt: go.mod @bash ./scripts/notice.sh + + +############################################################################## +# Smoke tests -- Basic smoke tests for the APM Lambda extension +############################################################################## + +SMOKETEST_VERSIONS ?= latest +SMOKETEST_DIRS = $$(find ./tf -mindepth 0 -maxdepth 0 -type d) + +.PHONY: smoketest/discover +smoketest/discover: + @echo "$(SMOKETEST_DIRS)" + +.PHONY: smoketest/run +smoketest/run: build + @ for version in $(shell echo $(SMOKETEST_VERSIONS) | tr ',' ' '); do \ + echo "-> Running $(TEST_DIR) smoke tests for version $${version}..."; \ + cd $(TEST_DIR) && ./test.sh $${version}; \ + done + +.PHONY: smoketest/cleanup +smoketest/cleanup: + @ cd $(TEST_DIR); \ + if [ -f "./cleanup.sh" ]; then \ + ./cleanup.sh; \ + fi + +.PHONY: smoketest/all +smoketest/all/cleanup: + @ for test_dir in $(SMOKETEST_DIRS); do \ + echo "-> Cleanup $${test_dir} smoke tests..."; \ + $(MAKE) smoketest/cleanup TEST_DIR=$${test_dir}; \ + done From 0a7eefd81219f77b29abb5830a718ef7f4a471aa Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 08:30:36 +0100 Subject: [PATCH 09/51] Remove outputs --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 534d04b3..82831cb2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,9 +17,6 @@ permissions: jobs: build: runs-on: ubuntu-latest - outputs: - os: ${{ steps.artifacts.outputs.os }} - arch: ${{ steps.artifacts.outputs.arch }} steps: - uses: actions/checkout@v3 with: From fbd2a6901714cf0c13a10e4c3708ca7f0b741bcb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 08:55:10 +0100 Subject: [PATCH 10/51] Add slack notification --- .github/workflows/release.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82831cb2..128071ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,4 +54,27 @@ jobs: env: VERSION: ${{ github.ref_name }} + - if: ${{ success() }} + uses: elastic/apm-pipeline-library/.github/actions/slack-message@current + with: + url: ${{ secrets.VAULT_ADDR }} + roleId: ${{ secrets.VAULT_ROLE_ID }} + secretId: ${{ secrets.VAULT_SECRET_ID }} + channel: "#apm-serverless" + message: | + :large_green_circle: [${{ github.repository }}] Release *${{ github.ref_name }}* published." + Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) + + - if: ${{ failure() }} + uses: elastic/apm-pipeline-library/.github/actions/slack-message@current + with: + url: ${{ secrets.VAULT_ADDR }} + roleId: ${{ secrets.VAULT_ROLE_ID }} + secretId: ${{ secrets.VAULT_SECRET_ID }} + channel: "#apm-serverless" + message: | + :large_yellow_circle: [${{ github.repository }}] Release *${{ github.ref_name }}* could not be published." + Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) + + From 03751bc415ec09f7cf715f8aa753d1fcfe5f3636 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:04:26 +0100 Subject: [PATCH 11/51] Update .ci/publish-aws.sh Co-authored-by: Victor Martinez --- .ci/publish-aws.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index ed70c443..9b52b4eb 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -4,7 +4,7 @@ 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.} +GOOS=${GOOS:?Please 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.} From b564627bd718c5cb467d92375870fc8cbe516c50 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:05:41 +0100 Subject: [PATCH 12/51] Adjust shebang --- .ci/publish-aws.sh | 2 +- .ci/release-github.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 9b52b4eb..364fa6fa 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail export AWS_FOLDER=${AWS_FOLDER:-.aws} diff --git a/.ci/release-github.sh b/.ci/release-github.sh index 4df7190b..9a199263 100755 --- a/.ci/release-github.sh +++ b/.ci/release-github.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail export SUFFIX_ARN_FILE=${SUFFIX_ARN_FILE:-arn-file.md} From 88f138d4cfddba7d546cd88502220949eced7a0c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:11:32 +0100 Subject: [PATCH 13/51] Use make to the release --- .github/workflows/release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 128071ce..0659e6fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,10 +45,12 @@ jobs: 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 + - name: Install GoReleaser uses: goreleaser/goreleaser-action@v4 with: - args: release --rm-dist + install-only: true + - name: Release + run: make release - name: GitHub Release run: make release-notes env: From 37f2b84fc08fc9e4dacb7d8fdc6afe114cc41288 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:15:09 +0100 Subject: [PATCH 14/51] Move test command to Makfile --- .github/workflows/test.yml | 4 +--- Makefile | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4365af82..b81ed6a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,9 +26,7 @@ jobs: - name: Build run: make build - name: Test - run: | - go install gotest.tools/gotestsum@latest - gotestsum --format testname --junitfile ${{ matrix.platform }}-junit-report.xml + run: make test junitfile="${{ matrix.platform }}-junit-report.xml" - uses: actions/upload-artifact@v3 if: success() || failure() with: diff --git a/Makefile b/Makefile index b64394fa..ca8c749b 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,10 @@ release: release-notes: @./.ci/release-github.sh +test: + @go install gotest.tools/gotestsum@latest + @gotestsum --format testname --junitfile $(junitfile) + lint: @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 run From ef2f48513e78096b346a8655ed21bf6c2786bb5d Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:15:21 +0100 Subject: [PATCH 15/51] Fix build command --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b81ed6a1..7ce87ee6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: with: go-version-file: 'go.mod' - name: Build - run: make build + run: make dist - name: Test run: make test junitfile="${{ matrix.platform }}-junit-report.xml" - uses: actions/upload-artifact@v3 From 7b1c80c4bf936c08d00e59c0e8c8ad5096e93ded Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:20:01 +0100 Subject: [PATCH 16/51] Add opentelemtry workflow --- .github/workflows/opentelemetry.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/opentelemetry.yml diff --git a/.github/workflows/opentelemetry.yml b/.github/workflows/opentelemetry.yml new file mode 100644 index 00000000..99b205c5 --- /dev/null +++ b/.github/workflows/opentelemetry.yml @@ -0,0 +1,23 @@ +--- +name: OpenTelemetry Export Trace + +on: + workflow_run: + workflows: + - Issue Labeler + - Add to obs-docs project + - Add to APM Project + - release + - test + - test-reporter + types: [completed] + +jobs: + otel-export-trace: + runs-on: ubuntu-latest + steps: + - uses: elastic/apm-pipeline-library/.github/actions/opentelemetry@current + with: + vaultUrl: ${{ secrets.VAULT_ADDR }} + vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} + vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} From f3b775a20760b2848b539adcc00cfd9b85bf4f08 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:23:11 +0100 Subject: [PATCH 17/51] Add opencontainers labels --- .goreleaser.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 28bb5c32..01b3123c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -48,6 +48,10 @@ dockers: build_flag_templates: - "--platform=linux/amd64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" + - "--label=org.opencontainers.image.created={{ .Date }}" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.version={{ .Version }}" extra_files: - NOTICE.txt - dependencies.asciidoc @@ -61,6 +65,10 @@ dockers: build_flag_templates: - "--platform=linux/arm64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" + - "--label=org.opencontainers.image.created={{ .Date }}" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.version={{ .Version }}" publishers: - name: publish-aws From b23272aaa3dcea334526b36ca458d0406d31f04b Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:24:10 +0100 Subject: [PATCH 18/51] Use more specific version for vault-action --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0659e6fc..f5eee730 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,7 @@ jobs: url: ${{ secrets.VAULT_ADDR }} roleId: ${{ secrets.VAULT_ROLE_ID }} secretId: ${{ secrets.VAULT_SECRET_ID }} - - uses: hashicorp/vault-action@v2 + - uses: hashicorp/vault-action@v2.4.2 with: url: ${{ secrets.VAULT_ADDR }} method: approle From 69f52a51aaece8dadeb843e11be8c67b87726594 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:26:35 +0100 Subject: [PATCH 19/51] Fix build test --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ce87ee6..31d15544 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,10 @@ jobs: - uses: actions/setup-go@v3 with: go-version-file: 'go.mod' + - name: Install GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + install-only: true - name: Build run: make dist - name: Test From e983461bcde6edbb27313427ade74352d59460a7 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:29:07 +0100 Subject: [PATCH 20/51] Run build on a seperate job --- .github/workflows/test.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31d15544..58e6bd5a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,12 +23,6 @@ jobs: - uses: actions/setup-go@v3 with: go-version-file: 'go.mod' - - name: Install GoReleaser - uses: goreleaser/goreleaser-action@v4 - with: - install-only: true - - name: Build - run: make dist - name: Test run: make test junitfile="${{ matrix.platform }}-junit-report.xml" - uses: actions/upload-artifact@v3 @@ -36,7 +30,19 @@ jobs: with: name: test-results path: '*-junit-report.xml' - + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - name: Install GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + install-only: true + - name: Build + run: make dist lint: runs-on: ubuntu-latest steps: From 2cc8c07f666570e281232e915d724a2cac706f5f Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:34:10 +0100 Subject: [PATCH 21/51] Pin gotestsum version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ca8c749b..f83e0618 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ release-notes: @./.ci/release-github.sh test: - @go install gotest.tools/gotestsum@latest + @go install gotest.tools/gotestsum@v1.9.0 @gotestsum --format testname --junitfile $(junitfile) lint: From 38753055563a324cf0231c74c3d80506e311e30a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:40:00 +0100 Subject: [PATCH 22/51] Make sure extension file filename is consistent in docker iamge --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0258237f..402ff777 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,5 @@ # https://github.com/docker-library/repo-info/tree/master/repos/alpine/remote FROM alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad ARG EXTENSION_FILE -COPY ${EXTENSION_FILE} NOTICE.txt dependencies.asciidoc /opt/ +COPY ${EXTENSION_FILE} /opt/elastic-apm-extension +COPY NOTICE.txt dependencies.asciidoc /opt/ From 26ad58d73304cd8bdd2270f2f250f51b1076c10c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 09:45:53 +0100 Subject: [PATCH 23/51] Add description to scripts --- .ci/publish-aws.sh | 7 ++++++- .ci/release-github.sh | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 364fa6fa..8c17a147 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash set -euo pipefail +# +# Publishes the created artifacts from GoReleaser to AWS as AWS Lambda Layers in every region. +# Finalized by generating an ARN table which will be used in the release notes. +# + export AWS_FOLDER=${AWS_FOLDER:-.aws} export SUFFIX_ARN_FILE=${SUFFIX_ARN_FILE:-arn-file.md} @@ -14,7 +19,7 @@ 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} +rm -rf "${AWS_FOLDER}" # Delete previous layers for region in $ALL_AWS_REGIONS; do diff --git a/.ci/release-github.sh b/.ci/release-github.sh index 9a199263..1193a2d6 100755 --- a/.ci/release-github.sh +++ b/.ci/release-github.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash set -euo pipefail +# +# Collects all created ARN tables created by .ci/publish-aws.sh script +# and publishes a GitHub Release Note with the given information. +# + export SUFFIX_ARN_FILE=${SUFFIX_ARN_FILE:-arn-file.md} VERSION=${VERSION:?Please provide VERSION environment variable. e.g. current git tag} From 5ac288888db3e154e6339269112fca97c322c7cb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:12:51 +0100 Subject: [PATCH 24/51] Use env to create docker image tag --- .goreleaser.yaml | 8 ++++---- Makefile | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 01b3123c..c7a265a4 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -43,8 +43,8 @@ dockers: goos: linux goarch: amd64 image_templates: - - 'docker.elastic.co/observability/{{ .ProjectName }}-x86_64:{{ trimprefix .Tag "v" }}' - - "docker.elastic.co/observability/{{ .ProjectName }}-x86_64:latest" + - '{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-x86_64:{{ trimprefix .Tag "v" }}' + - "{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-x86_64:latest" build_flag_templates: - "--platform=linux/amd64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" @@ -60,8 +60,8 @@ dockers: id: linux-arm64-image goarch: arm64 image_templates: - - 'docker.elastic.co/observability/{{ .ProjectName }}-arm64:{{ trimprefix .Tag "v" }}' - - "docker.elastic.co/observability/{{ .ProjectName }}-arm64:latest" + - '{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-arm64:{{ trimprefix .Tag "v" }}' + - "{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-arm64:latest" build_flag_templates: - "--platform=linux/arm64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" diff --git a/Makefile b/Makefile index f83e0618..a8d5a32a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL = /bin/bash -eo pipefail -DOCKER_IMAGE_NAME = observability/apm-lambda-extension -DOCKER_REGISTRY = docker.elastic.co +export DOCKER_IMAGE_NAME = observability/apm-lambda-extension +export DOCKER_REGISTRY = docker.elastic.co clean: @rm -rf dist/ From 43ab35c0c9a84a658511735844b65a3c216cbf92 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:13:09 +0100 Subject: [PATCH 25/51] Formatting --- .goreleaser.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c7a265a4..c2148138 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -43,8 +43,8 @@ dockers: goos: linux goarch: amd64 image_templates: - - '{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-x86_64:{{ trimprefix .Tag "v" }}' - - "{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-x86_64:latest" + - '{{ .Env.DOCKER_REGISTRY }}/{{ .Env.DOCKER_IMAGE_NAME }}-x86_64:{{ trimprefix .Tag "v" }}' + - "{{ .Env.DOCKER_REGISTRY }}/{{ .Env.DOCKER_IMAGE_NAME }}-x86_64:latest" build_flag_templates: - "--platform=linux/amd64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" @@ -60,8 +60,8 @@ dockers: id: linux-arm64-image goarch: arm64 image_templates: - - '{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-arm64:{{ trimprefix .Tag "v" }}' - - "{{ .Env.DOCKER_REGISTRY}}/{{ .Env.DOCKER_IMAGE_NAME }}-arm64:latest" + - '{{ .Env.DOCKER_REGISTRY }}/{{ .Env.DOCKER_IMAGE_NAME }}-arm64:{{ trimprefix .Tag "v" }}' + - "{{ .Env.DOCKER_REGISTRY }}/{{ .Env.DOCKER_IMAGE_NAME }}-arm64:latest" build_flag_templates: - "--platform=linux/arm64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" From 575766d202a55489fc24bde689284fbd64969b0c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:21:44 +0100 Subject: [PATCH 26/51] Mark PHONY rules --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index a8d5a32a..c0b63e5b 100644 --- a/Makefile +++ b/Makefile @@ -9,16 +9,19 @@ clean: dist: @goreleaser release --snapshot --rm-dist +.PHONY: release release: @goreleaser release --rm-dist release-notes: @./.ci/release-github.sh +.PHONY: test test: @go install gotest.tools/gotestsum@v1.9.0 @gotestsum --format testname --junitfile $(junitfile) +.PHONY: lint lint: @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 run From 818ba189182d8b9f02416284e1d75d785068b3d9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:23:51 +0100 Subject: [PATCH 27/51] Use Make rule for notice.txt --- .goreleaser.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c2148138..d7668471 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,7 +9,7 @@ before: - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .java . - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . # NOTICE.txt - - ./scripts/notice.sh + - make NOTICE.txt builds: - env: From e527f43daf19eeb30cfd25dbad82ee9f39fa3987 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:25:23 +0100 Subject: [PATCH 28/51] Move check-licences to Makefile rule --- .goreleaser.yaml | 4 +--- Makefile | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d7668471..c3756dbe 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,9 +5,7 @@ before: # test - 'sh -c "go test extension/*.go -v"' # check-licenses - - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing . - - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .java . - - go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . + - make check-licenses # NOTICE.txt - make NOTICE.txt diff --git a/Makefile b/Makefile index c0b63e5b..0364f40d 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,12 @@ lint: NOTICE.txt: go.mod @bash ./scripts/notice.sh +.PHONY: check-linceses +check-licenses: + @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing . + @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .java . + @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . + ############################################################################## # Smoke tests -- Basic smoke tests for the APM Lambda extension From 6b3bb5aca734423a653af535bca4d72799af510d Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:35:46 +0100 Subject: [PATCH 29/51] Move notice check to Makefile rule --- .github/workflows/test.yml | 4 +--- Makefile | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58e6bd5a..5ba658cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,9 +61,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: notice - run: | - make NOTICE.txt - git diff --exit-code --quiet && exit 0 || echo "regenerate NOTICE.txt" && exit 1 + run: make check-notice diff --git a/Makefile b/Makefile index 0364f40d..029acaa9 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,11 @@ check-licenses: @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . +.PHONY: check-notice +check-notice: + $(MAKE) NOTICE.txt + @git diff --exit-code --quiet NOTICE.txt && exit 0 || echo "regenerate NOTICE.txt" && exit 1 + ############################################################################## # Smoke tests -- Basic smoke tests for the APM Lambda extension ############################################################################## From b5323fa5cadad6531ffa956875457419abe8f28c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:41:09 +0100 Subject: [PATCH 30/51] Move to Makefile rule --- .github/workflows/test.yml | 9 +++------ Makefile | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ba658cd..6e58e9c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,12 +50,9 @@ jobs: - uses: actions/setup-go@v3 with: go-version-file: 'go.mod' - - name: lint-prep - run: go mod tidy && git diff --exit-code - - name: lint-run - run: make lint - - name: Go vet - run: go vet + - run: make lint-prep + - run: make lint + - run: go vet notice: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index 029acaa9..b8dbf5d5 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,10 @@ test: @go install gotest.tools/gotestsum@v1.9.0 @gotestsum --format testname --junitfile $(junitfile) +.PHONY: lint-prep +lint-prep: + @go mod tidy && git diff --exit-code + .PHONY: lint lint: @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version From 9589f03f437a900debee2dae3f05f3d0928b04da Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:45:32 +0100 Subject: [PATCH 31/51] Remove excess newlines --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f5eee730..908d1283 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,6 +77,3 @@ jobs: message: | :large_yellow_circle: [${{ github.repository }}] Release *${{ github.ref_name }}* could not be published." Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) - - - From 66d3978f0787dd5e0435e8bfdf65c7b700a5cf37 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:47:31 +0100 Subject: [PATCH 32/51] Use new channel name --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 908d1283..eebf331e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,7 @@ jobs: url: ${{ secrets.VAULT_ADDR }} roleId: ${{ secrets.VAULT_ROLE_ID }} secretId: ${{ secrets.VAULT_SECRET_ID }} - channel: "#apm-serverless" + channel: "#apm-aws-lambda" message: | :large_green_circle: [${{ github.repository }}] Release *${{ github.ref_name }}* published." Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) @@ -73,7 +73,7 @@ jobs: url: ${{ secrets.VAULT_ADDR }} roleId: ${{ secrets.VAULT_ROLE_ID }} secretId: ${{ secrets.VAULT_SECRET_ID }} - channel: "#apm-serverless" + channel: "#apm-aws-lambda" message: | :large_yellow_circle: [${{ github.repository }}] Release *${{ github.ref_name }}* could not be published." Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) From 02aa3fe7c40693271994b80ee86e89a0585f180e Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 10:52:46 +0100 Subject: [PATCH 33/51] Move to Makefile rule --- .goreleaser.yaml | 5 +---- Makefile | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c3756dbe..106e7e38 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,11 +2,8 @@ project_name: apm-lambda-extension before: hooks: - # test - - 'sh -c "go test extension/*.go -v"' - # check-licenses + - make check-extension - make check-licenses - # NOTICE.txt - make NOTICE.txt builds: diff --git a/Makefile b/Makefile index b8dbf5d5..9f6b9294 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,10 @@ check-notice: $(MAKE) NOTICE.txt @git diff --exit-code --quiet NOTICE.txt && exit 0 || echo "regenerate NOTICE.txt" && exit 1 +.PHONY: check-extension +check-extension: + @go test extension/*.go -v + ############################################################################## # Smoke tests -- Basic smoke tests for the APM Lambda extension ############################################################################## From 13332861707ef42f3d8e80b08cafe9fa895be7cb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 12:20:04 +0100 Subject: [PATCH 34/51] Set access and modification times for reproducible builds --- .ci/publish-aws.sh | 12 +++++++++++- .gitignore | 11 ++++++----- .goreleaser.yaml | 2 ++ Dockerfile | 4 ++++ Makefile | 13 +++++++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 8c17a147..02f98a84 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -36,6 +36,16 @@ done mkdir -p "${AWS_FOLDER}" +# Related to reproducible builds +zip_file="./dist/${VERSION}-${GOOS}-${GOARCH}.zip" +new_zip_file="./dist/${VERSION}-${GOOS}-${GOARCH}-with-build-time.zip" +tmp_dir=".tmp/${VERSION}-${GOOS}-${GOARCH}" +rm -rf "$tmp_dir" +mkdir -p .tmp +unzip "${zip_file}" -d "${tmp_dir}" +find "${tmp_dir}" -exec touch -t "${BUILD_DATE}" {} \; +(cd "${tmp_dir}" && zip -X -r "../../${new_zip_file}" .) + for region in $ALL_AWS_REGIONS; do echo "Publish ${FULL_LAYER_NAME} in ${region}" publish_output=$(aws lambda \ @@ -45,7 +55,7 @@ for region in $ALL_AWS_REGIONS; do --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") + --zip-file="fileb://${new_zip_file}") 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}" diff --git a/.gitignore b/.gitignore index 2989719b..705eddae 100644 --- a/.gitignore +++ b/.gitignore @@ -20,13 +20,14 @@ # Dependency directories (remove the comment below to include it) # vendor/ -# AWS regions file -.regions -.aws-*/ -*arn-file.md - bin/ # local docs html_docs + +# temporary release files dist/ +.tmp +.aws-*/ +*arn-file.md + diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 106e7e38..d7a3f854 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -43,6 +43,7 @@ dockers: build_flag_templates: - "--platform=linux/amd64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" + - "--build-arg=BUILD_DATE={{ .Env.BUILD_DATE }}" - "--label=org.opencontainers.image.created={{ .Date }}" - "--label=org.opencontainers.image.title={{ .ProjectName }}" - "--label=org.opencontainers.image.revision={{ .FullCommit }}" @@ -60,6 +61,7 @@ dockers: build_flag_templates: - "--platform=linux/arm64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" + - "--build-arg=BUILD_DATE={{ .Env.BUILD_DATE }}" - "--label=org.opencontainers.image.created={{ .Date }}" - "--label=org.opencontainers.image.title={{ .ProjectName }}" - "--label=org.opencontainers.image.revision={{ .FullCommit }}" diff --git a/Dockerfile b/Dockerfile index 402ff777..22e69c96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,5 +3,9 @@ # https://github.com/docker-library/repo-info/tree/master/repos/alpine/remote FROM alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad ARG EXTENSION_FILE +ARG BUILD_DATE COPY ${EXTENSION_FILE} /opt/elastic-apm-extension COPY NOTICE.txt dependencies.asciidoc /opt/ + +# Related to reproducible builds +RUN find /opt -exec touch -t ${BUILD_DATE} {} \; diff --git a/Makefile b/Makefile index 9f6b9294..898992dd 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,19 @@ SHELL = /bin/bash -eo pipefail export DOCKER_IMAGE_NAME = observability/apm-lambda-extension export DOCKER_REGISTRY = docker.elastic.co +# Add support for SOURCE_DATE_EPOCH and reproducble buils +# See https://reproducible-builds.org/specs/source-date-epoch/ +SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) +DATE_FMT = +%Y%m%d%H%M.%S +# Fallback mechanism to support other systems: +# 1. 'date -d': Busybox and GNU coreutils. +# 2. 'date -r': BSD date. It does not support '-d'. +export BUILD_DATE = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}") + + +date: + @echo $(BUILD_DATE) + clean: @rm -rf dist/ @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs docker rmi --force From 71bc0e2a67e393cf97da9f694ff58e39753ef958 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 13:15:43 +0100 Subject: [PATCH 35/51] Fix docker build in test --- .github/workflows/test.yml | 5 +++++ Dockerfile | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e58e9c2..9df9ecd4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,11 @@ jobs: - 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 - name: Install GoReleaser uses: goreleaser/goreleaser-action@v4 with: diff --git a/Dockerfile b/Dockerfile index 22e69c96..7338ea84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,5 @@ COPY ${EXTENSION_FILE} /opt/elastic-apm-extension COPY NOTICE.txt dependencies.asciidoc /opt/ # Related to reproducible builds -RUN find /opt -exec touch -t ${BUILD_DATE} {} \; +RUN find /opt -exec touch -t "${BUILD_TIME}" {} \; + From 8bd2e4302b57a015a963ec39b16642bc946df466 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 15:38:04 +0100 Subject: [PATCH 36/51] Use `go run ...` instead of binary --- .github/workflows/release.yml | 4 ---- .github/workflows/test.yml | 4 ---- Makefile | 10 +++------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eebf331e..f13436a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,10 +45,6 @@ jobs: 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: Install GoReleaser - uses: goreleaser/goreleaser-action@v4 - with: - install-only: true - name: Release run: make release - name: GitHub Release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9df9ecd4..c829af8d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,10 +42,6 @@ jobs: platforms: linux/arm64, linux/amd64 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Install GoReleaser - uses: goreleaser/goreleaser-action@v4 - with: - install-only: true - name: Build run: make dist lint: diff --git a/Makefile b/Makefile index 898992dd..43c56d45 100644 --- a/Makefile +++ b/Makefile @@ -12,27 +12,23 @@ DATE_FMT = +%Y%m%d%H%M.%S export BUILD_DATE = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}") -date: - @echo $(BUILD_DATE) - clean: @rm -rf dist/ @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs docker rmi --force dist: - @goreleaser release --snapshot --rm-dist + @go run github.com/goreleaser/goreleaser@v1.14.1 release --snapshot --rm-dist .PHONY: release release: - @goreleaser release --rm-dist + go run github.com/goreleaser/goreleaser@v1.14.1 release --rm-dist release-notes: @./.ci/release-github.sh .PHONY: test test: - @go install gotest.tools/gotestsum@v1.9.0 - @gotestsum --format testname --junitfile $(junitfile) + @go run gotest.tools/gotestsum@v1.9.0 --format testname --junitfile $(junitfile) .PHONY: lint-prep lint-prep: From ec50ef8bdece29b6d5b5b7461a2021a3f4c04d64 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 15:40:48 +0100 Subject: [PATCH 37/51] Update .ci/publish-aws.sh Co-authored-by: Victor Martinez --- .ci/publish-aws.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 02f98a84..bd83df39 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -14,6 +14,7 @@ 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} +BUILD_DATE=${BUILD_DATE:?Please provide BUILD_DATE environment variable.} FULL_LAYER_NAME="${ELASTIC_LAYER_NAME}-${ARCHITECTURE}" From b1c1134f0d8adbb8e1b1a9c6447766e508a9f685 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 17:20:27 +0100 Subject: [PATCH 38/51] Add compatible-architectures metadata --- .ci/publish-aws.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index bd83df39..13d409c9 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -54,6 +54,7 @@ for region in $ALL_AWS_REGIONS; do publish-layer-version \ --region="${region}" \ --layer-name="${FULL_LAYER_NAME}" \ + --compatible-architectures="${ARCHITECTURE}" \ --description="AWS Lambda Extension Layer for Elastic APM ${ARCHITECTURE}" \ --license="Apache-2.0" \ --zip-file="fileb://${new_zip_file}") From 858bd1902a08bc635909928d52e9e66c68ea1a7b Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 25 Jan 2023 17:35:09 +0100 Subject: [PATCH 39/51] Delete zip without custom build_time and rename the zip to the original name --- .ci/publish-aws.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 13d409c9..8a31efc4 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -46,6 +46,8 @@ mkdir -p .tmp unzip "${zip_file}" -d "${tmp_dir}" find "${tmp_dir}" -exec touch -t "${BUILD_DATE}" {} \; (cd "${tmp_dir}" && zip -X -r "../../${new_zip_file}" .) +rm -rf "${zip_file}" +mv "${new_zip_file}" "${zip_file}" for region in $ALL_AWS_REGIONS; do echo "Publish ${FULL_LAYER_NAME} in ${region}" @@ -57,7 +59,7 @@ for region in $ALL_AWS_REGIONS; do --compatible-architectures="${ARCHITECTURE}" \ --description="AWS Lambda Extension Layer for Elastic APM ${ARCHITECTURE}" \ --license="Apache-2.0" \ - --zip-file="fileb://${new_zip_file}") + --zip-file="fileb://${zip_file}") 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}" From c9ad1d72cb907a2e78ace5a1d9c35ca981719ff9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 30 Jan 2023 09:34:44 +0100 Subject: [PATCH 40/51] Remove check-extension rule --- .goreleaser.yaml | 1 - Makefile | 4 ---- 2 files changed, 5 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d7a3f854..dfdd3cdb 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -2,7 +2,6 @@ project_name: apm-lambda-extension before: hooks: - - make check-extension - make check-licenses - make NOTICE.txt diff --git a/Makefile b/Makefile index 43c56d45..ba663490 100644 --- a/Makefile +++ b/Makefile @@ -54,10 +54,6 @@ check-notice: $(MAKE) NOTICE.txt @git diff --exit-code --quiet NOTICE.txt && exit 0 || echo "regenerate NOTICE.txt" && exit 1 -.PHONY: check-extension -check-extension: - @go test extension/*.go -v - ############################################################################## # Smoke tests -- Basic smoke tests for the APM Lambda extension ############################################################################## From 8975604b5c891a79e4c925b6aadfed9d9c4b53bb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 09:13:57 +0100 Subject: [PATCH 41/51] Use goreleaser's mtime option to set the buildinfo in archives --- .ci/publish-aws.sh | 10 ---------- .goreleaser.yaml | 2 ++ Makefile | 3 ++- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 8a31efc4..9472252e 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -37,17 +37,7 @@ done mkdir -p "${AWS_FOLDER}" -# Related to reproducible builds zip_file="./dist/${VERSION}-${GOOS}-${GOARCH}.zip" -new_zip_file="./dist/${VERSION}-${GOOS}-${GOARCH}-with-build-time.zip" -tmp_dir=".tmp/${VERSION}-${GOOS}-${GOARCH}" -rm -rf "$tmp_dir" -mkdir -p .tmp -unzip "${zip_file}" -d "${tmp_dir}" -find "${tmp_dir}" -exec touch -t "${BUILD_DATE}" {} \; -(cd "${tmp_dir}" && zip -X -r "../../${new_zip_file}" .) -rm -rf "${zip_file}" -mv "${new_zip_file}" "${zip_file}" for region in $ALL_AWS_REGIONS; do echo "Publish ${FULL_LAYER_NAME} in ${region}" diff --git a/.goreleaser.yaml b/.goreleaser.yaml index dfdd3cdb..277365a0 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -27,6 +27,8 @@ archives: files: - NOTICE.txt - dependencies.asciidoc + builds_info: + mtime: "{{ .Env.BUILD_DATE_RFC_3339 }}" rlcp: true # https://goreleaser.com/deprecations/#archivesrlcp dockers: diff --git a/Makefile b/Makefile index ba663490..8c242a3b 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,12 @@ export DOCKER_REGISTRY = docker.elastic.co # See https://reproducible-builds.org/specs/source-date-epoch/ SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) DATE_FMT = +%Y%m%d%H%M.%S +DATE_FMT_RFC_3339 = +%Y-%m-%dT%H:%M:%SZ # Fallback mechanism to support other systems: # 1. 'date -d': Busybox and GNU coreutils. # 2. 'date -r': BSD date. It does not support '-d'. export BUILD_DATE = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}") - +export BUILD_DATE_RFC_3339 = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT_RFC_3339}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT_RFC_3339}") clean: @rm -rf dist/ From d15a6b9839f1db730b05ded25e0d0a026f0d0636 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 09:21:36 +0100 Subject: [PATCH 42/51] Fix Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7338ea84..f9280532 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,5 +8,5 @@ COPY ${EXTENSION_FILE} /opt/elastic-apm-extension COPY NOTICE.txt dependencies.asciidoc /opt/ # Related to reproducible builds -RUN find /opt -exec touch -t "${BUILD_TIME}" {} \; +RUN find /opt -exec touch -t "${BUILD_DATE}" {} \; From ccb7116483e31cb1ffac3080a25964ebe4b84f95 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 12:16:42 +0100 Subject: [PATCH 43/51] Use existing .CommitTimestamp --- .ci/publish-aws.sh | 1 - .goreleaser.yaml | 7 ++++--- Dockerfile | 4 ++-- Makefile | 7 ------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/.ci/publish-aws.sh b/.ci/publish-aws.sh index 9472252e..2c8f22f0 100755 --- a/.ci/publish-aws.sh +++ b/.ci/publish-aws.sh @@ -14,7 +14,6 @@ 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} -BUILD_DATE=${BUILD_DATE:?Please provide BUILD_DATE environment variable.} FULL_LAYER_NAME="${ELASTIC_LAYER_NAME}-${ARCHITECTURE}" diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 277365a0..d22aed84 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,6 +18,7 @@ builds: ldflags: - -s -w binary: "extensions/{{ .ProjectName }}" + mod_timestamp: '{{ .CommitTimestamp }}' archives: - id: zip @@ -28,7 +29,7 @@ archives: - NOTICE.txt - dependencies.asciidoc builds_info: - mtime: "{{ .Env.BUILD_DATE_RFC_3339 }}" + mtime: "{{ .CommitTimestamp }}" rlcp: true # https://goreleaser.com/deprecations/#archivesrlcp dockers: @@ -44,7 +45,7 @@ dockers: build_flag_templates: - "--platform=linux/amd64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" - - "--build-arg=BUILD_DATE={{ .Env.BUILD_DATE }}" + - "--build-arg=COMMIT_TIMESTAMP={{ .CommitTimestamp }}" - "--label=org.opencontainers.image.created={{ .Date }}" - "--label=org.opencontainers.image.title={{ .ProjectName }}" - "--label=org.opencontainers.image.revision={{ .FullCommit }}" @@ -62,7 +63,7 @@ dockers: build_flag_templates: - "--platform=linux/arm64" - "--build-arg=EXTENSION_FILE={{ .ProjectName }}" - - "--build-arg=BUILD_DATE={{ .Env.BUILD_DATE }}" + - "--build-arg=COMMIT_TIMESTAMP={{ .CommitTimestamp }}" - "--label=org.opencontainers.image.created={{ .Date }}" - "--label=org.opencontainers.image.title={{ .ProjectName }}" - "--label=org.opencontainers.image.revision={{ .FullCommit }}" diff --git a/Dockerfile b/Dockerfile index f9280532..bdc684ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,10 @@ # https://github.com/docker-library/repo-info/tree/master/repos/alpine/remote FROM alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad ARG EXTENSION_FILE -ARG BUILD_DATE +ARG COMMIT_TIMESTAMP COPY ${EXTENSION_FILE} /opt/elastic-apm-extension COPY NOTICE.txt dependencies.asciidoc /opt/ # Related to reproducible builds -RUN find /opt -exec touch -t "${BUILD_DATE}" {} \; +RUN find /opt -exec touch -amdt "${COMMIT_TIMESTAMP}" {} \; diff --git a/Makefile b/Makefile index 8c242a3b..c1390c2e 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,6 @@ export DOCKER_REGISTRY = docker.elastic.co # Add support for SOURCE_DATE_EPOCH and reproducble buils # See https://reproducible-builds.org/specs/source-date-epoch/ SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) -DATE_FMT = +%Y%m%d%H%M.%S -DATE_FMT_RFC_3339 = +%Y-%m-%dT%H:%M:%SZ -# Fallback mechanism to support other systems: -# 1. 'date -d': Busybox and GNU coreutils. -# 2. 'date -r': BSD date. It does not support '-d'. -export BUILD_DATE = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}") -export BUILD_DATE_RFC_3339 = $(shell date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT_RFC_3339}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT_RFC_3339}") clean: @rm -rf dist/ From 645fcfddc05f72acb45db59c1e6f20b4aa18924f Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 12:32:39 +0100 Subject: [PATCH 44/51] Set mtime also for files --- .goreleaser.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d22aed84..2bc43fcf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -26,8 +26,12 @@ archives: name_template: |- {{ .Tag }}-{{ .Os }}-{{ .Arch }} files: - - NOTICE.txt - - dependencies.asciidoc + - src: NOTICE.txt + info: + mtime: '{{ .CommitDate }}' + - src: dependencies.asciidoc + info: + mtime: '{{ .CommitDate }}' builds_info: mtime: "{{ .CommitTimestamp }}" rlcp: true # https://goreleaser.com/deprecations/#archivesrlcp From 8dc2d5ebfe97ccd7293e168f8a1c25a13fea487c Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 12:36:55 +0100 Subject: [PATCH 45/51] Remove unused SOURCE_DATE_EPOCH --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index c1390c2e..6551fcd5 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,6 @@ SHELL = /bin/bash -eo pipefail export DOCKER_IMAGE_NAME = observability/apm-lambda-extension export DOCKER_REGISTRY = docker.elastic.co -# Add support for SOURCE_DATE_EPOCH and reproducble buils -# See https://reproducible-builds.org/specs/source-date-epoch/ -SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) - clean: @rm -rf dist/ @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs docker rmi --force From 2c5201016e08901ffb500210e01e7ef94b4cbc13 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 12:38:30 +0100 Subject: [PATCH 46/51] Add zip rule --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 6551fcd5..a86be83f 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ clean: dist: @go run github.com/goreleaser/goreleaser@v1.14.1 release --snapshot --rm-dist +zip: + @go run github.com/goreleaser/goreleaser@v1.14.1 release --snapshot --rm-dist --skip-docker + .PHONY: release release: go run github.com/goreleaser/goreleaser@v1.14.1 release --rm-dist From 57d1dcb2c49088454fb106c0a13d461b57211061 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 12:42:01 +0100 Subject: [PATCH 47/51] Refactor --- Makefile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a86be83f..d9c45b5f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ SHELL = /bin/bash -eo pipefail + +GORELEASER_VERSION = "v1.14.1" +GO_LICENSER_VERSION = "v0.4.0" +GOLANGCI_LINT_VERSION = "v1.48.0" export DOCKER_IMAGE_NAME = observability/apm-lambda-extension export DOCKER_REGISTRY = docker.elastic.co @@ -7,14 +11,14 @@ clean: @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs docker rmi --force dist: - @go run github.com/goreleaser/goreleaser@v1.14.1 release --snapshot --rm-dist + @go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --snapshot --rm-dist zip: - @go run github.com/goreleaser/goreleaser@v1.14.1 release --snapshot --rm-dist --skip-docker + @go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --snapshot --rm-dist --skip-docker .PHONY: release release: - go run github.com/goreleaser/goreleaser@v1.14.1 release --rm-dist + go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --rm-dist release-notes: @./.ci/release-github.sh @@ -29,17 +33,17 @@ lint-prep: .PHONY: lint lint: - @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 version - @go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0 run + @go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) version + @go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run NOTICE.txt: go.mod @bash ./scripts/notice.sh .PHONY: check-linceses check-licenses: - @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing . - @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .java . - @go run github.com/elastic/go-licenser@v0.4.0 -d -exclude tf -exclude testing -ext .js . + @go run github.com/elastic/go-licenser@$(GO_LICENSER_VERSION) -d -exclude tf -exclude testing . + @go run github.com/elastic/go-licenser@$(GO_LICENSER_VERSION) -d -exclude tf -exclude testing -ext .java . + @go run github.com/elastic/go-licenser@$(GO_LICENSER_VERSION) -d -exclude tf -exclude testing -ext .js . .PHONY: check-notice From a3fc3748652f74d9b4e55daa5882ff62dcd69a15 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 12:43:55 +0100 Subject: [PATCH 48/51] Add .PHONY where missing --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index d9c45b5f..6dbb1bb4 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ clean: dist: @go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --snapshot --rm-dist +.PHONY: zip zip: @go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --snapshot --rm-dist --skip-docker @@ -20,6 +21,7 @@ zip: release: go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --rm-dist +.PHONY: release-notes release-notes: @./.ci/release-github.sh From d1b6db3aa0903759547e4d042d951c28e4aba315 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 2 Feb 2023 17:11:47 +0100 Subject: [PATCH 49/51] Failsafe clean rule --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6dbb1bb4..4e26a4fb 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ export DOCKER_REGISTRY = docker.elastic.co clean: @rm -rf dist/ - @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs docker rmi --force + @docker image ls "$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)*" -aq | xargs -I {} docker rmi --force {} || true dist: @go run github.com/goreleaser/goreleaser@$(GORELEASER_VERSION) release --snapshot --rm-dist From 2a93275a70640d12ba76d8e80c3ebdbd18fe62a9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 13 Feb 2023 09:36:39 +0100 Subject: [PATCH 50/51] Update Dockerfile Co-authored-by: kruskall <99559985+kruskall@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bdc684ab..97d1894a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Pin to Alpine 3.16.2 # For a complete list of hashes, see: # https://github.com/docker-library/repo-info/tree/master/repos/alpine/remote -FROM alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad +FROM --platform=$BUILDPLATFORM alpine@sha256:b95359c2505145f16c6aa384f9cc74eeff78eb36d308ca4fd902eeeb0a0b161b ARG EXTENSION_FILE ARG COMMIT_TIMESTAMP COPY ${EXTENSION_FILE} /opt/elastic-apm-extension From daa0ceec202377c22d98238e4b84d67088b135e1 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 13 Feb 2023 09:36:52 +0100 Subject: [PATCH 51/51] Update Dockerfile Co-authored-by: kruskall <99559985+kruskall@users.noreply.github.com> --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 97d1894a..85f4d049 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,5 +8,5 @@ COPY ${EXTENSION_FILE} /opt/elastic-apm-extension COPY NOTICE.txt dependencies.asciidoc /opt/ # Related to reproducible builds -RUN find /opt -exec touch -amdt "${COMMIT_TIMESTAMP}" {} \; +RUN find /opt -exec touch -am -d $(date -u -d @"${COMMIT_TIMESTAMP}" "+%Y%m%d%H%M.%S") -t $(date -u -d @"${COMMIT_TIMESTAMP}" "+%Y%m%d%H%M.%S") {} \;