Changeset View
Changeset View
Standalone View
Standalone View
tests/build_and_test_image.sh
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
#!/bin/bash | |||||
# Copyright (C) 2021-2022 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
DOCKER_IMAGE="softwareheritage/maven-index-exporter" | |||||
LOG=test_docker_image.log | |||||
# This script builds the docker image for maven-index-exporter, and | |||||
# executes it on a known set of indexes and checks the results in order | |||||
# to test the full tool chain. | |||||
echo "Script started on `date +%Y%m%d_%H%M%S`." | |||||
echo "* Writing log to $LOG." | |||||
# Find location of script directory | |||||
OLD_DIR=$(pwd) | |||||
REPO_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | |||||
cd $OLD_DIR | |||||
# First clean up and remove any docker image with our own name | |||||
docker rmi $DOCKER_IMAGE >>$LOG 2>&1 | |||||
RET=$? | |||||
if [[ $RET -eq 0 ]]; then | |||||
echo "* Docker image [$DOCKER_IMAGE] deleted." | |||||
elif [[ $RET -eq 1 ]]; then | |||||
echo "* Docker image [$DOCKER_IMAGE] doesn't exist." | |||||
else | |||||
echo "Error when deleting docker image [$DOCKER_IMAGE]." | |||||
fi | |||||
# Build the image and tag it as $DOCKER_IMAGE | |||||
cd $REPO_DIR/docker | |||||
echo "* Building docker image." | |||||
docker build . -t $DOCKER_IMAGE >>$LOG | |||||
RET=$? | |||||
if [[ $RET -eq 0 ]]; then | |||||
echo "PASS: docker build returned 0." | |||||
else | |||||
echo "FAIL: docker build returned $RET." | |||||
exit 20 | |||||
fi | |||||
# Assert docker image has been created. | |||||
COUNT=$(docker images | grep -E "^$DOCKER_IMAGE\s" | wc -l) | |||||
if [[ $COUNT -eq 0 ]]; then | |||||
echo "FAIL: Docker image cannot be listed." | |||||
exit 10 | |||||
else | |||||
echo "PASS: Docker image is listed." | |||||
fi | |||||
cd $OLD_DIR | |||||
./test_image.sh |