Files
VoiceRSSSummary/run-docker.sh
2025-06-08 17:06:29 +09:00

67 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Run Docker container for Voice RSS Summary project
# Usage: ./run-docker.sh [container-name] [image-tag]
IMAGE_NAME="voice-rss-summary"
CONTAINER_NAME="${1:-voice-rss-summary}"
IMAGE_TAG="${2:-latest}"
FULL_IMAGE="${IMAGE_NAME}:${IMAGE_TAG}"
echo "Starting Docker container: ${CONTAINER_NAME}"
echo "Using image: ${FULL_IMAGE}"
# Check if image exists
if ! docker image inspect "${FULL_IMAGE}" >/dev/null 2>&1; then
echo "Error: Docker image '${FULL_IMAGE}' not found"
echo "Build it first with: ./build-docker-image.sh"
exit 1
fi
# Stop and remove existing container if it exists
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Stopping and removing existing container: ${CONTAINER_NAME}"
docker stop "${CONTAINER_NAME}" >/dev/null 2>&1 || true
docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || true
fi
# Create required directories if they don't exist
mkdir -p "$(pwd)/public/podcast_audio" "$(pwd)/data"
# Check for required files
if [[ ! -f "$(pwd)/.env" ]]; then
echo "Warning: .env file not found. Create one with required environment variables."
fi
if [[ ! -f "$(pwd)/feed_urls.txt" ]]; then
echo "Warning: feed_urls.txt not found. Creating empty file."
touch "$(pwd)/feed_urls.txt"
fi
# Run container with proper volume mounts and networking
docker run \
--detach \
--name "${CONTAINER_NAME}" \
--restart unless-stopped \
--publish 3000:3000 \
--publish 3001:3001 \
--volume "$(pwd)/feed_urls.txt:/app/feed_urls.txt:ro" \
--volume "$(pwd)/.env:/app/.env:ro" \
--volume "$(pwd)/public:/app/public" \
--volume "$(pwd)/data:/app/data" \
--health-cmd="bun -e 'fetch(\"http://localhost:3000\").then(() => process.exit(0)).catch(() => process.exit(1))'" \
--health-interval=30s \
--health-timeout=3s \
--health-start-period=10s \
--health-retries=3 \
"${FULL_IMAGE}"
echo "\nContainer started successfully!"
echo "Container name: ${CONTAINER_NAME}"
echo "Web UI: http://localhost:3000"
echo "Admin panel: http://localhost:3001"
echo "\nTo view logs: docker logs -f ${CONTAINER_NAME}"
echo "To stop: docker stop ${CONTAINER_NAME}"
echo "To remove: docker rm ${CONTAINER_NAME}"