Skip to content

Commit e3e5dc5

Browse files
committed
Run integration tests for every distro on PR
1 parent 53a2c87 commit e3e5dc5

File tree

7 files changed

+124
-13
lines changed

7 files changed

+124
-13
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target:
55

66
.PHONY: init
77
init:
8-
pip3 install -r requirements/base.txt -r requirements/dev.txt
8+
pip3 install -r requirements/base.txt -r requirements/dev.txt --use-pep517
99

1010
.PHONY: test
1111
test: check-format
@@ -21,7 +21,7 @@ test-smoke: setup-codebuild-agent
2121

2222
.PHONY: test-integ
2323
test-integ: setup-codebuild-agent
24-
CODEBUILD_IMAGE_TAG=codebuild-agent tests/integration/codebuild-local/test_all.sh tests/integration/codebuild/.
24+
CODEBUILD_IMAGE_TAG=codebuild-agent DISTRO="$(DISTRO)" tests/integration/codebuild-local/test_all.sh tests/integration/codebuild
2525

2626
.PHONY: check-security
2727
check-security:

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from setuptools import Extension, find_packages, setup
1010
from awslambdaric import __version__
1111

12-
1312
def get_curl_extra_linker_flags():
1413
# We do not want to build the dependencies during packaging
1514
if platform.system() != "Linux" or os.getenv("BUILD") == "true":

tests/integration/codebuild-local/test_all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ main() {
5454

5555
BUILDSPEC_YML_DIR="$1"
5656
HAS_YML=0
57-
for f in "$BUILDSPEC_YML_DIR"/*.yml ; do
57+
for f in "$BUILDSPEC_YML_DIR"/*"$DISTRO"*.yml ; do
5858
[ -f "$f" ] || continue;
5959
do_one_yaml "$f"
6060
HAS_YML=1

tests/integration/codebuild/buildspec.os.amazonlinux.1.yml

-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ batch:
1818
- "1"
1919
RUNTIME_VERSION:
2020
- "3.7"
21-
- "3.8"
22-
- "3.9"
23-
- "3.10"
24-
- "3.11"
25-
- "3.12"
2621
phases:
2722
pre_build:
2823
commands:

tests/integration/codebuild/buildspec.os.amazonlinux.2.yml

-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ batch:
1717
DISTRO_VERSION:
1818
- "2"
1919
RUNTIME_VERSION:
20-
- "3.7"
2120
- "3.8"
2221
- "3.9"
2322
- "3.10"
2423
- "3.11"
25-
- "3.12"
2624
phases:
2725
pre_build:
2826
commands:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
version: 0.2
2+
3+
env:
4+
variables:
5+
OS_DISTRIBUTION: amazonlinux
6+
PYTHON_LOCATION: "/usr/local/bin/python3"
7+
TEST_NAME: "aws-lambda-python-rtc-amazonlinux-test"
8+
batch:
9+
build-matrix:
10+
static:
11+
ignore-failure: false
12+
env:
13+
privileged-mode: true
14+
dynamic:
15+
env:
16+
variables:
17+
DISTRO_VERSION:
18+
- "2023"
19+
RUNTIME_VERSION:
20+
- "3.12"
21+
phases:
22+
pre_build:
23+
commands:
24+
- export IMAGE_TAG="python-${OS_DISTRIBUTION}-${DISTRO_VERSION}:${RUNTIME_VERSION}"
25+
- echo "Extracting and including the Runtime Interface Emulator"
26+
- SCRATCH_DIR=".scratch"
27+
- mkdir "${SCRATCH_DIR}"
28+
- ARCHITECTURE=$(arch)
29+
- >
30+
if [[ "$ARCHITECTURE" == "x86_64" ]]; then
31+
RIE="aws-lambda-rie"
32+
elif [[ "$ARCHITECTURE" == "aarch64" ]]; then
33+
RIE="aws-lambda-rie-arm64"
34+
else
35+
echo "Architecture $ARCHITECTURE is not currently supported."
36+
exit 1
37+
fi
38+
- tar -xvf tests/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}"
39+
- >
40+
cp "tests/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \
41+
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
42+
- >
43+
echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \
44+
"${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
45+
- >
46+
if [[ -z "${DOCKERHUB_USERNAME}" && -z "${DOCKERHUB_PASSWORD}" ]];
47+
then
48+
echo "DockerHub credentials not set as CodeBuild environment variables. Continuing without docker login."
49+
else
50+
echo "Performing DockerHub login . . ."
51+
docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
52+
fi
53+
- echo "Building image ${IMAGE_TAG}"
54+
- >
55+
docker build . \
56+
-f "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" \
57+
-t "${IMAGE_TAG}" \
58+
--build-arg RUNTIME_VERSION="${RUNTIME_VERSION}" \
59+
--build-arg DISTRO_VERSION="${DISTRO_VERSION}" \
60+
--build-arg ARCHITECTURE="${ARCHITECTURE}"
61+
build:
62+
commands:
63+
- set -x
64+
- echo "Running Image ${IMAGE_TAG}"
65+
- docker network create "${TEST_NAME}-network"
66+
- >
67+
docker run \
68+
--detach \
69+
--name "${TEST_NAME}-app" \
70+
--network "${TEST_NAME}-network" \
71+
--entrypoint="" \
72+
"${IMAGE_TAG}" \
73+
sh -c "/usr/bin/${RIE} ${PYTHON_LOCATION} -m awslambdaric app.handler"
74+
- sleep 2
75+
- >
76+
docker run \
77+
--name "${TEST_NAME}-tester" \
78+
--env "TARGET=${TEST_NAME}-app" \
79+
--network "${TEST_NAME}-network" \
80+
--entrypoint="" \
81+
"${IMAGE_TAG}" \
82+
sh -c 'curl -X POST "http://${TARGET}:8080/2015-03-31/functions/function/invocations" -d "{}" --max-time 10'
83+
- actual="$(docker logs --tail 1 "${TEST_NAME}-tester" | xargs)"
84+
- expected='success'
85+
- |
86+
echo "Response: ${actual}"
87+
if [[ "$actual" != "$expected" ]]; then
88+
echo "fail! runtime: $RUNTIME - expected output $expected - got $actual"
89+
exit -1
90+
fi
91+
finally:
92+
- |
93+
echo "---------Container Logs: ${TEST_NAME}-app----------"
94+
echo
95+
docker logs "${TEST_NAME}-app" || true
96+
echo
97+
echo "---------------------------------------------------"
98+
echo "--------Container Logs: ${TEST_NAME}-tester--------"
99+
echo
100+
docker logs "${TEST_NAME}-tester" || true
101+
echo
102+
echo "---------------------------------------------------"
103+
- echo "Cleaning up..."
104+
- docker stop "${TEST_NAME}-app" || true
105+
- docker rm --force "${TEST_NAME}-app" || true
106+
- docker stop "${TEST_NAME}-tester" || true
107+
- docker rm --force "${TEST_NAME}-tester" || true
108+
- docker network rm "${TEST_NAME}-network" || true

tests/integration/docker/Dockerfile.echo.amazonlinux

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ RUN yum install -y \
2020
openssl-devel \
2121
wget \
2222
libffi-devel \
23+
python3-setuptools \
2324
sqlite-devel
2425

26+
# Python3.10+ requires openssl1.1.1+
27+
RUN if [[ "${DISTRO_VERSION}" == "2" ]]; then \
28+
yum install -y openssl11-devel openssl11 ; \
29+
else \
30+
yum install -y openssl-devel openssl ; \
31+
fi
32+
2533
RUN RUNTIME_LATEST_VERSION=${RUNTIME_VERSION}.$(curl -s https://www.python.org/ftp/python/ | \
2634
grep -oE "href=\"$(echo ${RUNTIME_VERSION} | sed "s/\\./\\\./g")\.[0-9]+" | \
2735
cut -d. -f3 | \
@@ -32,8 +40,8 @@ RUN RUNTIME_LATEST_VERSION=${RUNTIME_VERSION}.$(curl -s https://www.python.org/f
3240
done) \
3341
&& tar -xzf Python-${RUNTIME_LATEST_VERSION}.tgz \
3442
&& cd Python-${RUNTIME_LATEST_VERSION} \
35-
&& ./configure --prefix=/usr/local --enable-shared \
36-
&& make \
43+
&& ./configure --prefix=/usr/local --enable-shared --with-openssl=/usr/ \
44+
&& make -j $(nproc) \
3745
&& make install \
3846
&& ln -s /usr/local/bin/python${RUNTIME_VERSION} /usr/local/bin/python${RUNTIME_LATEST_VERSION}
3947

@@ -78,6 +86,9 @@ RUN mkdir -p ${RIC_BUILD_DIR}
7886
# Copy function code and Runtime Interface Client .tgz
7987
WORKDIR ${RIC_BUILD_DIR}
8088
COPY . .
89+
RUN if [[ "${RUNTIME_VERSION}" == "3.12" ]]; then \
90+
python${RUNTIME_VERSION} -m pip install setuptools ; \
91+
fi
8192
RUN make init build test && \
8293
mv ./dist/awslambdaric-*.tar.gz ./dist/awslambdaric-test.tar.gz
8394

0 commit comments

Comments
 (0)