|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +pr_number="${1:?usage: $0 <pr-number>}" |
| 6 | +registry_host="${SCROLL_REGISTRY_HOST:?SCROLL_REGISTRY_HOST is required}" |
| 7 | +registry_host="${registry_host#http://}" |
| 8 | +registry_host="${registry_host#https://}" |
| 9 | +registry_host="${registry_host%%/*}" |
| 10 | + |
| 11 | +namespace="${SCROLL_REGISTRY_PR_NAMESPACE:-druid-team-experimental}" |
| 12 | +runtime_namespace="${SCROLL_REGISTRY_RUNTIME_NAMESPACE:-druid-team}" |
| 13 | +runtime_image="${DRUID_SCROLL_RUNTIME_IMAGE:-${registry_host}/${runtime_namespace}/druid:stable-nix}" |
| 14 | +roots="${SCROLL_PR_ROOTS:-}" |
| 15 | + |
| 16 | +yaml_value() { |
| 17 | + awk -F':[[:space:]]*' -v key="$2" ' |
| 18 | + $1 == key { |
| 19 | + value = $2 |
| 20 | + gsub(/^"/, "", value) |
| 21 | + gsub(/"$/, "", value) |
| 22 | + print value |
| 23 | + exit |
| 24 | + } |
| 25 | + ' "$1" |
| 26 | +} |
| 27 | + |
| 28 | +scroll_dirs() { |
| 29 | + if [[ -n "$roots" ]]; then |
| 30 | + for root in $roots; do |
| 31 | + for dir in "$root"/*; do |
| 32 | + [[ -f "$dir/scroll.yaml" ]] || continue |
| 33 | + printf '%s\n' "$dir" |
| 34 | + done |
| 35 | + [[ -f "$root/scroll.yaml" ]] && printf '%s\n' "$root" |
| 36 | + done |
| 37 | + return |
| 38 | + fi |
| 39 | + find ./scrolls -type f -name scroll.yaml -print | sed 's#/scroll.yaml$##' | sort |
| 40 | +} |
| 41 | + |
| 42 | +port_args() { |
| 43 | + awk ' |
| 44 | + /^ports:/ { in_ports=1; next } |
| 45 | + /^[^[:space:]-]/ { in_ports=0 } |
| 46 | + in_ports && /^[[:space:]]*-[[:space:]]*name:/ { |
| 47 | + name=$0 |
| 48 | + sub(/^[[:space:]]*-[[:space:]]*name:[[:space:]]*/, "", name) |
| 49 | + gsub(/"/, "", name) |
| 50 | + } |
| 51 | + in_ports && /^[[:space:]]*port:/ { |
| 52 | + port=$0 |
| 53 | + sub(/^[[:space:]]*port:[[:space:]]*/, "", port) |
| 54 | + if (name != "" && port != "") { |
| 55 | + printf " -p %s=%s", name, port |
| 56 | + } |
| 57 | + } |
| 58 | + ' "$1/scroll.yaml" |
| 59 | +} |
| 60 | + |
| 61 | +category_for_dir() { |
| 62 | + local dir="$1" |
| 63 | + dir="${dir#./scrolls/}" |
| 64 | + echo "${dir%%/*}" |
| 65 | +} |
| 66 | + |
| 67 | +push_dir() { |
| 68 | + local dir="$1" |
| 69 | + local name app_version image artifact ports category |
| 70 | + |
| 71 | + if [[ "$dir" == ./scrolls/.sample || "$dir" == ./scrolls/.sample/* ]]; then |
| 72 | + echo "Skipping ${dir}: sample scrolls are validation fixtures" |
| 73 | + return |
| 74 | + fi |
| 75 | + |
| 76 | + name="$(yaml_value "$dir/scroll.yaml" name)" |
| 77 | + app_version="$(yaml_value "$dir/scroll.yaml" app_version)" |
| 78 | + if [[ "$app_version" == "latest" ]]; then |
| 79 | + echo "Skipping ${dir}: PR previews do not publish latest tags" |
| 80 | + return |
| 81 | + fi |
| 82 | + |
| 83 | + image="${name##*/}" |
| 84 | + artifact="${registry_host}/${namespace}/${image}:${app_version}-pr${pr_number}" |
| 85 | + ports="$(port_args "$dir")" |
| 86 | + category="$(category_for_dir "$dir")" |
| 87 | + |
| 88 | + echo "Pushing ${artifact} from ${dir}" |
| 89 | + # shellcheck disable=SC2086 |
| 90 | + druid push "$artifact" "$dir" $ports \ |
| 91 | + -i "$runtime_image" \ |
| 92 | + --min-disk 3Gi --min-ram 512Mi --min-cpu 0.25 \ |
| 93 | + --smart --category "$category" |
| 94 | +} |
| 95 | + |
| 96 | +while IFS= read -r dir; do |
| 97 | + push_dir "$dir" |
| 98 | +done < <(scroll_dirs) |
0 commit comments