test: fix Docker tests in GH Actions (#9812)
GH Actions recently changed their Docker build implementation and it has a different output than previously, causing the tests that parse its output to fail. This switches the test to not parse Docker build output. The parsing was used to extract the image ID while still showing logs. A better way to show logs and still know the image ID is to tag it, which is what this now does. This also renames the Docker tests so that they run earlier. This takes better advantage of the fact that the sharness tests are run in parallel. Since the Docker test are quite long, and are at the end of the list, the test runner is not running other tests in parallel while the Docker tests are running.
Gus Eggert committed
Apr 12, 2023 at 03:03 UTC
3a15a0fc550b1307cf54ef6ea5606fbe1bf72410
3 files changed
+15
-22
test/ipfs-test-lib.sh
+6
-6
@@ -50,19 +50,19 @@ test_path_cmp() {
50
51
# Docker
52
53
-# This takes a Dockerfile, and a build context directory
53
+# This takes a Dockerfile, a tag name, and a build context directory
54
docker_build() {
55
- docker build --rm -f "$1" "$2" | ansi_strip
55
+ docker build --rm --tag "$1" --file "$2" "$3" | ansi_strip
56
}
57
58
# This takes an image as argument and writes a docker ID on stdout
59
docker_run() {
60
- docker run -d "$1"
60
+ docker run --detach "$1"
61
}
62
63
# This takes a docker ID and a command as arguments
64
docker_exec() {
65
- docker exec -t "$1" /bin/sh -c "$2"
65
+ docker exec --tty "$1" /bin/sh -c "$2"
66
}
67
68
# This takes a docker ID as argument
@@ -72,12 +72,12 @@ docker_stop() {
72
73
# This takes a docker ID as argument
74
docker_rm() {
75
- docker rm -f -v "$1" > /dev/null
75
+ docker rm --force --volumes "$1" > /dev/null
76
}
77
78
# This takes a docker image name as argument
79
docker_rmi() {
80
- docker rmi -f "$1" > /dev/null
80
+ docker rmi --force "$1" > /dev/null
81
}
82
83
# Test whether all the expected lines are included in a file. The file
test/sharness/t0002-docker-image.sh
renamed
+5
-11
@@ -27,18 +27,12 @@ TEST_TRASH_DIR=$(pwd)
27
TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR")
28
TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
29
APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")
30
+IMAGE_TAG=kubo_test
31
32
test_expect_success "docker image build succeeds" '
32
- docker_build "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR" | tee build-actual ||
33
+ docker_build "$IMAGE_TAG" "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR" ||
34
test_fsh echo "TEST_TESTS_DIR: $TEST_TESTS_DIR" ||
34
- test_fsh echo "APP_ROOT_DIR : $APP_ROOT_DIR" ||
35
- test_fsh cat build-actual
36
-'
37
-
38
-test_expect_success "docker image build output looks good" '
39
- SUCCESS_LINE=$(egrep "^Successfully built" build-actual) &&
40
- IMAGE_ID=$(expr "$SUCCESS_LINE" : "^Successfully built \(.*\)") ||
41
- test_fsh cat build-actual
35
+ test_fsh echo "APP_ROOT_DIR : $APP_ROOT_DIR"
36
'
37
38
test_expect_success "write init scripts" '
@@ -52,7 +46,7 @@ test_expect_success "docker image runs" '
46
-p 127.0.0.1:5001:5001 -p 127.0.0.1:8080:8080 \
47
-v "$PWD/001.sh":/container-init.d/001.sh \
48
-v "$PWD/002.sh":/container-init.d/002.sh \
55
- "$IMAGE_ID")
49
+ "$IMAGE_TAG")
50
'
51
52
test_expect_success "docker container gateway is up" '
@@ -100,5 +94,5 @@ test_expect_success "stop docker container" '
94
'
95
96
docker_rm "$DOC_ID"
103
-docker_rmi "$IMAGE_ID"
97
+docker_rmi "$IMAGE_TAG"
98
test_done
test/sharness/t0003-docker-migrate.sh
renamed
+4
-5
@@ -24,10 +24,10 @@ TEST_TRASH_DIR=$(pwd)
24
TEST_SCRIPTS_DIR=$(dirname "$TEST_TRASH_DIR")
25
TEST_TESTS_DIR=$(dirname "$TEST_SCRIPTS_DIR")
26
APP_ROOT_DIR=$(dirname "$TEST_TESTS_DIR")
27
+IMAGE_TAG=kubo_migrate
28
29
test_expect_success "docker image build succeeds" '
29
- docker_build "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR" >actual &&
30
- IMAGE_ID=$(tail -n1 actual | cut -d " " -f 3)
30
+ docker_build "$IMAGE_TAG" "$TEST_TESTS_DIR/../Dockerfile" "$APP_ROOT_DIR"
31
'
32
33
test_init_ipfs
@@ -53,7 +53,7 @@ test_expect_success "startup fake dists server" '
53
'
54
55
test_expect_success "docker image runs" '
56
- DOC_ID=$(docker run -d -v "$IPFS_PATH":/data/ipfs --net=host "$IMAGE_ID")
56
+ DOC_ID=$(docker run -d -v "$IPFS_PATH":/data/ipfs --net=host "$IMAGE_TAG")
57
'
58
59
test_expect_success "docker container tries to pull migrations from netcat" '
@@ -78,6 +78,5 @@ test_expect_success "correct version was requested" '
78
'
79
80
docker_rm "$DOC_ID"
81
-docker_rmi "$IMAGE_ID"
81
+docker_rmi "$IMAGE_TAG"
82
test_done
83
-