|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +deployDocs() { |
| 4 | + local ns="$1" |
| 5 | + local tag="$2" |
| 6 | + local docsURL="$3" |
| 7 | + local typesenseFQDN="$4" |
| 8 | + |
| 9 | + echo "Building the aifrim/lttle-docs:$tag image..." |
| 10 | + docker build --build-arg DOCS_URL="$docsURL" --build-arg TYPESENSE_FQDN="$typesenseFQDN" --build-arg TYPESENSE_API_KEY="$TYPESENSE_API_KEY" -f ./docker/dockerfile . -t aifrim/lttle-docs:$tag |
| 11 | + |
| 12 | + echo "Pushing the aifrim/lttle-docs:$tag image..." |
| 13 | + docker push aifrim/lttle-docs:$tag |
| 14 | + |
| 15 | + echo "Deploying only the nginx-docs" |
| 16 | + lttle deploy ./lttle/docs.lttle.yaml |
| 17 | + |
| 18 | + echo "Restarting the machine in namespace $ns..." |
| 19 | + lttle machine restart --ns $ns nginx-docs |
| 20 | +} |
| 21 | + |
| 22 | +deployTypeSense() { |
| 23 | + local ns="$1" |
| 24 | + local tag="$2" |
| 25 | + local docsURL="$3" |
| 26 | + |
| 27 | + if [[ $ns != 'main' ]]; then |
| 28 | + echo "Backing up & patching ./docker/typesense-production.config.json" |
| 29 | + |
| 30 | + # Need to patch ./docker/typesense-production.config.json to scrape preview environment url |
| 31 | + cp ./docker/typesense-scraper.production.config.json ./docker/typesense-scraper.production.config.json.bak |
| 32 | + jq --arg url "$docsURL" '.start_urls[0].url = $url' ./docker/typesense-scraper.production.config.json.bak > ./docker/typesense-scraper.production.config.json |
| 33 | + fi |
| 34 | + |
| 35 | + echo "Building the aifrim/typesense-scraper:$tag image..." |
| 36 | + |
| 37 | + echo "Using config"; |
| 38 | + cat ./docker/typesense-scraper.production.config.json |
| 39 | + |
| 40 | + docker build -f ./docker/typesense-scraper.dockerfile docker -t aifrim/typesense-scraper:$tag |
| 41 | + |
| 42 | + if [[ $ns != 'main' ]]; then |
| 43 | + echo "Restoring ./docker/typesense-scraper.production.config.json" |
| 44 | + cp ./docker/typesense-scraper.production.config.json.bak ./docker/typesense-scraper.production.config.json |
| 45 | + rm ./docker/typesense-scraper.production.config.json.bak |
| 46 | + fi |
| 47 | + |
| 48 | + echo "Pushing the aifrim/typesense-scraper:$tag image..." |
| 49 | + docker push aifrim/typesense-scraper:$tag |
| 50 | + |
| 51 | + echo "Deploying only the typesense-search" |
| 52 | + lttle deploy ./lttle/typesense.lttle.yaml |
| 53 | + |
| 54 | + restartMachines "$ns" |
| 55 | +} |
| 56 | + |
| 57 | +restartMachines() { |
| 58 | + local ns="$1" |
| 59 | + |
| 60 | + echo "Restarting the machine in namespace $ns..." |
| 61 | + |
| 62 | + lttle machine restart --ns $ns nginx-docs |
| 63 | + lttle machine restart --ns $ns typesense-search |
| 64 | + lttle machine restart --ns $ns typesense-scraper |
| 65 | +} |
| 66 | + |
| 67 | +isUp() { |
| 68 | + local url="$1" |
| 69 | + local timeout="$2" |
| 70 | + local sleep="$3" |
| 71 | + |
| 72 | + START=$(date +%s) |
| 73 | + |
| 74 | + while true; do |
| 75 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$url") |
| 76 | + |
| 77 | + if [ "$STATUS" -eq 200 ]; then |
| 78 | + echo "✅ $url is up (HTTP 200)" |
| 79 | + return 0 |
| 80 | + fi |
| 81 | + |
| 82 | + NOW=$(date +%s) |
| 83 | + ELAPSED=$((NOW - START)) |
| 84 | + |
| 85 | + if [ "$ELAPSED" -ge "$timeout" ]; then |
| 86 | + echo "❌ Timeout reached ($timeout seconds). $url did not return 200." |
| 87 | + return 1 |
| 88 | + fi |
| 89 | + |
| 90 | + echo "⏳ $url not ready yet (status: $STATUS). Retrying in $sleep seconds..." |
| 91 | + sleep $sleep |
| 92 | + done |
| 93 | +} |
0 commit comments