95 lines
2.9 KiB
Bash
Executable File
95 lines
2.9 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] [--from-ghcr]
|
|
|
|
GITHUB_USERNAME="anosatsuk124"
|
|
IMAGE_NAME="voice-rss-summary"
|
|
CONTAINER_NAME="${1:-voice-rss-summary}"
|
|
IMAGE_TAG="${2:-latest}"
|
|
FROM_GHCR=false
|
|
|
|
# Check for --from-ghcr flag
|
|
for arg in "$@"; do
|
|
if [[ "$arg" == "--from-ghcr" ]]; then
|
|
FROM_GHCR=true
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [[ "$FROM_GHCR" == "true" ]]; then
|
|
FULL_IMAGE="ghcr.io/${GITHUB_USERNAME}/${IMAGE_NAME}:${IMAGE_TAG}"
|
|
else
|
|
FULL_IMAGE="${IMAGE_NAME}:${IMAGE_TAG}"
|
|
fi
|
|
|
|
echo "Starting Docker container: ${CONTAINER_NAME}"
|
|
echo "Using image: ${FULL_IMAGE}"
|
|
|
|
# Check if image exists or pull from GHCR
|
|
if ! docker image inspect "${FULL_IMAGE}" >/dev/null 2>&1; then
|
|
if [[ "$FROM_GHCR" == "true" ]]; then
|
|
echo "Pulling image from GitHub Container Registry..."
|
|
if ! docker pull "${FULL_IMAGE}"; then
|
|
echo "Error: Failed to pull Docker image '${FULL_IMAGE}' from GHCR"
|
|
echo "Make sure the image exists and you have access to it"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Error: Docker image '${FULL_IMAGE}' not found"
|
|
echo "Build it first with: ./build-docker-image.sh"
|
|
echo "Or use --from-ghcr flag to pull from GitHub Container Registry"
|
|
exit 1
|
|
fi
|
|
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" || true
|
|
|
|
# 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
|
|
exec 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 ""
|
|
echo "Container started successfully!"
|
|
echo "Container name: ${CONTAINER_NAME}"
|
|
echo "Image: ${FULL_IMAGE}"
|
|
echo "Web UI: http://localhost:3000"
|
|
echo "Admin panel: http://localhost:3001"
|
|
echo ""
|
|
echo "To view logs: docker logs -f ${CONTAINER_NAME}"
|
|
echo "To stop: docker stop ${CONTAINER_NAME}"
|
|
echo "To remove: docker rm ${CONTAINER_NAME}"
|