Files
immich-sdk/scripts/start-immich.sh
Joakim Hulthe 2e7db3b35a Add integration testing infrastructure with Podman Compose
- Add docker/podman-compose.yml for Immich server (no ML)
- Add test-data/sample-photos/ with 3 public domain images
- Add scripts/start-immich.sh for container startup + admin/API key creation
- Add scripts/seed-data.sh for uploading test photos and creating albums
- Add scripts/stop-immich.sh for cleanup with volume destruction
- Add scripts/run-example.sh wrapper (fixed env var export)
- Update examples to use IMMICH_URL and IMMICH_API_KEY env vars
- Add .github/workflows/integration-test.yml for CI
- Update assets.list() to use /search/metadata endpoint
- Update AGENTS.md with example running instructions
- Add 5 new examples: search_metadata, album_management, timeline_browsing,
  delete_assets, server_info
2026-04-14 20:13:30 +00:00

122 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# Script to start Immich containers, create admin user, and generate API key
# This script is used for integration testing
cd "$(dirname "$0")/.."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check dependencies
check_dependency() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}Error: $1 is not installed${NC}"
exit 1
fi
}
echo "Checking dependencies..."
check_dependency "podman"
check_dependency "curl"
check_dependency "jq"
# Check if podman-compose is available
if ! podman compose version &> /dev/null && ! command -v podman-compose &> /dev/null; then
echo -e "${RED}Error: podman-compose is not available${NC}"
echo "Please install podman-compose or ensure 'podman compose' is available"
exit 1
fi
# Start containers
echo "Starting Immich containers..."
podman compose -f docker/podman-compose.yml up -d
# Wait for health check (max 120s)
echo "Waiting for Immich to be ready..."
READY=false
for i in {1..60}; do
if curl -s http://localhost:2283/api/server/ping > /dev/null 2>&1; then
echo -e "${GREEN}Immich is ready!${NC}"
READY=true
break
fi
echo "Attempt $i/60 - waiting for Immich..."
sleep 2
done
if [ "$READY" = false ]; then
echo -e "${RED}Error: Immich failed to become ready within 120 seconds${NC}"
exit 1
fi
# Admin credentials
ADMIN_EMAIL="admin@example.com"
ADMIN_PASSWORD="admin123"
ADMIN_NAME="Admin User"
# Create admin user
echo "Creating admin user..."
curl -s -X POST http://localhost:2283/api/auth/admin-sign-up \
-H "Content-Type: application/json" \
-d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\",\"name\":\"$ADMIN_NAME\"}" \
|| echo -e "${YELLOW}Admin may already exist, continuing...${NC}"
# Login to get access token
echo "Logging in to get access token..."
LOGIN_RESPONSE=$(curl -s -X POST http://localhost:2283/api/auth/login \
-H "Content-Type: application/json" \
-d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\"}")
ACCESS_TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.accessToken')
if [ -z "$ACCESS_TOKEN" ] || [ "$ACCESS_TOKEN" = "null" ]; then
echo -e "${RED}Error: Failed to get access token${NC}"
echo "Response: $LOGIN_RESPONSE"
exit 1
fi
# Create API key
echo "Creating API key..."
API_KEY_RESPONSE=$(curl -s -X POST http://localhost:2283/api/api-keys \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{"name":"sdk-test-key","permissions":["all"]}')
API_KEY=$(echo "$API_KEY_RESPONSE" | jq -r '.secret')
if [ -z "$API_KEY" ] || [ "$API_KEY" = "null" ]; then
echo -e "${RED}Error: Failed to create API key${NC}"
echo "Response: $API_KEY_RESPONSE"
exit 1
fi
# Save to .env.test
echo "Saving credentials to .env.test..."
cat > .env.test << EOF
IMMICH_URL=http://localhost:2283
IMMICH_API_KEY=$API_KEY
EOF
# Success message
echo -e "${GREEN}=======================================${NC}"
echo -e "${GREEN}Immich setup complete!${NC}"
echo -e "${GREEN}=======================================${NC}"
echo ""
echo "Credentials saved to .env.test:"
echo " IMMICH_URL: http://localhost:2283"
echo " IMMICH_API_KEY: ${API_KEY:0:10}... (truncated)"
echo ""
echo "Admin user:"
echo " Email: $ADMIN_EMAIL"
echo " Password: $ADMIN_PASSWORD"
echo ""
echo "You can now access Immich at: http://localhost:2283"
echo ""
echo "To stop the containers, run:"
echo " podman compose -f docker/podman-compose.yml down"