Skip to content

Commit 04d14b2

Browse files
committed
Fix build script and Dockerfile so tests can be run locally
1 parent 735f9ad commit 04d14b2

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

contract-tests/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ The steps to add a new test for a library or framework are:
3232

3333
Pre-requirements:
3434
* Have `docker` installed and running - verify by running the `docker` command.
35-
* Copy the `aws_opentelemetry_distro` wheel file to each application folder under `images` (e.g. to `requests`, but not `mock-collector`)
35+
* Create `aws-otel-python-instrumentation/contract-tests/dist` folder
36+
* Copy the `aws_opentelemetry_distro` wheel file to `aws-otel-python-instrumentation/contract-tests/dist` folder
3637

3738
From `aws-otel-python-instrumentation/contract-tests` execute:
3839

contract-tests/images/applications/requests/Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# Meant to be run from aws-otel-python-instrumentation/contract-tests.
2+
# Assumes existence of dist/aws_opentelemetry_distro-<pkg_version>-py3-none-any.whl.
3+
# Assumes filename of aws_opentelemetry_distro-<pkg_version>-py3-none-any.whl is passed in as "DISTRO" arg.
14
FROM python:3.9-slim
25
WORKDIR /requests
3-
COPY . /requests
6+
COPY ./dist /requests
7+
COPY ./images/applications/requests /requests
48

5-
RUN pip install -r requirements.txt && pip install aws_opentelemetry_distro-0.0.1-py3-none-any.whl --force-reinstall
9+
ARG DISTRO
10+
RUN pip install -r requirements.txt && pip install ${DISTRO} --force-reinstall
611
RUN opentelemetry-bootstrap -a install
712

813
# Without `-u`, logs will be buffered and `wait_for_logs` will never return.

contract-tests/set-up-contract-tests.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
1+
#!/bin/bash
2+
# Check script is running in contract-tests
3+
current_path=`pwd`
4+
current_dir="${current_path##*/}"
5+
if [ "$current_dir" != "contract-tests" ]; then
6+
echo "Please run from contract-tests dir"
7+
exit
8+
fi
9+
10+
# Remove old whl files (excluding distro whl)
11+
rm -rf dist/mock_collector*
12+
rm -rf dist/contract_tests*
13+
14+
# Create mock-collector image
115
cd images/mock-collector
216
docker build . -t aws-appsignals-mock-collector-python
17+
cd ../..
18+
19+
# Find and store aws_opentelemetry_distro whl file
20+
cd dist
21+
DISTRO=(aws_opentelemetry_distro*.whl)
22+
if [ "$DISTRO" = "aws_opentelemetry_distro*.whl" ]; then
23+
echo "Could not find aws_opentelemetry_distro whl file in dist dir."
24+
exit 1
25+
fi
326
cd ..
427

5-
cd applications
6-
for dir in */
28+
# Create application images
29+
for dir in images/applications/*
730
do
8-
cd $dir
9-
docker build . -t aws-appsignals-tests-${dir%/}-app
10-
cd ..
31+
application="${dir##*/}"
32+
docker build . -t aws-appsignals-tests-${application}-app -f ${dir}/Dockerfile --build-arg="DISTRO=${DISTRO}"
1133
done
1234

13-
cd ../..
14-
15-
mkdir dist
16-
rm -rf dist/*
35+
# Build and install mock-collector
1736
cd images/mock-collector
1837
python3 -m build --outdir ../../dist --no-isolation
1938
cd ../../dist
20-
pip wheel --no-deps mock_collector-1.0.0.tar.gz
2139
pip install mock_collector-1.0.0-py3-none-any.whl --force-reinstall
2240

41+
# Build and install contract-tests
2342
cd ../tests
2443
python3 -m build --outdir ../dist --no-isolation
2544
cd ../dist
26-
pip wheel --no-deps contract_tests-1.0.0.tar.gz
2745
# --force-reinstall causes `ERROR: No matching distribution found for mock-collector==1.0.0`, but uninstalling and reinstalling works pretty reliably.
2846
pip uninstall contract-tests -y
2947
pip install contract_tests-1.0.0-py3-none-any.whl

0 commit comments

Comments
 (0)