File size: 1,075 Bytes
8960eeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Build the Docker image, run the container, wait for it to come up, run the
# HTTP smoke test against it, then tear everything down.
#
# Usage:  scripts/docker_smoke.sh
# Requires a running Docker daemon.
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
IMAGE="ppt-pdf-tools:smoke"
NAME="ppt-pdf-tools-smoke"
PORT="${PORT:-8123}"
BASE_URL="http://localhost:$PORT"

cleanup() {
  docker rm -f "$NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT

echo "==> Building image ($IMAGE)…"
docker build -t "$IMAGE" "$ROOT"

echo "==> Starting container on port $PORT…"
cleanup
docker run -d --name "$NAME" -p "$PORT:8000" "$IMAGE" >/dev/null

echo "==> Waiting for health…"
for i in $(seq 1 30); do
  if curl -fs "$BASE_URL/api/health" >/dev/null 2>&1; then
    echo "    up after ${i}s"
    break
  fi
  if [ "$i" -eq 30 ]; then
    echo "    container failed to become healthy; logs:"
    docker logs "$NAME" || true
    exit 1
  fi
  sleep 1
done

echo "==> Running HTTP smoke test…"
"$ROOT/scripts/smoke_test.sh" "$BASE_URL"