From 92b87f9cb633fb4bdebbb3b8f173f2683ee4b60f Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Tue, 7 Nov 2023 19:53:25 +0100 Subject: [PATCH 1/3] chore: fix set lambda log retention to 3 days --- packages/otelbin-validation/src/main.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/otelbin-validation/src/main.ts b/packages/otelbin-validation/src/main.ts index 46d25618..8431053d 100644 --- a/packages/otelbin-validation/src/main.ts +++ b/packages/otelbin-validation/src/main.ts @@ -5,6 +5,7 @@ import { ApiKeySourceType, AwsIntegration, LambdaIntegration, RestApi, UsagePlan import { Platform } from 'aws-cdk-lib/aws-ecr-assets'; import { PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; import { Architecture, DockerImageCode, DockerImageFunction } from 'aws-cdk-lib/aws-lambda'; +import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3'; import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment'; import { Construct } from 'constructs'; @@ -166,6 +167,7 @@ export class OTelBinValidationStack extends Stack { */ memorySize: 1024, timeout: Duration.seconds(15), + logRetention: RetentionDays.THREE_DAYS, }); const releaseResource = distributionResource.addResource(release.version); From 9f52df3eea389dcb779bc3bae8a05fdd74c45f46 Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Tue, 7 Nov 2023 19:53:35 +0100 Subject: [PATCH 2/3] fix: test env deletion --- .github/workflows/ci.yaml | 11 +++-------- .github/workflows/clean-up-test-env.yaml | 11 +++++++++++ .github/workflows/scripts/test_env_name.sh | 10 ++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/scripts/test_env_name.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bea8b0ea..2ab83e76 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -77,18 +77,13 @@ jobs: - name: Get test environment name id: get_test_env_name shell: bash + env: + REF_NAME: ${{ github.head_ref || github.ref_name }} # When the trigger is a pull event, use the PR's branch name (`github.head_ref`), which # is available only for pull trigger. Otherwise, use the branch on which the commit was pushed. # (Ref names in pull requests are in the shape of `/merge` and those will break CDK.) run: | - export REF_NAME="${{ github.head_ref || github.ref_name }}" - # Ensure test name is not long enough to break restrictions on length names in AWS (e.g., role-name length) - # This logic ensures test envs have max length 18. Names of length 13 to 17 will become of length 18 to ensure - # no accidental clashes. - if [[ ${#REF_NAME} -gt 12 ]]; then - REF_NAME="${REF_NAME:0:12}-$(echo "${REF_NAME:12}" | md5sum | awk '{print $1}' | cut -c 1-5 | tr -d '\n')" - fi - echo "test_env_name=${REF_NAME}" >> $GITHUB_OUTPUT || exit 1 + ./.github/workflows/scripts/test_env_name.sh >> $GITHUB_OUTPUT || exit 1 - name: Deploy validation backend shell: bash diff --git a/.github/workflows/clean-up-test-env.yaml b/.github/workflows/clean-up-test-env.yaml index 35fc80f2..7f381473 100644 --- a/.github/workflows/clean-up-test-env.yaml +++ b/.github/workflows/clean-up-test-env.yaml @@ -26,6 +26,17 @@ jobs: run: | npm ci + - name: Get test environment name + id: get_test_env_name + shell: bash + env: + REF_NAME: ${{ github.head_ref || github.ref_name }} + # When the trigger is a pull event, use the PR's branch name (`github.head_ref`), which + # is available only for pull trigger. Otherwise, use the branch on which the commit was pushed. + # (Ref names in pull requests are in the shape of `/merge` and those will break CDK.) + run: | + ./.github/workflows/scripts/test_env_name.sh >> $GITHUB_OUTPUT || exit 1 + - name: Delete validation backend shell: bash working-directory: packages/otelbin-validation diff --git a/.github/workflows/scripts/test_env_name.sh b/.github/workflows/scripts/test_env_name.sh new file mode 100644 index 00000000..92f07ed5 --- /dev/null +++ b/.github/workflows/scripts/test_env_name.sh @@ -0,0 +1,10 @@ +#!/bin/env bash + +# Ensure test name is not long enough to break restrictions on length names in AWS (e.g., role-name length) +# This logic ensures test envs have max length 18. Names of length 13 to 17 will become of length 18 to ensure +# no accidental clashes. +if [[ ${#REF_NAME} -gt 12 ]]; then + REF_NAME="${REF_NAME:0:12}-$(echo "${REF_NAME:12}" | md5sum | awk '{print $1}' | cut -c 1-5 | tr -d '\n')" +fi + +echo "${REF_NAME}" \ No newline at end of file From bcf8b79fd48e2145e40edb7d654b63d45cd056b9 Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Tue, 7 Nov 2023 19:58:34 +0100 Subject: [PATCH 3/3] fix: script permissions and wiring in pipelines --- .github/workflows/ci.yaml | 2 +- .github/workflows/clean-up-test-env.yaml | 2 +- .github/workflows/scripts/test_env_name.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 .github/workflows/scripts/test_env_name.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2ab83e76..694c5b8f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -83,7 +83,7 @@ jobs: # is available only for pull trigger. Otherwise, use the branch on which the commit was pushed. # (Ref names in pull requests are in the shape of `/merge` and those will break CDK.) run: | - ./.github/workflows/scripts/test_env_name.sh >> $GITHUB_OUTPUT || exit 1 + echo "test_env_name=$(./.github/workflows/scripts/test_env_name.sh)" >> $GITHUB_OUTPUT || exit 1 - name: Deploy validation backend shell: bash diff --git a/.github/workflows/clean-up-test-env.yaml b/.github/workflows/clean-up-test-env.yaml index 7f381473..59b76adc 100644 --- a/.github/workflows/clean-up-test-env.yaml +++ b/.github/workflows/clean-up-test-env.yaml @@ -35,7 +35,7 @@ jobs: # is available only for pull trigger. Otherwise, use the branch on which the commit was pushed. # (Ref names in pull requests are in the shape of `/merge` and those will break CDK.) run: | - ./.github/workflows/scripts/test_env_name.sh >> $GITHUB_OUTPUT || exit 1 + echo "test_env_name=$(./.github/workflows/scripts/test_env_name.sh)" >> $GITHUB_OUTPUT || exit 1 - name: Delete validation backend shell: bash diff --git a/.github/workflows/scripts/test_env_name.sh b/.github/workflows/scripts/test_env_name.sh old mode 100644 new mode 100755 index 92f07ed5..36da25cc --- a/.github/workflows/scripts/test_env_name.sh +++ b/.github/workflows/scripts/test_env_name.sh @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash # Ensure test name is not long enough to break restrictions on length names in AWS (e.g., role-name length) # This logic ensures test envs have max length 18. Names of length 13 to 17 will become of length 18 to ensure