Repository navigation
Expand file tree
/
Copy pathsmoke.sh
More file actions
executable file
·67 lines (56 loc) · 2.97 KB
/
Copy pathsmoke.sh
File metadata and controls
executable file
·67 lines (56 loc) · 2.97 KB
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
#!/usr/bin/env bash
# End-to-end smoke test for an installed Appwrite release.
#
# Signs in to the console (creating the root account on a fresh install),
# creates a project, a database, a collection and an attribute, and waits for
# the attribute to become available. Attributes are created asynchronously by
# the databases queue, so this proves the API, datastores and workers work
# together. Finally it checks the console.
#
# Usage: hack/smoke.sh [release] [namespace]
# Requires: kubectl, curl, jq.
set -euo pipefail
# shellcheck source=lib/api.sh
source "$(dirname "$0")/lib/api.sh"
RELEASE="${1:-appwrite}"
NAMESPACE="${2:-appwrite}"
TIMEOUT="${SMOKE_TIMEOUT:-180}"
api_connect "$RELEASE" "$NAMESPACE"
log "API version"
call GET /health/version | jq -e '.version'
log "Sign in to the console"
api_login
log "Create a project"
project=$(api_project smoke)
echo "$project"
log "Create a database, a collection and an attribute"
call POST /databases '{"databaseId":"smoke","name":"Smoke"}' "$project" >/dev/null
call POST /databases/smoke/collections '{"collectionId":"items","name":"Items"}' "$project" >/dev/null
call POST /databases/smoke/collections/items/attributes/string '{"key":"title","size":64,"required":false}' "$project" >/dev/null
log "Wait for the databases worker to make the attribute available"
deadline=$((SECONDS + TIMEOUT))
until status=$(call GET /databases/smoke/collections/items/attributes/title "" "$project" | jq -r '.status') && [[ "$status" == available ]]; do
[[ "$status" == failed ]] && fail "attribute creation failed"
(( SECONDS < deadline )) || fail "attribute still '$status' after ${TIMEOUT}s: is the worker running?"
sleep 3
done
echo "attribute is available"
log "Create a document"
call POST /databases/smoke/collections/items/documents '{"documentId":"unique()","data":{"title":"hello"}}' "$project" | jq -e '.title == "hello"' >/dev/null
if kubectl -n "$NAMESPACE" get svc "${API_SERVICE%-api}-browser" >/dev/null 2>&1; then
log "Screenshot through the browser service"
shot="$API_TMP/shot.png"
code=$(curl -sS -o "$shot" -w '%{http_code}' -H "Host: $API_HOST" -H "X-Appwrite-Project: console" \
-H "X-Fallback-Cookies: $API_COOKIES" \
"http://127.0.0.1:$API_PORT/v1/avatars/screenshots?url=https%3A%2F%2Fexample.com&width=640&height=360")
if [[ "$code" != 200 || "$(head -c 4 "$shot" | tail -c 3)" != PNG ]]; then
fail "screenshot returned HTTP $code"
fi
echo "screenshot OK ($(wc -c < "$shot") bytes)"
fi
log "Console"
console="${API_SERVICE%-api}-console"
kubectl -n "$NAMESPACE" run "smoke-$(date +%s)" --rm -i --restart=Never --quiet \
--image=curlimages/curl:8.16.0 \
--overrides='{"spec":{"securityContext":{"runAsNonRoot":true,"runAsUser":100,"seccompProfile":{"type":"RuntimeDefault"}},"containers":[{"name":"c","image":"curlimages/curl:8.16.0","args":["-fsS","-o","/dev/null","-w","console HTTP %{http_code}\\n","http://'"$console"'/"],"securityContext":{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}}]}}'
log "OK"