Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build new Lambda extension #1383

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 69 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: CI

on:
push:
Expand All @@ -9,54 +9,10 @@ on:
pull_request:

jobs:
dist:
name: distribution packages
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-python@v2
with:
python-version: 3.9

- run: |
pip install virtualenv
make aws-lambda-layer-build

- uses: actions/upload-artifact@v2
with:
name: ${{ github.sha }}
path: |
dist/*
dist-serverless/*

docs:
timeout-minutes: 10
name: build documentation
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-python@v2
with:
python-version: 3.9

- run: |
pip install virtualenv
make apidocs
cd docs/_build && zip -r gh-pages ./

- uses: actions/upload-artifact@v2
with:
name: ${{ github.sha }}
path: docs/_build/gh-pages.zip

lint:
timeout-minutes: 10
name: Lint Sources
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
Expand All @@ -69,9 +25,10 @@ jobs:
tox -e linters

test:
continue-on-error: true
timeout-minutes: 45
name: Run Tests
runs-on: ${{ matrix.linux-version }}
timeout-minutes: 45
continue-on-error: true
strategy:
matrix:
linux-version: [ubuntu-latest]
Expand Down Expand Up @@ -125,7 +82,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: setup
- name: Setup Test Env
env:
PGHOST: localhost
PGPASSWORD: sentry
Expand All @@ -134,7 +91,7 @@ jobs:
psql -c 'create database test_travis_ci_test;' -U postgres
pip install codecov tox

- name: run tests
- name: Run Tests
env:
CI_PYTHON_VERSION: ${{ matrix.python-version }}
timeout-minutes: 45
Expand All @@ -144,3 +101,64 @@ jobs:
coverage combine .coverage*
coverage xml -i
codecov --file coverage.xml

dist:
name: Build AWS Lambda Layer
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-python@v2
with:
python-version: 3.9

- run: |
echo "Creating directory containing Python SDK Lambda Layer"
pip install virtualenv
make aws-lambda-layer

echo "Saving SDK_VERSION for later"
export SDK_VERSION=$(grep "VERSION = " sentry_sdk/consts.py | cut -f3 -d' ' | tr -d '"')
echo "SDK_VERSION=$SDK_VERSION"
echo "SDK_VERSION=$SDK_VERSION" >> $GITHUB_ENV

- uses: actions/upload-artifact@v3
with:
name: ${{ github.sha }}
path: |
dist-serverless/*

- uses: getsentry/action-build-aws-lambda-extension@v1
with:
artifact_name: ${{ github.sha }}
zip_file_name: sentry-python-serverless-${{ env.SDK_VERSION }}.zip

- name: Upload Zip
uses: actions/upload-artifact@v3
with:
name: ${{ github.sha }}
path: sentry-python-serverless-${{ env.SDK_VERSION }}.zip

docs:
name: Build SDK API Doc
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-python@v2
with:
python-version: 3.9

- run: |
pip install virtualenv
make apidocs
cd docs/_build && zip -r gh-pages ./

- uses: actions/upload-artifact@v2
with:
name: ${{ github.sha }}
path: docs/_build/gh-pages.zip
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ help:
@echo "make test: Run basic tests (not testing most integrations)"
@echo "make test-all: Run ALL tests (slow, closest to CI)"
@echo "make format: Run code formatters (destructive)"
@echo "make aws-lambda-layer-build: Build serverless ZIP dist package"
@echo "make aws-lambda-layer: Build AWS Lambda layer directory for serverless integration"
@echo
@echo "Also make sure to read ./CONTRIBUTING.md"
@false
Expand All @@ -19,9 +19,8 @@ help:
$(VENV_PATH)/bin/pip install tox

dist: .venv
rm -rf dist build
rm -rf dist dist-serverless build
$(VENV_PATH)/bin/python setup.py sdist bdist_wheel

.PHONY: dist

format: .venv
Expand All @@ -46,7 +45,6 @@ lint: .venv
echo "Bad formatting? Run: make format"; \
echo "================================"; \
false)

.PHONY: lint

apidocs: .venv
Expand All @@ -60,8 +58,8 @@ apidocs-hotfix: apidocs
@$(VENV_PATH)/bin/ghp-import -pf docs/_build
.PHONY: apidocs-hotfix

aws-lambda-layer-build: dist
aws-lambda-layer: dist
$(VENV_PATH)/bin/pip install urllib3
$(VENV_PATH)/bin/pip install certifi
$(VENV_PATH)/bin/python -m scripts.build_awslambda_layer
.PHONY: aws-lambda-layer-build
$(VENV_PATH)/bin/python -m scripts.build_aws_lambda_layer
.PHONY: aws-lambda-layer
72 changes: 72 additions & 0 deletions scripts/build_aws_lambda_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import shutil
import subprocess
import tempfile

from sentry_sdk.consts import VERSION as SDK_VERSION

DIST_PATH = "dist" # created by "make dist" that is called by "make aws-lambda-layer"
PYTHON_SITE_PACKAGES = "python" # see https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path


class LayerBuilder:
def __init__(
self,
base_dir, # type: str
):
# type: (...) -> None
self.base_dir = base_dir
self.python_site_packages = os.path.join(self.base_dir, PYTHON_SITE_PACKAGES)

def make_directories(self):
# type: (...) -> None
os.makedirs(self.python_site_packages)

def install_python_packages(self):
# type: (...) -> None
sentry_python_sdk = os.path.join(
DIST_PATH,
f"sentry_sdk-{SDK_VERSION}-py2.py3-none-any.whl", # this is generated by "make dist" that is called by "make aws-lamber-layer"
)
subprocess.run(
[
"pip",
"install",
"--no-cache-dir", # always access PyPI
"--quiet",
sentry_python_sdk,
"--target",
self.python_site_packages,
],
check=True,
)

def create_init_serverless_sdk_package(self):
# type: (...) -> None
"""
Method that creates the init_serverless_sdk pkg in the
sentry-python-serverless zip
"""
serverless_sdk_path = (
f"{self.python_site_packages}/sentry_sdk/"
f"integrations/init_serverless_sdk"
)
if not os.path.exists(serverless_sdk_path):
os.makedirs(serverless_sdk_path)
shutil.copy(
"scripts/init_serverless_sdk.py", f"{serverless_sdk_path}/__init__.py"
)


def build_layer_dir():
with tempfile.TemporaryDirectory() as base_dir:
layer_builder = LayerBuilder(base_dir)
layer_builder.make_directories()
layer_builder.install_python_packages()
layer_builder.create_init_serverless_sdk_package()

shutil.copytree(base_dir, "dist-serverless")


if __name__ == "__main__":
build_layer_dir()
117 changes: 0 additions & 117 deletions scripts/build_awslambda_layer.py

This file was deleted.

Loading