Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
harrryr committed May 15, 2024
1 parent ab73636 commit 8bfd7ea
Show file tree
Hide file tree
Showing 7 changed files with 798 additions and 2 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This workflow build the aws-opentelemetry-distro wheel file, upload to staging S3 bucket, and build project docker image then push to staging ECR
name: Python Instrumentation Main Build
on:
push:

env:
AWS_DEFAULT_REGION: us-east-1
STAGING_ECR_REGISTRY: 637423224110.dkr.ecr.us-east-1.amazonaws.com
STAGING_ECR_REPOSITORY: aws-observability/adot-autoinstrumentation-python-staging
STAGING_S3_BUCKET: ${{ secrets.STAGING_BUCKET_NAME }}

concurrency:
group: python-instrumentation-main-build
cancel-in-progress: false

permissions:
id-token: write
contents: read

jobs:
build:
runs-on: ubuntu-latest
outputs:
aws_default_region: ${{ steps.python_output.outputs.awsDefaultRegion}}
python_image_tag: ${{ steps.python_output.outputs.python_image_tag}}
staging_image: ${{ steps.python_output.outputs.stagingImage}}
staging_registry: ${{ steps.python_output.outputs.stagingRegistry}}
staging_repository: ${{ steps.python_output.outputs.stagingRepository}}
staging_wheel_file: ${{ steps.staging_wheel_output.outputs.STAGING_WHEEL}}
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Get Python Distro Output
id: python_output
run: |
pkg_version=$(grep '__version__' ./aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}')
echo "ADOT_PYTHON_VERSION=$pkg_version" >> $GITHUB_OUTPUT
shortsha="$(git rev-parse --short HEAD)"
echo "SHORT_SHA=$shortsha" >> $GITHUB_ENV
python_distro_tag=$pkg_version-$shortsha
echo "awsDefaultRegion=${{ env.AWS_DEFAULT_REGION }}" >> $GITHUB_OUTPUT
echo "python_image_tag=$python_distro_tag" >> $GITHUB_OUTPUT
echo "stagingRegistry=${{ env.STAGING_ECR_REGISTRY }}" >> $GITHUB_OUTPUT
echo "stagingRepository=${{ env.STAGING_ECR_REPOSITORY }}" >> $GITHUB_OUTPUT
echo "stagingImage=${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:$python_distro_tag" >> $GITHUB_OUTPUT
- name: Build and Push Wheel and Image Files
uses: ./.github/actions/artifacts_build
with:
aws-region: ${{ env.AWS_DEFAULT_REGION }}
image_uri_with_tag: ${{ steps.python_output.outputs.stagingImage}}
image_registry: ${{ env.STAGING_ECR_REGISTRY }}
snapshot-ecr-role: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
push_image: true
load_image: false
python_version: "3.10"
package_name: aws-opentelemetry-distro
os: ubuntu-latest

# workaround: prefixing the short-sha with a 0 to create a valid
# wheel file name as per https://peps.python.org/pep-0427/#file-name-convention
- name: Output Wheel File Name
id: staging_wheel_output
run: |
staging_wheel="aws_opentelemetry_distro-${{ steps.python_output.outputs.ADOT_PYTHON_VERSION}}-0${{ env.SHORT_SHA }}-py3-none-any.whl"
echo "STAGING_WHEEL=$staging_wheel" >> $GITHUB_OUTPUT
cd ./dist
cp aws_opentelemetry_distro-${{ steps.python_output.outputs.ADOT_PYTHON_VERSION}}-py3-none-any.whl $staging_wheel
- name: Upload wheel to S3
run: |
aws s3 cp dist/${{ steps.staging_wheel_output.outputs.STAGING_WHEEL}} s3://${{ env.STAGING_S3_BUCKET }}
- name: Upload Wheel to GitHub Actions
uses: actions/upload-artifact@v3
with:
name: ${{ steps.staging_wheel_output.outputs.STAGING_WHEEL}}
path: dist/${{ steps.staging_wheel_output.outputs.STAGING_WHEEL}}

- name: Set up and run contract tests with pytest
run: |
bash scripts/set-up-contract-tests.sh
pip install pytest
pytest contract-tests/tests
# Application Signals specific e2e eks tests
application-signals-python-e2e-eks-test:
needs: [build]
uses: aws-observability/aws-application-signals-test-framework/.github/workflows/application-signals-python-e2e-eks-test.yml@main
secrets: inherit
with:
aws-region: ${{ needs.build.outputs.aws_default_region }}
test-cluster-name: e2e-python-adot-test
caller-workflow-name: 'main-build'
application-signals-adot-image: ${{ needs.build.outputs.staging_registry }}/aws-observability/adot-autoinstrumentation-python-staging
application-signals-adot-image-tag: ${{ needs.build.outputs.python_image_tag }}

# Application Signals specific e2e tests for ec2
application-signals-python-e2e-ec2-test:
needs: [ build ]
uses: aws-observability/aws-application-signals-test-framework/.github/workflows/application-signals-python-e2e-ec2-test.yml@main
secrets: inherit
with:
aws-region: ${{ needs.build.outputs.aws_default_region }}
staging_wheel_name: ${{ needs.build.outputs.staging_wheel_file }}
caller-workflow-name: 'main-build'
36 changes: 34 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,43 @@ ADD aws-opentelemetry-distro/ ./aws-opentelemetry-distro/
RUN sed -i "/opentelemetry-exporter-otlp-proto-grpc/d" ./aws-opentelemetry-distro/pyproject.toml

RUN mkdir workspace && pip install --target workspace ./aws-opentelemetry-distro
#RUN chmod -R go+r /autoinstrumentation

# Stage 1: Build the cp-utility binary
FROM rust:1.75 as builder

WORKDIR /usr/src/cp-utility
COPY ./tools/cp-utility .

## TARGETARCH is defined by buildx
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH

# Run validations and audit only on amd64 bacause it is faster and those two steps
# are only used to validate the source code and don't require anything that is
# architecture specific.

# Validations
## Validate formatting
RUN if [ $TARGETARCH = "amd64" ]; then rustup component add rustfmt && cargo fmt --check ; fi

## Audit dependencies
RUN if [ $TARGETARCH = "amd64" ]; then cargo install cargo-audit && cargo audit ; fi


# Cross-compile based on the target platform.
RUN if [ $TARGETARCH = "amd64" ]; then export ARCH="x86_64" ; \
elif [ $TARGETARCH = "arm64" ]; then export ARCH="aarch64" ; \
else false; \
fi \
&& rustup target add ${ARCH}-unknown-linux-musl \
&& cargo test --target ${ARCH}-unknown-linux-musl \
&& cargo install --target ${ARCH}-unknown-linux-musl --path . --root .

FROM scratch

FROM busybox
# Required to copy attribute files to distributed docker images
ADD THIRD-PARTY-LICENSES ./THIRD-PARTY-LICENSES

COPY --from=builder /usr/src/cp-utility/bin/cp-utility /bin/cp
COPY --from=build /operator-build/workspace /autoinstrumentation
RUN chmod -R go+r /autoinstrumentation
3 changes: 3 additions & 0 deletions tools/cp-utility/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use git CLI to fetch the source code instead of relying on the rust git implementation
[net]
git-fetch-with-cli = true
221 changes: 221 additions & 0 deletions tools/cp-utility/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8bfd7ea

Please sign in to comment.