Skip to content

Commit

Permalink
Fix tests (#302)
Browse files Browse the repository at this point in the history
Cherry-pick:
- [Replace docker-compose with plugin if
available](178c5ae)
- [support docker compose
v2](1d98818)

---------

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
Signed-off-by: Bob Callaway <bcallaway@google.com>
Co-authored-by: Colleen Murphy <cmurphy@users.noreply.github.com>
Co-authored-by: Bob Callaway <bcallaway@google.com>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 12d7b79 commit 1cbf3a5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
run: sudo add-apt-repository ppa:savoury1/minisign && sudo apt-get update && sudo apt-get install minisign
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Docker Build
run: docker-compose build
run: docker compose build
- name: Extract version of Go to use
run: echo "GOVERSION=$(cat Dockerfile|grep golang | awk ' { print $2 } ' | cut -d '@' -f 1 | cut -d ':' -f 2 | uniq)" >> $GITHUB_ENV
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
Expand All @@ -139,7 +139,7 @@ jobs:
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Docker Build
run: docker-compose build
run: docker compose build
- name: Extract version of Go to use
run: echo "GOVERSION=$(cat Dockerfile|grep golang | awk ' { print $2 } ' | cut -d '@' -f 1 | cut -d ':' -f 2 | uniq)" >> $GITHUB_ENV
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
Expand Down
35 changes: 20 additions & 15 deletions tests/issue-872-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
set -e
testdir=$(dirname "$0")

docker_compose="docker compose"
if ! ${docker_compose} version >/dev/null 2>&1; then
docker_compose="docker-compose"
fi

echo "* starting services"
docker-compose up -d
${docker_compose} up -d

echo "* building CLI"
go build -o rekor-cli ./cmd/rekor-cli
Expand Down Expand Up @@ -50,7 +55,7 @@ trap "rm -rf $REKORTMPDIR" EXIT
waitForRekorServer

echo "* stopping rekor to test issue #872"
docker-compose stop rekor-server
${docker_compose} stop rekor-server

docker volume rm -f issue872_attestations || true
ATT_VOLUME=$(docker volume create --name issue872_attestations)
Expand Down Expand Up @@ -90,7 +95,7 @@ volumes:
EOF

echo "* starting rekor v0.6.0 to test issue #872"
docker-compose -f $V060_COMPOSE_FILE --project-directory=$PWD up -d rekor-server-issue-872-v060
${docker_compose} -f $V060_COMPOSE_FILE --project-directory=$PWD up -d rekor-server-issue-872-v060
sleep 5

# this rekor-cli image is based on v0.6.0 and has the fix for issue #800
Expand All @@ -104,8 +109,8 @@ V060_UPLOAD_OUTPUT=$REKORTMPDIR/issue-872-upload-output
echo "* inserting intoto entry into Rekor v0.6.0"
if ! $ISSUE800_CLI upload --type intoto --artifact tests/intoto_dsse.json --public-key tests/intoto_dsse.pem --format=json --rekor_server=http://localhost:3000 > $V060_UPLOAD_OUTPUT; then
echo "* failed to insert intoto entry to test issue #872, exiting"
docker-compose logs --no-color > /tmp/docker-compose.log
docker-compose -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
${docker_compose} -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
exit 1
fi

Expand All @@ -114,8 +119,8 @@ V060_GET_OUTPUT=$REKORTMPDIR/issue-872-get-output
echo "* read back entry from Rekor v0.6.0"
if ! $ISSUE800_CLI get --log-index=$ISSUE872_UPLOAD_INDEX --format=json --rekor_server=http://localhost:3000 > $V060_GET_OUTPUT; then
echo "* failed to retrieve entry from rekor v0.6.0 to test issue #872, exiting"
docker-compose logs --no-color > /tmp/docker-compose.log
docker-compose -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
${docker_compose} -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
exit 1
fi

Expand All @@ -124,16 +129,16 @@ V060_ATT_LENGTH=$(jq -r '.Attestation | length' $V060_GET_OUTPUT)
if [ $V060_ATT_LENGTH -eq 0 ]; then
echo "* failed to read back attestation while testing issue #872 against rekor v0.6.0, exiting"
cat $V060_GET_OUTPUT
docker-compose logs --no-color > /tmp/docker-compose.log
docker-compose -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
${docker_compose} -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
exit 1
fi

echo "* grabbing TreeID to use when starting older version"
REKOR_TRILLIAN_LOG_SERVER_TLOG_ID=$($ISSUE800_CLI loginfo --rekor_server=http://localhost:3000 --format=json | jq -r .TreeID)
echo "* stopping rekor v0.6.0 to test issue #872"
docker-compose -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
docker-compose -f $V060_COMPOSE_FILE --project-directory=$PWD stop rekor-server-issue-872-v060
${docker_compose} -f $V060_COMPOSE_FILE --project-directory=$PWD logs rekor-server-issue-872-v060 > /tmp/post-insert-docker-compose.log
${docker_compose} -f $V060_COMPOSE_FILE --project-directory=$PWD stop rekor-server-issue-872-v060

COMPOSE_FILE=$REKORTMPDIR/docker-compose-issue872.yaml
cat << EOF > $COMPOSE_FILE
Expand Down Expand Up @@ -177,14 +182,14 @@ EOF

docker network prune -f
echo "* starting rekor under test to ensure attestation inserted in old version is successfully returned"
docker-compose -f $COMPOSE_FILE --project-directory=$PWD up -d
${docker_compose} -f $COMPOSE_FILE --project-directory=$PWD up -d
waitForRekorServer

ISSUE872_GET_ENTRY=$REKORTMPDIR/issue-872-get-entry
echo "* fetching previous entry made under v0.6.0"
if ! $REKOR_CLI get --log-index=$ISSUE872_UPLOAD_INDEX --rekor_server=http://localhost:3000 --format=json > $ISSUE872_GET_ENTRY; then
echo "* failed to read back intoto entry while testing issue #872, exiting"
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi

Expand All @@ -194,8 +199,8 @@ ATT_LENGTH=$(jq -r '.Attestation | length' $ISSUE872_GET_ENTRY)
if [ $ATT_LENGTH -eq 0 ]; then
echo "* failed to read back attestation while testing issue #872, exiting"
cat $ISSUE872_GET_ENTRY
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
else
echo "* tests succeeded!"
fi
fi
23 changes: 14 additions & 9 deletions tests/rekor-harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ set -e

TREE_ID=""

docker_compose="docker compose"
if ! ${docker_compose} version >/dev/null 2>&1; then
docker_compose="docker-compose"
fi

function start_server () {
server_version=$1
current_branch=$(git rev-parse --abbrev-ref HEAD)
git checkout $server_version
if [ $(docker-compose ps | grep -c "(healthy)") == 0 ]; then
if [ $(${docker_compose} ps | grep -c "(healthy)") == 0 ]; then
echo "starting services with version $server_version"
docker-compose up -d --build
${docker_compose} up -d --build
sleep 30
make rekor-cli
export TREE_ID=$(./rekor-cli loginfo --format json --rekor_server http://localhost:3000 --store_tree_state=false | jq -r .TreeID)
Expand All @@ -36,17 +41,17 @@ function start_server () {
replace="\"--trillian_log_server.tlog_id=$TREE_ID\","
sed -i "s/$search/$replace/" docker-compose.yml

docker-compose up -d --build rekor-server
${docker_compose} up -d --build rekor-server
fi

count=0
echo -n "waiting up to 60 sec for system to start"
until [ $(docker-compose ps | grep -c "(healthy)") == 3 ];
until [ $(${docker_compose} ps | grep -c "(healthy)") == 3 ];
do
if [ $count -eq 6 ]; then
echo "! timeout reached"
cat docker-compose.yml
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
else
echo -n "."
Expand Down Expand Up @@ -76,13 +81,13 @@ function run_tests () {

go clean -testcache
if ! REKORTMPDIR=$REKORTMPDIR SERVER_VERSION=$1 CLI_VERSION=$2 go test -run TestHarness -v -tags=e2e ./tests/ ; then
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi
if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then
if ${docker_compose} logs --no-color | grep -q "panic: runtime error:" ; then
# if we're here, we found a panic
echo "Failing due to panics detected in logs"
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi
}
Expand All @@ -102,7 +107,7 @@ VERSIONS="$VERSIONS $HEAD"
echo $VERSIONS

export REKOR_HARNESS_TMPDIR="$(mktemp -d -t rekor_test_harness.XXXXXX)"
docker-compose down
${docker_compose} down

for server_version in $VERSIONS
do
Expand Down
17 changes: 11 additions & 6 deletions tests/sharding-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ set -ex
# Things to install first:
# - jq, createtree

docker_compose="docker compose"
if ! ${docker_compose} version >/dev/null 2>&1; then
docker_compose="docker-compose"
fi

# Spin up services as usual

echo "Installing createtree..."
go install github.com/google/trillian/cmd/createtree@latest

echo "starting services"
docker-compose up -d
${docker_compose} up -d --build
rm ~/.rekor/state.json || true

echo "building CLI and server"
Expand Down Expand Up @@ -64,7 +69,7 @@ function waitForRekorServer () {
count=0

echo -n "waiting up to 60 sec for system to start"
until [ $(docker-compose ps | grep -c "(healthy)") == 3 ];
until [ $(${docker_compose} ps | grep -c "(healthy)") == 3 ];
do
if [ $count -eq 6 ]; then
echo "! timeout reached"
Expand All @@ -84,12 +89,12 @@ function waitForRekorServer () {
function collectLogsOnFailure () {
if [[ "$1" -ne "0" ]]; then
echo "failure detected, collecting docker-compose logs"
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit $1
elif docker-compose logs --no-color | grep -q "panic: runtime error:" ; then
elif ${docker_compose} logs --no-color | grep -q "panic: runtime error:" ; then
# if we're here, we found a panic
echo "failing due to panics detected in logs"
docker-compose logs --no-color > /tmp/docker-compose.log
${docker_compose} logs --no-color > /tmp/docker-compose.log
exit 1
fi
exit 0
Expand Down Expand Up @@ -189,7 +194,7 @@ EOF

# Spin up the new Rekor

docker-compose -f $COMPOSE_FILE up -d
${docker_compose} -f $COMPOSE_FILE up -d
waitForRekorServer
$REKOR_CLI loginfo --rekor_server http://localhost:3000

Expand Down

0 comments on commit 1cbf3a5

Please sign in to comment.