#!/bin/bash set -e # Deploy script for My Weekly To-Do List # Usage: ./deploy.sh [version] # Example: ./deploy.sh 1.1.0 APP_NAME="my-weekly-todo" COMPOSE_FILE="docker-compose.yml" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' echo -e "${GREEN}=== $APP_NAME Deploy ===${NC}" # Ensure we're on main branch BRANCH=$(git rev-parse --abbrev-ref HEAD) if [ "$BRANCH" != "main" ]; then echo -e "${RED}Error: Must deploy from main branch (currently on '$BRANCH')${NC}" echo "Run: git checkout main && git merge dev" exit 1 fi # Check for uncommitted changes if [ -n "$(git status --porcelain)" ]; then echo -e "${RED}Error: Uncommitted changes detected. Commit or stash first.${NC}" git status --short exit 1 fi # Optional: bump version VERSION=$1 if [ -n "$VERSION" ]; then echo -e "${YELLOW}Bumping version to $VERSION...${NC}" npm version "$VERSION" --no-git-tag-version git add package.json package-lock.json git commit -m "chore: bump version to v$VERSION" git tag -a "v$VERSION" -m "Release v$VERSION" echo -e "${GREEN}Tagged v$VERSION${NC}" fi # Run database migrations echo -e "${YELLOW}Running database migrations...${NC}" docker compose -f "$COMPOSE_FILE" run --rm app npx prisma migrate deploy 2>/dev/null || true # Build and deploy echo -e "${YELLOW}Building production image...${NC}" docker compose -f "$COMPOSE_FILE" build --no-cache echo -e "${YELLOW}Starting services...${NC}" docker compose -f "$COMPOSE_FILE" up -d # Wait for health check echo -e "${YELLOW}Waiting for health check...${NC}" sleep 10 if docker compose -f "$COMPOSE_FILE" ps | grep -q "healthy"; then echo -e "${GREEN}Deployment successful!${NC}" else echo -e "${YELLOW}Services started (health check may still be warming up)${NC}" docker compose -f "$COMPOSE_FILE" ps fi CURRENT_VERSION=$(node -p "require('./package.json').version") echo -e "${GREEN}=== Deployed v$CURRENT_VERSION ===${NC}"