Skip to content

Commit 380b619

Browse files
liustveMiqueashersrprashwangzlei
authored
cherry-pick main to release/0.18.x (#795)
Cherry-picked from main: - #791 - #793 - #788 - #786 - #794 --------- Co-authored-by: Miqueas Herrera <vherremi@amazon.com> Co-authored-by: Prashant Srivastava <50466688+srprash@users.noreply.github.com> Co-authored-by: Lei Wang <66336933+wangzlei@users.noreply.github.com>
1 parent f2c33a6 commit 380b619

43 files changed

Lines changed: 1419 additions & 127 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/artifacts_build/action.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ inputs:
88
required: false
99
description: "AWS Region, required only if push_image is true"
1010
image_uri_with_tag:
11-
required: true
12-
description: "Image URI with Tag"
11+
required: false
12+
description: "Image URI with Tag, required only if build_image is true"
1313
image_registry:
1414
required: false
1515
description: "Image Registry, required only if push_image is true"
1616
snapshot-ecr-role:
1717
required: false
1818
description: "IAM Role used for pushing to snapshot ecr, required only if push_image is true"
1919
push_image:
20-
required: true
20+
required: false
21+
default: 'false'
2122
description: "Whether push image to ECR"
2223
load_image:
23-
required: true
24+
required: false
25+
default: 'false'
2426
description: "Whether load the image for the following use, only load in PR build"
2527
python_version:
2628
required: true
@@ -31,6 +33,14 @@ inputs:
3133
os:
3234
required: true
3335
description: "The os"
36+
run_unit_tests:
37+
required: false
38+
default: 'true'
39+
description: "Whether to run unit tests during setup. Set to false when unit tests run in a separate job."
40+
build_image:
41+
required: false
42+
default: 'true'
43+
description: "Whether to build and scan the operator image. Set to false for wheel-only callers (e.g. contract tests, which don't use the operator image)."
3444
trivyignore-file:
3545
required: false
3646
default: ''
@@ -45,10 +55,10 @@ runs:
4555
using: "composite"
4656
steps:
4757
- name: Action verification
48-
if: ${{ (inputs.load_image == false || inputs.load_image == 'false') && (inputs.push_image == false || inputs.push_image == 'false') }}
58+
if: ${{ (inputs.build_image == true || inputs.build_image == 'true') && (inputs.load_image == false || inputs.load_image == 'false') && (inputs.push_image == false || inputs.push_image == 'false') }}
4959
shell: bash
5060
run: |
51-
echo "At least one of push_image or load_image must be true"
61+
echo "At least one of push_image or load_image must be true"
5262
exit 1
5363
5464
- name: Set up
@@ -57,7 +67,7 @@ runs:
5767
python_version: ${{ inputs.python_version }}
5868
package_name: ${{ inputs.package_name }}
5969
os: ${{ inputs.os }}
60-
run_unit_tests: true
70+
run_unit_tests: ${{ inputs.run_unit_tests }}
6171

6272
- name: Configure AWS Credentials
6373
if: ${{ inputs.push_image == true || inputs.push_image == 'true' }}
@@ -76,6 +86,7 @@ runs:
7686
python -m build --outdir ../dist
7787
7888
- name: Set up QEMU
89+
if: ${{ inputs.build_image == true || inputs.build_image == 'true' }}
7990
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 #3.6.0
8091

8192
- name: Set up Docker Buildx
@@ -99,6 +110,7 @@ runs:
99110
run: docker logout public.ecr.aws
100111

101112
- name: Build and push image according to input
113+
if: ${{ inputs.build_image == true || inputs.build_image == 'true' }}
102114
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #6.18.0
103115
with:
104116
push: ${{ inputs.push_image }}
@@ -107,8 +119,11 @@ runs:
107119
platforms: ${{ inputs.platforms }}
108120
tags: ${{ inputs.image_uri_with_tag }}
109121
load: ${{ inputs.load_image }}
122+
cache-from: type=gha,scope=operator-image
123+
cache-to: type=gha,scope=operator-image,mode=max
110124

111125
- name: Perform image scan
126+
if: ${{ inputs.build_image == true || inputs.build_image == 'true' }}
112127
uses: ./.github/actions/image_scan
113128
with:
114129
image-ref: ${{ inputs.image_uri_with_tag }}

.github/actions/set_up/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
run_unit_tests:
1616
required: true
1717
description: "true/false flag indicating if we should run unit tests/benchmarks with tox"
18+
wheel_path:
19+
required: false
20+
default: ''
21+
description: "Optional path to a prebuilt aws-opentelemetry-distro wheel. When set, tox installs the distro from this wheel (via ADOT_WHEEL) instead of building from source."
1822

1923

2024
runs:
@@ -25,6 +29,11 @@ runs:
2529
with:
2630
python-version: ${{ inputs.python_version }}
2731

32+
- name: Use prebuilt distro wheel
33+
if: ${{ inputs.wheel_path != '' }}
34+
shell: bash
35+
run: echo "ADOT_WHEEL=$(realpath '${{ inputs.wheel_path }}')" >> "$GITHUB_ENV"
36+
2837
- name: Install tox
2938
shell: bash
3039
run: |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
## SPDX-License-Identifier: Apache-2.0
3+
4+
name: Contract Tests
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
python-version:
10+
required: true
11+
type: string
12+
description: "Python version to build the application images against and test."
13+
wheel-artifact-name:
14+
required: false
15+
type: string
16+
default: distro-wheel
17+
description: "Name of the uploaded distro wheel artifact to download and install into the app images."
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
select-tests:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
tests: ${{ steps.filter.outputs.tests }}
27+
steps:
28+
- name: Checkout Repo @ SHA - ${{ github.sha }}
29+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
30+
31+
- name: Select tests supporting Python ${{ inputs.python-version }}
32+
id: filter
33+
env:
34+
PYTHON_VERSION: ${{ inputs.python-version }}
35+
run: |
36+
tests=$(yq -o=json '.' contract-tests/tests.yaml | jq -c --arg py "$PYTHON_VERSION" '
37+
.test_base as $base
38+
| [ .tests[]
39+
| select(.versions | index($py))
40+
| { name,
41+
pytest_args: ([ .paths[] | $base + "/" + . ] | join(" ")) } ]')
42+
echo "tests=$tests" >> "$GITHUB_OUTPUT"
43+
44+
contract-test:
45+
needs: select-tests
46+
runs-on: ubuntu-latest
47+
strategy:
48+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
49+
matrix:
50+
test: ${{ fromJSON(needs.select-tests.outputs.tests) }}
51+
name: ${{ matrix.test.name }}
52+
steps:
53+
- name: Checkout Repo @ SHA - ${{ github.sha }}
54+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #3.11.1
58+
59+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6.0.0
60+
with:
61+
python-version: '3.12'
62+
63+
- name: Download distro wheel
64+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 #v5.0.0
65+
with:
66+
name: ${{ inputs.wheel-artifact-name }}
67+
path: dist
68+
69+
- name: Set up and run ${{ matrix.test.name }} contract tests (python ${{ inputs.python-version }})
70+
run: |
71+
bash scripts/set-up-contract-tests.sh "${{ inputs.python-version }}" ${{ matrix.test.name }}
72+
pytest ${{ matrix.test.pytest_args }} -v

.github/workflows/di-contract-tests.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
pull_request:
88
branches:
99
- main
10+
- "release/v*"
1011
workflow_dispatch:
1112

1213
permissions:
@@ -19,27 +20,23 @@ jobs:
1920
strategy:
2021
matrix:
2122
python-version: ["3.10", "3.11", "3.12"]
23+
suite: ["django", "fastapi", "flask"]
2224
fail-fast: false
2325

2426
steps:
2527
- name: Checkout Repo @ SHA - ${{ github.sha }}
2628
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
2729

28-
- name: Build Wheel and Image Files
30+
- name: Build wheel
2931
uses: ./.github/actions/artifacts_build
3032
with:
31-
image_uri_with_tag: di-contract-tests/${{ matrix.python-version }}
32-
push_image: false
33-
load_image: true
34-
# `load` can only materialise a single-platform image into the local Docker
35-
# daemon; multi-platform builds produce a manifest list which buildx cannot load.
36-
platforms: linux/amd64
33+
build_image: false
34+
run_unit_tests: false
3735
python_version: ${{ matrix.python-version }}
3836
package_name: aws-opentelemetry-distro
3937
os: ubuntu-latest
4038

41-
- name: Set up and run DI contract tests
39+
- name: Set up and run di-${{ matrix.suite }} contract tests
4240
run: |
43-
bash scripts/set-up-contract-tests.sh ${{ matrix.python-version }}
44-
pip install pytest testcontainers typing_extensions
45-
pytest contract-tests/tests/test/amazon/di/ -v
41+
bash scripts/set-up-contract-tests.sh "${{ matrix.python-version }}" di-${{ matrix.suite }}
42+
pytest contract-tests/tests/test/amazon/di/${{ matrix.suite }}_test.py -v

.github/workflows/pr-build.yml

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,51 @@ jobs:
122122
123123
echo "No github.event usage found in run steps"
124124
125-
build:
125+
build-wheel:
126+
runs-on: ubuntu-latest
127+
steps:
128+
- name: Checkout Repo @ SHA - ${{ github.sha }}
129+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
130+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6.0.0
131+
with:
132+
python-version: '3.11'
133+
- name: Build distro wheel
134+
run: |
135+
pip install --upgrade pip setuptools wheel packaging build
136+
rm -rf ./dist/*
137+
cd ./aws-opentelemetry-distro
138+
python -m build --outdir ../dist
139+
- name: Upload distro wheel
140+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
141+
with:
142+
name: distro-wheel
143+
path: dist/aws_opentelemetry_distro-*-py3-none-any.whl
144+
retention-days: 1
145+
146+
build-lambda:
147+
runs-on: ubuntu-latest
148+
steps:
149+
- name: Checkout Repo @ SHA - ${{ github.sha }}
150+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
151+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6.0.0
152+
with:
153+
python-version: |
154+
3.10
155+
3.11
156+
3.12
157+
3.13
158+
3.14
159+
- name: Build sample lambda function
160+
working-directory: lambda-layer/sample-apps
161+
run: ./package-lambda-function.sh
162+
- name: Build layers
163+
working-directory: lambda-layer/src
164+
run: |
165+
./build-lambda-layer.sh
166+
pip install tox
167+
tox
168+
169+
build-and-scan-image:
126170
runs-on: ubuntu-latest
127171
strategy:
128172
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
@@ -132,7 +176,7 @@ jobs:
132176
- name: Checkout Repo @ SHA - ${{ github.sha }}
133177
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
134178

135-
- name: Build Wheel and Image Files
179+
- name: Build and scan operator image
136180
uses: ./.github/actions/artifacts_build
137181
with:
138182
image_uri_with_tag: pr-build/${{ matrix.python-version }}
@@ -141,32 +185,49 @@ jobs:
141185
python_version: ${{ matrix.python-version }}
142186
package_name: aws-opentelemetry-distro
143187
os: ubuntu-latest
188+
run_unit_tests: false
144189
trivyignore-file: .github/trivy/pr-build.trivyignore.yaml
145190
platforms: linux/amd64
146191

147-
- name: Set up and run contract tests with pytest
148-
run: |
149-
bash scripts/set-up-contract-tests.sh
150-
pip install pytest
151-
pytest contract-tests/tests
152-
153-
build-lambda:
192+
unit-tests:
154193
runs-on: ubuntu-latest
194+
needs: build-wheel
195+
strategy:
196+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
197+
matrix:
198+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
155199
steps:
156200
- name: Checkout Repo @ SHA - ${{ github.sha }}
157201
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
158-
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6.0.0
202+
203+
- name: Download distro wheel
204+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 #v5.0.0
159205
with:
160-
python-version: '3.x'
161-
- name: Build sample lambda function
162-
working-directory: lambda-layer/sample-apps
163-
run: ./package-lambda-function.sh
164-
- name: Build layers
165-
working-directory: lambda-layer/src
166-
run: |
167-
./build-lambda-layer.sh
168-
pip install tox
169-
tox
206+
name: distro-wheel
207+
path: dist
208+
209+
- name: Resolve wheel path
210+
id: wheel
211+
run: echo "path=$(ls dist/aws_opentelemetry_distro-*-py3-none-any.whl)" >> "$GITHUB_OUTPUT"
212+
213+
- name: Set up and run unit tests
214+
uses: ./.github/actions/set_up
215+
with:
216+
python_version: ${{ matrix.python-version }}
217+
package_name: aws-opentelemetry-distro
218+
os: ubuntu-latest
219+
run_unit_tests: true
220+
wheel_path: ${{ steps.wheel.outputs.path }}
221+
222+
contract-tests:
223+
needs: build-wheel
224+
strategy:
225+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
226+
matrix:
227+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
228+
uses: ./.github/workflows/contract-tests.yml
229+
with:
230+
python-version: ${{ matrix.python-version }}
170231

171232
lint:
172233
runs-on: ubuntu-latest
@@ -216,7 +277,7 @@ jobs:
216277

217278
all-pr-checks-pass:
218279
runs-on: ubuntu-latest
219-
needs: [static-code-checks, lint, spotless, build, build-lambda]
280+
needs: [static-code-checks, lint, spotless, unit-tests, build-wheel, build-and-scan-image, contract-tests, build-lambda]
220281
if: always()
221282
steps:
222283
- name: Checkout to get workflow file

.github/workflows/release-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ jobs:
314314
aws lambda publish-layer-version \
315315
--layer-name ${{ env.LAYER_NAME }} \
316316
--content S3Bucket=${{ env.BUCKET_NAME }},S3Key=${{ env.LAYER_ARTIFACT_NAME }} \
317-
--compatible-runtimes python3.10 python3.11 python3.12 python3.13 \
317+
--compatible-runtimes python3.10 python3.11 python3.12 python3.13 python3.14 \
318318
--compatible-architectures "arm64" "x86_64" \
319319
--license-info "Apache-2.0" \
320320
--description "AWS Distro of OpenTelemetry Lambda Layer for Python Runtime" \

0 commit comments

Comments
 (0)