-
Notifications
You must be signed in to change notification settings - Fork 10
/
pyrsia_node_docker_build_service.bats
147 lines (124 loc) · 4.63 KB
/
pyrsia_node_docker_build_service.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
# common setup
COMMON_SETUP='common-setup'
# docker compose file
DOCKER_COMPOSE_DIR="$REPO_DIR/bats/tests/resources/docker/docker-compose_auth_nodes.yml"
# docker image tag info
NODE_DOCKER_IMAGE_NAME="alpine"
NODE_DOCKER_IMAGE_TAG="3.16"
NODE_DOCKER_IMAGE_OTHER_TAG="3.15"
# docker mapping id
BUILD_SERVICE_DOCKER_MAPPING_ID="$NODE_DOCKER_IMAGE_NAME:$NODE_DOCKER_IMAGE_TAG"
BUILD_SERVICE_DOCKER_MAPPING_OTHER_ID="$NODE_DOCKER_IMAGE_NAME:$NODE_DOCKER_IMAGE_OTHER_TAG"
# node_hostname
NODE_HOSTNAME="localhost:7889"
CLIENT_HOSTNAME="localhost:7888"
setup_file() {
load $COMMON_SETUP
_common_setup_file "$DOCKER_COMPOSE_DIR"
}
teardown_file() {
load $COMMON_SETUP
_common_teardown_file
}
setup() {
load $COMMON_SETUP
_common_setup
PYRSIA_CLI="$PYRSIA_TARGET_DIR/pyrsia"
}
@test "Testing the build service, docker (build and download docker image, inspect-log)." {
# the build image request should fail on the non existing maven mapping ID and non authorized node (node authorization is done later in the code)
run "$PYRSIA_CLI" build docker --image "FAKE_IMAGE_NAME"
refute_output --partial "successfully"
# get peer_id of node
_get_peer_id_of_node "$NODE_HOSTNAME"
# add authorize node
run "$PYRSIA_CLI" authorize --peer "$PEER_ID"
# check if the add authorize node successful
assert_output --partial "successfully"
# confirm the artifact is not already added to pyrsia node
run "$PYRSIA_CLI" inspect-log docker --image $BUILD_SERVICE_DOCKER_MAPPING_ID
refute_output --partial $BUILD_SERVICE_DOCKER_MAPPING_ID
# init the build
local build_message
build_message=$("$PYRSIA_CLI" build docker --image $BUILD_SERVICE_DOCKER_MAPPING_ID)
local build_id
build_id=$(echo "$build_message" | awk -F\' '{ print $2 }')
run echo "$build_message"
assert_output --partial "successfully"
# waiting until the build is done => inspect logs available
echo -e "\t- Building docker image $BUILD_SERVICE_DOCKER_MAPPING_ID - [$PYRSIA_CLI build docker --image $BUILD_SERVICE_DOCKER_MAPPING_ID], it might take a while..." >&3
# shellcheck disable=SC2034
for i in {0..40}
do
inspect_log=$($PYRSIA_CLI inspect-log docker --image $BUILD_SERVICE_DOCKER_MAPPING_ID)
if [[ "$inspect_log" == *"$BUILD_SERVICE_DOCKER_MAPPING_ID"* ]]; then
sleep 10
# check if build status is present and SUCCESS
log INFO "Check build status for build ID $build_id"
run $PYRSIA_CLI build status --id "$build_id"
assert_output --partial "SUCCESS"
break
fi
sleep 5
done
# check if the logs contains the artifact info
run echo "$inspect_log"
assert_output --partial $BUILD_SERVICE_DOCKER_MAPPING_ID
echo -e "\t- Docker image built successfully - $BUILD_SERVICE_DOCKER_MAPPING_ID" >&3
# check if the built image can be pulled from the Pyrsia node
local image_exists=false;
# shellcheck disable=SC2034
for i in {0..20}
do
# query the registry
# shellcheck disable=SC2155
local result=$(curl --silent http://$CLIENT_HOSTNAME/v2/library/$NODE_DOCKER_IMAGE_NAME/manifests/$NODE_DOCKER_IMAGE_TAG/)
if ! [[ $result == *error* ]]; then
image_exists=true
break
fi
sleep 5
done
assert $image_exists
}
@test "No build status is returned when build id does not exist." {
local build_id="b024a136-9021-42a1-b8de-c665c94470f4"
run "$PYRSIA_CLI" build status --id $build_id
assert_output --partial "'$build_id' was not found"
assert_output --partial "Failed to fetch"
}
@test "Verify that a node can't be authorized twice." {
# get peer_id of node
_get_peer_id_of_node "$NODE_HOSTNAME"
# try to authorize again
run "$PYRSIA_CLI" authorize --peer "$PEER_ID"
assert_output --partial "400 Bad"
assert_output --partial "already exists"
}
@test "Verify that a build starts if an artifact is requested but doesn't exist in the transparency log yet." {
# request an image from the Pyrsia node that hasn't been built yet
local image_exists=false;
local URL=http://$CLIENT_HOSTNAME/v2/library/$NODE_DOCKER_IMAGE_NAME/manifests/$NODE_DOCKER_IMAGE_OTHER_TAG/
# shellcheck disable=SC2155
local result=$(curl -sS $URL)
run echo "$result"
assert_output --partial "ManifestUnknown"
sleep 10
# shellcheck disable=SC2034
for i in {0..20}
do
# query the registry
# shellcheck disable=SC2155
result=$(curl --silent $URL)
if ! [[ $result == *error* ]]; then
image_exists=true
break
fi
sleep 5
done
assert $image_exists
# confirm the artifact is already added to pyrsia node
run "$PYRSIA_CLI" inspect-log docker --image $BUILD_SERVICE_DOCKER_MAPPING_OTHER_ID
assert_output --partial $BUILD_SERVICE_DOCKER_MAPPING_OTHER_ID
}