Skip to content

Commit

Permalink
Add main_build and release_build workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhlogin committed Feb 2, 2024
1 parent 4422de1 commit 14068ff
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 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:
Expand All @@ -10,9 +11,9 @@ on:
- "release/v*"
env:
AWS_DEFAULT_REGION: us-east-1
TEST_TAG: 611364707713.dkr.ecr.us-east-1.amazonaws.com/eks/observability/adot-autoinstrumentation-python:test
STAGING_ECR_REGISTRY: 611364707713.dkr.ecr.us-east-1.amazonaws.com
STAGING_ECR_REGISTRY: 637423224110.dkr.ecr.us-east-1.amazonaws.com
STAGING_ECR_REPOSITORY: eks/observability/adot-autoinstrumentation-python
S3_INTEGRATION_BUCKET: ${{ secrets.S3_INTEGRATION_BUCKET }}

concurrency:
group: python-instrumentation-main-build
Expand All @@ -26,9 +27,9 @@ jobs:
build:
runs-on: ubuntu-latest
outputs:
python_image_tag: ${{ steps.java_agent_versioning.outputs.STAGING_TAG}}
python_distro_tag: ${{ steps.python_distro_versioning.outputs.STAGING_TAG}}
staging-image-name: ${{ steps.imageNameOutput.outputs.imageName }}
staging_wheel_file: ${}
staging_wheel_file: ${{ steps.staging_wheel_build.outputs.STAGING_WHEEL}}
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
Expand All @@ -39,14 +40,17 @@ jobs:
python-version: "3.11"

- name: Install Dependencies and Build Wheel
id: staging_wheel_build
run: |
pip install --upgrade pip setuptools wheel packaging build
rm -rf ./dist/*
cd ./aws-opentelemetry-distro
python3 -m build --outdir ../dist
python -m build --outdir ../dist
cd ../dist
pkg_version=$(grep '__version__' ../aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}')
pip wheel --no-deps aws_opentelemetry_distro-${pkg_version}.tar.gz
echo "ADOT_PYTHON_VERSION=$pkg_version" >> $GITHUB_OUTPUT
pip wheel --no-deps aws_opentelemetry_distro-$pkg_version.tar.gz
echo "STAGING_WHEEL=aws_opentelemetry_distro-$pkg_version-py3-none-any.whl" >> $GITHUB_OUTPUT
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -55,7 +59,7 @@ jobs:
aws-region: ${{ env.AWS_DEFAULT_REGION }}

- name: Upload wheel to S3
run: aws s3 cp dist/*.whl s3://your-s3-bucket/path/to/wheels/
run: aws s3 cp dist/*.whl ${{ env.S3_INTEGRATION_BUCKET }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -66,25 +70,29 @@ jobs:
- name: Log in to AWS ECR
uses: docker/login-action@v3
with:
registry: 611364707713.dkr.ecr.us-east-1.amazonaws.com
registry: ${{ env.STAGING_ECR_REGISTRY }}
env:
AWS_REGION: us-east-1
AWS_REGION: ${{ env.AWS_DEFAULT_REGION }}

- name: Copy Files to Docker Build Context
- name: Get Python Distro Image Tag
id: python_distro_versioning
run: |
mkdir -p $GITHUB_WORKSPACE/auto-instrumentation/
cp -r ./distro $GITHUB_WORKSPACE/auto-instrumentation/
cp -r docker_requirements $GITHUB_WORKSPACE/auto-instrumentation//
shortsha="$(git rev-parse --short HEAD)"
python_distro_tag=${{ steps.staging_wheel_build.outputs.ADOT_PYTHON_VERSION }}-$shortsha
echo "STAGING_TAG=$python_distro_tag" >> $GITHUB_OUTPUT
- name: Build and push staging image
uses: docker/build-push-action@v5
with:
push: true
context: $GITHUB_WORKSPACE/auto-instrumentation/
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:${{ steps.java_agent_versioning.outputs.STAGING_TAG }}
${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:${{ steps.python_distro_versioning.outputs.STAGING_TAG }}
- name: Set image name to output
id: imageNameOutput
run: echo "imageName=${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:${{ steps.java_agent_versioning.outputs.STAGING_TAG }}" >> "$GITHUB_OUTPUT"
run: echo "imageName=${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:${{ steps.python_distro_versioning.outputs.STAGING_TAG }}" >> "$GITHUB_OUTPUT"

# TODO: Add Contract test and E2E test
79 changes: 79 additions & 0 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release Build
on:
workflow_dispatch:
inputs:
version:
description: The version to tag the release with, e.g., 1.2.0, 1.2.1-alpha.1
required: true
env:
AWS_DEFAULT_REGION: us-east-1
STAGING_ECR_REGISTRY: 637423224110.dkr.ecr.us-east-1.amazonaws.com
STAGING_ECR_REPOSITORY: eks/observability/adot-autoinstrumentation-python

permissions:
id-token: write
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Dependencies and Build Wheel
id: staging_wheel_build
run: |
pip install --upgrade pip setuptools wheel packaging build
rm -rf ./dist/*
cd ./aws-opentelemetry-distro
python -m build --outdir ../dist
cd ../dist
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
pip wheel --no-deps aws_opentelemetry_distro-$pkg_version.tar.gz
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to AWS ECR
uses: docker/login-action@v3
with:
registry: ${{ env.STAGING_ECR_REGISTRY }}
env:
AWS_REGION: ${{ env.AWS_DEFAULT_REGION }}

- name: Build and push staging image
uses: docker/build-push-action@v5
with:
push: true
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:v${{ github.event.inputs.version }}
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
run: |
cp "dist/aws_opentelemetry_distro-${{ steps.staging_wheel_build.outputs.ADOT_PYTHON_VERSION }}-py3-none-any.whl" aws_opentelemetry_distro.whl
gh release create --target "$GITHUB_REF_NAME" \
--title "Release v${{ github.event.inputs.version }}" \
--draft \
"v${{ github.event.inputs.version }}" \
aws_opentelemetry_distro.whl
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
# Those two packages are essential to Python auto-instrumentation.
# - Grant the necessary access to `/autoinstrumentation` directory. `chmod -R go+r /autoinstrumentation`
# - For auto-instrumentation by container injection, the Linux command cp is
# used and must be availabe in the image.
# used and must be available in the image.
FROM python:3.10 AS build

WORKDIR /operator-build

ADD autoinstrumentation/image-requirements.txt .
ADD image-requirements.txt .
ADD aws-opentelemetry-distro/ ./aws-opentelemetry-distro/

RUN mkdir workspace && pip install --target workspace -r image-requirements.txt && pip install --target workspace ./aws_opentelemetry_distro
RUN mkdir workspace && pip install --target workspace -r image-requirements.txt && pip install --target workspace ./aws-opentelemetry-distro

FROM busybox

Expand Down
1 change: 0 additions & 1 deletion image-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
grpcio==1.60.0
opentelemetry-distro==0.43b0
# We don't use the distro[otlp] option which automatically includes exporters since gRPC is not appropriate for
# injected auto-instrumentation, where it has a strict dependency on the OS / Python version the artifact is built for.
opentelemetry-exporter-otlp-proto-http==1.22.0
Expand Down

0 comments on commit 14068ff

Please sign in to comment.