1+ version : 0.2
2+
3+ env :
4+ variables :
5+ OS_DISTRIBUTION : debian
6+ NPX_BINARY_LOCATION : " /usr/local/bin/npx"
7+ batch :
8+ build-matrix :
9+ static :
10+ ignore-failure : false
11+ env :
12+ privileged-mode : true
13+ dynamic :
14+ env :
15+ variables :
16+ DISTRO_VERSION :
17+ - " bookworm"
18+ RUNTIME_VERSION :
19+ - " 16"
20+ - " 18"
21+ phases :
22+ pre_build :
23+ commands :
24+ - export IMAGE_TAG="nodejs-${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 test/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}"
39+ - >
40+ cp "test/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+ - >
54+ echo "RUN apt-get update && apt-get install -y curl" >> \
55+ "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp"
56+ - echo "Building image ${IMAGE_TAG}"
57+ - >
58+ docker build . \
59+ -f "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" \
60+ -t "${IMAGE_TAG}" \
61+ --build-arg RUNTIME_VERSION="${RUNTIME_VERSION}" \
62+ --build-arg DISTRO_VERSION="${DISTRO_VERSION}"
63+ build :
64+ commands :
65+ - set -x
66+ - echo "Running Image ${IMAGE_TAG}"
67+ - docker network create "${OS_DISTRIBUTION}-network"
68+ - >
69+ docker run \
70+ --detach \
71+ --name "${OS_DISTRIBUTION}-app" \
72+ --network "${OS_DISTRIBUTION}-network" \
73+ --entrypoint="" \
74+ "${IMAGE_TAG}" \
75+ sh -c "/usr/bin/${RIE} ${NPX_BINARY_LOCATION} aws-lambda-ric index.handler"
76+ - sleep 2
77+ - >
78+ docker run \
79+ --name "${OS_DISTRIBUTION}-tester" \
80+ --env "TARGET=${OS_DISTRIBUTION}-app" \
81+ --network "${OS_DISTRIBUTION}-network" \
82+ --entrypoint="" \
83+ "${IMAGE_TAG}" \
84+ sh -c 'curl -X POST "http://${TARGET}:8080/2015-03-31/functions/function/invocations" -d "{}" --max-time 10'
85+ - actual="$(docker logs --tail 1 "${OS_DISTRIBUTION}-tester" | xargs)"
86+ - expected='success'
87+ - |
88+ echo "Response: ${actual}"
89+ if [[ "$actual" != "$expected" ]]; then
90+ echo "fail! runtime: $RUNTIME - expected output $expected - got $actual"
91+ exit -1
92+ fi
93+ finally :
94+ - |
95+ echo "---------Container Logs: ${OS_DISTRIBUTION}-app----------"
96+ echo
97+ docker logs "${OS_DISTRIBUTION}-app" || true
98+ echo
99+ echo "---------------------------------------------------"
100+ echo "--------Container Logs: ${OS_DISTRIBUTION}-tester--------"
101+ echo
102+ docker logs "${OS_DISTRIBUTION}-tester" || true
103+ echo
104+ echo "---------------------------------------------------"
105+ - echo "Cleaning up..."
106+ - docker stop "${OS_DISTRIBUTION}-app" || true
107+ - docker rm --force "${OS_DISTRIBUTION}-app" || true
108+ - docker stop "${OS_DISTRIBUTION}-tester" || true
109+ - docker rm --force "${OS_DISTRIBUTION}-tester" || true
110+ - docker network rm "${OS_DISTRIBUTION}-network" || true
0 commit comments