diff --git a/Makefile b/Makefile index ab2ba46..361923d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ target: .PHONY: init init: - pip3 install -r requirements/base.txt -r requirements/dev.txt + pip3 install -r requirements/base.txt -r requirements/dev.txt --use-pep517 .PHONY: test test: check-format @@ -21,7 +21,7 @@ test-smoke: setup-codebuild-agent .PHONY: test-integ test-integ: setup-codebuild-agent - CODEBUILD_IMAGE_TAG=codebuild-agent tests/integration/codebuild-local/test_all.sh tests/integration/codebuild/. + CODEBUILD_IMAGE_TAG=codebuild-agent DISTRO="$(DISTRO)" tests/integration/codebuild-local/test_all.sh tests/integration/codebuild .PHONY: check-security check-security: diff --git a/README.md b/README.md index 248fde4..50333c6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The Python Runtime Interface Client package currently supports Python versions: ### Creating a Docker Image for Lambda with the Runtime Interface Client First step is to choose the base image to be used. The supported Linux OS distributions are: - - Amazon Linux 2 + - Amazon Linux (2 and 2023) - Alpine - CentOS - Debian diff --git a/setup.py b/setup.py index 2544b21..10bd228 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,6 @@ from setuptools import Extension, find_packages, setup from awslambdaric import __version__ - def get_curl_extra_linker_flags(): # We do not want to build the dependencies during packaging if platform.system() != "Linux" or os.getenv("BUILD") == "true": diff --git a/tests/integration/codebuild-local/test_all.sh b/tests/integration/codebuild-local/test_all.sh index 0c5168c..72760ef 100755 --- a/tests/integration/codebuild-local/test_all.sh +++ b/tests/integration/codebuild-local/test_all.sh @@ -54,7 +54,7 @@ main() { BUILDSPEC_YML_DIR="$1" HAS_YML=0 - for f in "$BUILDSPEC_YML_DIR"/*.yml ; do + for f in "$BUILDSPEC_YML_DIR"/*"$DISTRO"*.yml ; do [ -f "$f" ] || continue; do_one_yaml "$f" HAS_YML=1 diff --git a/tests/integration/codebuild/buildspec.os.amazonlinux.1.yml b/tests/integration/codebuild/buildspec.os.amazonlinux.1.yml index 91bb021..1e59885 100644 --- a/tests/integration/codebuild/buildspec.os.amazonlinux.1.yml +++ b/tests/integration/codebuild/buildspec.os.amazonlinux.1.yml @@ -18,11 +18,6 @@ batch: - "1" RUNTIME_VERSION: - "3.7" - - "3.8" - - "3.9" - - "3.10" - - "3.11" - - "3.12" phases: pre_build: commands: diff --git a/tests/integration/codebuild/buildspec.os.amazonlinux.2.yml b/tests/integration/codebuild/buildspec.os.amazonlinux.2.yml index 38f2509..0555005 100644 --- a/tests/integration/codebuild/buildspec.os.amazonlinux.2.yml +++ b/tests/integration/codebuild/buildspec.os.amazonlinux.2.yml @@ -17,12 +17,10 @@ batch: DISTRO_VERSION: - "2" RUNTIME_VERSION: - - "3.7" - "3.8" - "3.9" - "3.10" - "3.11" - - "3.12" phases: pre_build: commands: diff --git a/tests/integration/codebuild/buildspec.os.amazonlinux.2023.yml b/tests/integration/codebuild/buildspec.os.amazonlinux.2023.yml new file mode 100644 index 0000000..0a30d44 --- /dev/null +++ b/tests/integration/codebuild/buildspec.os.amazonlinux.2023.yml @@ -0,0 +1,108 @@ +version: 0.2 + +env: + variables: + OS_DISTRIBUTION: amazonlinux + PYTHON_LOCATION: "/usr/local/bin/python3" + TEST_NAME: "aws-lambda-python-rtc-amazonlinux-test" +batch: + build-matrix: + static: + ignore-failure: false + env: + privileged-mode: true + dynamic: + env: + variables: + DISTRO_VERSION: + - "2023" + RUNTIME_VERSION: + - "3.12" +phases: + pre_build: + commands: + - export IMAGE_TAG="python-${OS_DISTRIBUTION}-${DISTRO_VERSION}:${RUNTIME_VERSION}" + - echo "Extracting and including the Runtime Interface Emulator" + - SCRATCH_DIR=".scratch" + - mkdir "${SCRATCH_DIR}" + - ARCHITECTURE=$(arch) + - > + if [[ "$ARCHITECTURE" == "x86_64" ]]; then + RIE="aws-lambda-rie" + elif [[ "$ARCHITECTURE" == "aarch64" ]]; then + RIE="aws-lambda-rie-arm64" + else + echo "Architecture $ARCHITECTURE is not currently supported." + exit 1 + fi + - tar -xvf tests/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}" + - > + cp "tests/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \ + "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" + - > + echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \ + "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" + - > + if [[ -z "${DOCKERHUB_USERNAME}" && -z "${DOCKERHUB_PASSWORD}" ]]; + then + echo "DockerHub credentials not set as CodeBuild environment variables. Continuing without docker login." + else + echo "Performing DockerHub login . . ." + docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD + fi + - echo "Building image ${IMAGE_TAG}" + - > + docker build . \ + -f "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" \ + -t "${IMAGE_TAG}" \ + --build-arg RUNTIME_VERSION="${RUNTIME_VERSION}" \ + --build-arg DISTRO_VERSION="${DISTRO_VERSION}" \ + --build-arg ARCHITECTURE="${ARCHITECTURE}" + build: + commands: + - set -x + - echo "Running Image ${IMAGE_TAG}" + - docker network create "${TEST_NAME}-network" + - > + docker run \ + --detach \ + --name "${TEST_NAME}-app" \ + --network "${TEST_NAME}-network" \ + --entrypoint="" \ + "${IMAGE_TAG}" \ + sh -c "/usr/bin/${RIE} ${PYTHON_LOCATION} -m awslambdaric app.handler" + - sleep 2 + - > + docker run \ + --name "${TEST_NAME}-tester" \ + --env "TARGET=${TEST_NAME}-app" \ + --network "${TEST_NAME}-network" \ + --entrypoint="" \ + "${IMAGE_TAG}" \ + sh -c 'curl -X POST "http://${TARGET}:8080/2015-03-31/functions/function/invocations" -d "{}" --max-time 10' + - actual="$(docker logs --tail 1 "${TEST_NAME}-tester" | xargs)" + - expected='success' + - | + echo "Response: ${actual}" + if [[ "$actual" != "$expected" ]]; then + echo "fail! runtime: $RUNTIME - expected output $expected - got $actual" + exit -1 + fi + finally: + - | + echo "---------Container Logs: ${TEST_NAME}-app----------" + echo + docker logs "${TEST_NAME}-app" || true + echo + echo "---------------------------------------------------" + echo "--------Container Logs: ${TEST_NAME}-tester--------" + echo + docker logs "${TEST_NAME}-tester" || true + echo + echo "---------------------------------------------------" + - echo "Cleaning up..." + - docker stop "${TEST_NAME}-app" || true + - docker rm --force "${TEST_NAME}-app" || true + - docker stop "${TEST_NAME}-tester" || true + - docker rm --force "${TEST_NAME}-tester" || true + - docker network rm "${TEST_NAME}-network" || true diff --git a/tests/integration/docker/Dockerfile.echo.amazonlinux b/tests/integration/docker/Dockerfile.echo.amazonlinux index 188de01..88fa781 100644 --- a/tests/integration/docker/Dockerfile.echo.amazonlinux +++ b/tests/integration/docker/Dockerfile.echo.amazonlinux @@ -20,8 +20,16 @@ RUN yum install -y \ openssl-devel \ wget \ libffi-devel \ + python3-setuptools \ sqlite-devel +# Python3.10+ requires openssl1.1.1+ +RUN if [[ "${DISTRO_VERSION}" == "2" ]]; then \ + yum install -y openssl11-devel openssl11 ; \ +else \ + yum install -y openssl-devel openssl ; \ +fi + RUN RUNTIME_LATEST_VERSION=${RUNTIME_VERSION}.$(curl -s https://www.python.org/ftp/python/ | \ grep -oE "href=\"$(echo ${RUNTIME_VERSION} | sed "s/\\./\\\./g")\.[0-9]+" | \ cut -d. -f3 | \ @@ -32,8 +40,8 @@ RUN RUNTIME_LATEST_VERSION=${RUNTIME_VERSION}.$(curl -s https://www.python.org/f done) \ && tar -xzf Python-${RUNTIME_LATEST_VERSION}.tgz \ && cd Python-${RUNTIME_LATEST_VERSION} \ - && ./configure --prefix=/usr/local --enable-shared \ - && make \ + && ./configure --prefix=/usr/local --enable-shared --with-openssl=/usr/ \ + && make -j $(nproc) \ && make install \ && ln -s /usr/local/bin/python${RUNTIME_VERSION} /usr/local/bin/python${RUNTIME_LATEST_VERSION} @@ -78,6 +86,9 @@ RUN mkdir -p ${RIC_BUILD_DIR} # Copy function code and Runtime Interface Client .tgz WORKDIR ${RIC_BUILD_DIR} COPY . . +RUN if [[ "${RUNTIME_VERSION}" == "3.12" ]]; then \ + python${RUNTIME_VERSION} -m pip install setuptools ; \ +fi RUN make init build test && \ mv ./dist/awslambdaric-*.tar.gz ./dist/awslambdaric-test.tar.gz