diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fd584cc --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +VOLUME=maven_index_exporter +PUBLISH_DIR=/tmp/maven_index_exporter +# should be provided by the ci build +TAG=latest +IMAGE_NAME=softwareheritage/maven-index-exporter:$(TAG) +# ci build should provide the right label +IMAGE_LABEL=dummy +# can be overriden by ci +REGISTRY_URL=registry-1.docker.io + +build: + docker build \ + --tag $(IMAGE_NAME) \ + -f docker/Dockerfile \ + --label $(IMAGE_LABEL) \ + docker + +prepare: + docker volume create $(VOLUME) + mkdir -p /tmp/maven_index_exporter + +run: prepare + docker run \ + -v $(VOLUME):/work \ + -v $(PUBLISH_DIR):/publish \ + $(IMAGE_NAME) + +test: + ./tests/test_image.sh $(IMAGE_NAME) + +clean: + docker image ls -q --filter label=$(IMAGE_LABEL) \ + | uniq | xargs -r -t docker rmi --force + +# This will only work through the ci +push: + docker tag $(IMAGE_NAME) $(REGISTRY_URL)/$(IMAGE_NAME) + docker push $(REGISTRY_URL)/$(IMAGE_NAME) diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 88ce33e..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -build-and-test: - ./build_and_test_image.sh - -test: - ./test_image.sh diff --git a/tests/build_and_test_image.sh b/tests/build_and_test_image.sh deleted file mode 100755 index 19bdb54..0000000 --- a/tests/build_and_test_image.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/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 diff --git a/tests/test_image.sh b/tests/test_image.sh index 47065ac..37570c5 100755 --- a/tests/test_image.sh +++ b/tests/test_image.sh @@ -1,96 +1,105 @@ #!/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" +DOCKER_IMAGE=${1-"softwareheritage/maven-index-exporter"} LOG=test_docker_image.log REPO_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) WORK_DIR=$REPO_DIR/tests/repository_test EXPORT_DIR=$WORK_DIR/export PUBLISH_DIR=$REPO_DIR/tests/publish # clean up publish directory rm -rf $PUBLISH_DIR/* mkdir -p $PUBLISH_DIR # This will mock out the download part of the python code export MVN_IDX_EXPORTER_BASE_URL='test://example.org' # Run the image on the maven indexes. docker run -v $WORK_DIR:/work \ -v $PUBLISH_DIR:/publish \ -e MVN_IDX_EXPORTER_BASE_URL \ $DOCKER_IMAGE >>$LOG 2>&1 # Assert exported text files are there, with the correct content. EXPORT_FILE=$(ls $EXPORT_DIR/*.fld) if [[ -e $EXPORT_FILE ]]; then echo "PASS: file [$EXPORT_FILE] has been created." else echo "FAIL: file [$EXPORT_FILE] has NOT been created." exit 20 fi DOCS=$(grep -E "^doc" $EXPORT_FILE | wc -l) if [[ $DOCS -eq 10 ]]; then echo "PASS: file [$EXPORT_FILE] has 10 docs." else echo "FAIL: file [$EXPORT_FILE] has $DOCS docs, should be 10." exit 20 fi FIELDS=$(grep -E "^ field" $EXPORT_FILE | wc -l) if [[ $FIELDS -eq 35 ]]; then echo "PASS: file [$EXPORT_FILE] has 35 fields." else echo "FAIL: file [$EXPORT_FILE] has $FIELDS fields, should be 35." exit 20 fi FIELDS=$(grep "value al.aldi|sprova4j|0.1.0|sources|jar" $EXPORT_FILE | wc -l) if [[ $FIELDS -eq 1 ]]; then echo "PASS: file [$EXPORT_FILE] has sprova4j-0.1.0-sources.jar." else echo "FAIL: file [$EXPORT_FILE] has NOT sprova4j-0.1.0-sources.jar." exit 20 fi FIELDS=$(grep "value al.aldi|sprova4j|0.1.0|NA|pom" $EXPORT_FILE | wc -l) if [[ $FIELDS -eq 1 ]]; then echo "PASS: file [$EXPORT_FILE] has sprova4j-0.1.0.pom." else echo "FAIL: file [$EXPORT_FILE] has NOT sprova4j-0.1.0.pom." exit 20 fi FIELDS=$(grep "value al.aldi|sprova4j|0.1.1|sources|jar" $EXPORT_FILE | wc -l) if [[ $FIELDS -eq 1 ]]; then echo "PASS: file [$EXPORT_FILE] has sprova4j-0.1.1-sources.jar." else echo "FAIL: file [$EXPORT_FILE] has NOT sprova4j-0.1.1-sources.jar." exit 20 fi FIELDS=$(grep "value al.aldi|sprova4j|0.1.1|NA|pom" $EXPORT_FILE | wc -l) if [[ $FIELDS -eq 1 ]]; then echo "PASS: file [$EXPORT_FILE] has sprova4j-0.1.1.pom." else echo "FAIL: file [$EXPORT_FILE] has NOT sprova4j-0.1.1.pom." exit 20 fi +LOCK_FILE=$EXPORT_DIR/write.lock +if [[ ! -f $LOCK_FILE ]]; then + echo "PASS: lock file [$LOCK_FILE] cleaned up." +else + echo "FAIL: lock file [$LOCK_FILE] still present." + exit 20 +fi + + PUBLISH_FILE=$PUBLISH_DIR/export.fld if [[ -f $PUBLISH_FILE ]]; then echo "PASS: file [$PUBLISH_FILE] exists." else echo "FAIL: file [$PUBLISH_FILE] does not exist." exit 20 fi # Cleanup rm -rf $EXPORT_DIR cd $OLD_DIR