Skip to content

Commit b52283a

Browse files
authored
Add release workflow for Python (aws-observability#673)
Fixes aws-observability#651
1 parent ab9ca49 commit b52283a

File tree

6 files changed

+88
-4
lines changed

6 files changed

+88
-4
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: "Release Python Lambda Layer"
2+
3+
on:
4+
# (Using tag push instead of release to allow filtering by tag prefix.)
5+
push:
6+
tags:
7+
- layer-python/**
8+
9+
permissions:
10+
id-token: write
11+
contents: read
12+
13+
jobs:
14+
build-layer:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
PYTHON_SDK_VERSION: ${{ steps.save-python-sdk-version.outputs.PYTHON_SDK_VERSION}}
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- uses: actions/setup-python@v3
22+
with:
23+
python-version: '3.9'
24+
25+
- name: Build
26+
run: |
27+
cd python/sample-apps
28+
PYTHON_SDK_VERSION=$(./run.sh -n opentelemetry-python-layer -b true 2>&1 > /dev/null | sed -n "s/opentelemetry-sdk==\(.*\)/\1/p")
29+
shell: bash
30+
31+
- name: Show directory contents
32+
run: |
33+
ls -al
34+
working-directory: python/sample-apps
35+
36+
- name: Save Python SDK Version
37+
id: save-python-sdk-version
38+
run: |
39+
echo "PYTHON_SDK_VERSION=$PYTHON_SDK_VERSION" >> $GITHUB_OUTPUT
40+
41+
- uses: actions/upload-artifact@v3
42+
name: Save assembled layer to build
43+
with:
44+
name: opentelemetry-python-layer.zip
45+
path: python/sample-apps/opentelemetry-python-layer.zip
46+
47+
publish-layer:
48+
uses: ./.github/workflows/layer-publish.yml
49+
needs: build-layer
50+
strategy:
51+
matrix:
52+
aws_region:
53+
# - ap-northeast-1
54+
# - ap-northeast-2
55+
# - ap-south-1
56+
# - ap-southeast-1
57+
# - ap-southeast-2
58+
# - ca-central-1
59+
# - eu-central-1
60+
# - eu-north-1
61+
# - eu-west-1
62+
# - eu-west-2
63+
# - eu-west-3
64+
# - sa-east-1
65+
# - us-east-1
66+
# - us-east-2
67+
- us-west-1
68+
- us-west-2
69+
with:
70+
artifact-name: opentelemetry-python-layer.zip
71+
layer-name: opentelemetry-python
72+
component-version: ${{needs.build-layer.outputs.PYTHON_SDK_VERSION}}
73+
# architecture:
74+
release-group: dev
75+
aws_region: ${{ matrix.aws_region }}
76+
secrets: inherit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ terraform.*
1616
__pycache__/*
1717
.pyc
1818

19+
*.zip

python/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ Scripts and files used to build AWS Lambda Layers for running OpenTelemetry on A
1111
* [Docker](https://docs.docker.com/get-docker)
1212
3. Run aws configure to [set aws credential(with administrator permissions)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html#serverless-sam-cli-install-mac-iam-permissions) and default region.
1313
4. Download a local copy of this repository from Github.
14-
5. cd python/sample-apps && ./run.sh
14+
5. `cd python/sample-apps`
15+
6. If you just want to create a zip file with the OpenTelemetry Python AWS Lambda layer, then use the `-b true` option: `bash run.sh -n <LAYER_NAME_HERE> -b true`
16+
7. If you want to create the layer and automatically publish it, use no options: `bash run.sh`

python/sample-apps/run.sh

100644100755
File mode changed.

python/src/otel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ build-OTelLayer:
55
mkdir -p $(ARTIFACTS_DIR)/python
66
python3 -m pip install -r $(SDK)/requirements.txt -t $(ARTIFACTS_DIR)/python
77
python3 -m pip install -r $(SDK)/requirements-nodeps.txt -t $(ARTIFACTS_DIR)/tmp --no-deps
8+
python3 -m pip freeze --path $(ARTIFACTS_DIR)/python
89
cp -r $(ARTIFACTS_DIR)/tmp/* $(ARTIFACTS_DIR)/python/
910
rm -rf $(ARTIFACTS_DIR)/tmp
1011
cp -r $(SDK)/* $(ARTIFACTS_DIR)/python

utils/sam/run.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ main() {
3030
deploy=false
3131
layer=false
3232

33-
region=${AWS_REGION-$(aws configure get region)}
3433
stack=${OTEL_LAMBDA_STACK-"otel-stack"}
3534
layerName=${OTEL_LAMBDA_LAYER-"otel-layer"}
3635

@@ -75,6 +74,10 @@ main() {
7574
esac
7675
done
7776

77+
if [[ $deploy == true && $region == "" ]]; then
78+
region=${AWS_REGION-$(aws configure get region)}
79+
fi
80+
7881
echo "Invoked with: ${saved_args}"
7982

8083
if [[ $build == false && $deploy == false && $layer == false ]]; then
@@ -89,19 +92,20 @@ main() {
8992
echo "run.sh: building the collector..."
9093
pushd "$collectorPath"
9194
make package
92-
rm build/collector-extension-amd64.zip
95+
rm -f build/collector-extension-amd64.zip
9396
popd
9497
rm -rf otel/collector_build/
9598
cp -r "$collectorPath"/build/ otel/collector_build/
9699

97100
echo "run.sh: Starting sam build."
98101
sam build -u -t "$template"
102+
zip -qr "$layerName".zip .aws-sam/build
99103
fi
100104

101105
if [[ $deploy == true ]]; then
102106
sam deploy --stack-name "$stack" --region "$region" --capabilities CAPABILITY_NAMED_IAM --resolve-s3 --parameter-overrides LayerName="$layerName"
103107
rm -rf otel/otel_collector
104-
rm -rf .aws-sam
108+
rm -f "$layerName".zip
105109
fi
106110

107111
if [[ $layer == true ]]; then

0 commit comments

Comments
 (0)