Monorepo for Tangled tangled.org
6

Configure Feed

Select the types of activity you want to include in your feed.

1#!/usr/bin/env bash 2set -euo pipefail 3 4# start a local ncps binary cache 5# usage: ./start-test-cache.sh <test-dir> [port] 6 7if [ "$#" -lt 1 ]; then 8 echo "Usage: $0 <test-dir> [ncps-port]" 9 exit 1 10fi 11 12TEST_DIR="$(mkdir -p "$1" && cd "$1" && pwd)" 13PORT="${2:-8501}" 14 15ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" 16 17SECRET_KEY_PATH="$TEST_DIR/test-cache-key.secret" 18PUBLIC_KEY_PATH="$TEST_DIR/test-cache-key.pub" 19DB_PATH="$TEST_DIR/ncps.sqlite" 20CONFIG_PATH="$TEST_DIR/ncps-config.yaml" 21STORAGE_DIR="$TEST_DIR/storage" 22ENV_PATH="$TEST_DIR/env.sh" 23PID_PATH="$TEST_DIR/ncps.pid" 24 25mkdir -p "$STORAGE_DIR" 26 27echo "generating binary cache keys.." 28nix-store --generate-binary-cache-key test-cache-key "$SECRET_KEY_PATH" "$PUBLIC_KEY_PATH" 29PUBKEY_VAL=$(cat "$PUBLIC_KEY_PATH") 30 31echo "initializing ncps db..." 32nix shell nixpkgs#dbmate --command dbmate \ 33 --migrations-dir "$(nix build --no-link --print-out-paths nixpkgs#ncps)/share/ncps/db/migrations/sqlite" \ 34 -u "sqlite:$DB_PATH" \ 35 up 36 37echo "writing ncps configuration..." 38cat <<EOF > "$CONFIG_PATH" 39cache: 40 allow-delete-verb: true 41 allow-put-verb: true 42 hostname: "cache.local" 43 database-url: "sqlite:$DB_PATH" 44 secret-key-path: "$SECRET_KEY_PATH" 45 sign-narinfo: true 46 storage: 47 local: "$STORAGE_DIR" 48 upstream: 49 urls: 50 - https://cache.nixos.org 51 public-keys: 52 - cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= 53server: 54 addr: "127.0.0.1:$PORT" 55EOF 56 57echo "starting ncps on port $PORT..." 58export CACHE_ALLOW_PUT_VERB=true 59nix shell nixpkgs#ncps --command ncps serve --config "$CONFIG_PATH" & 60NCPS_PID=$! 61echo "$NCPS_PID" > "$PID_PATH" 62 63# wait for connection 64for i in {1..30}; do 65 if curl -s "http://127.0.0.1:$PORT/nix-cache-info" > /dev/null; then 66 echo "ncps is healthy." 67 break 68 fi 69 sleep 0.5 70 if ! kill -0 "$NCPS_PID" 2>/dev/null; then 71 echo "ncps exited unexpectedly during startup." 72 exit 1 73 fi 74done 75 76cat <<EOF > "$ENV_PATH" 77export CACHE_PUBKEY="$PUBKEY_VAL" 78export CACHE_PORT="$PORT" 79export CACHE_URL="http://127.0.0.1:$PORT" 80export CACHE_UPLOAD_URL="http://127.0.0.1:$PORT/upload" 81export CACHE_SECRET_KEY_PATH="$SECRET_KEY_PATH" 82export NCPS_PID="$NCPS_PID" 83export TEST_DIR="$TEST_DIR" 84EOF 85 86echo "cache server started successfully. source $ENV_PATH to use, and kill PID $NCPS_PID or check $PID_PATH to stop it."