83 lines
3.0 KiB
Bash
Executable File
83 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# Colors for terminal output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${YELLOW}Starting build-test-run script for local development${NC}"
|
|
|
|
# Create temp directory if it doesn't exist
|
|
mkdir -p ./temp
|
|
|
|
# Log file for build output
|
|
LOG_FILE="./temp/build-test-run.log"
|
|
echo "Build started at $(date)" > $LOG_FILE
|
|
|
|
# Step 1: Build the Docker images
|
|
echo -e "${GREEN}Step 1: Building Docker images${NC}"
|
|
echo "Building Docker images..." >> $LOG_FILE
|
|
docker compose -f docker-compose.dev.yml build >> $LOG_FILE 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Build failed. Check $LOG_FILE for details.${NC}"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}Build completed successfully${NC}"
|
|
|
|
# Step 2: Run tests if they exist
|
|
TESTS_PASSED=false
|
|
if [ -f "./tests/run_tests.sh" ]; then
|
|
echo -e "${GREEN}Step 2: Running tests${NC}"
|
|
echo "Running tests..." >> $LOG_FILE
|
|
chmod +x ./tests/run_tests.sh
|
|
./tests/run_tests.sh >> $LOG_FILE 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Tests failed. Check $LOG_FILE for details.${NC}"
|
|
echo -e "${YELLOW}Please fix the issues before committing your changes.${NC}"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}Tests completed successfully${NC}"
|
|
TESTS_PASSED=true
|
|
else
|
|
echo -e "${YELLOW}No test script found. Skipping tests.${NC}"
|
|
fi
|
|
|
|
# Step 3: Start the services
|
|
echo -e "${GREEN}Step 3: Starting services${NC}"
|
|
echo "Starting services..." >> $LOG_FILE
|
|
docker compose -f docker-compose.dev.yml up -d >> $LOG_FILE 2>&1
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Failed to start services. Check $LOG_FILE for details.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Get the URL for the service
|
|
PORT=$(docker compose -f docker-compose.dev.yml port template 3000 2>/dev/null | cut -d: -f2)
|
|
if [ -n "$PORT" ]; then
|
|
echo -e "${GREEN}Service is running at: ${YELLOW}http://localhost:$PORT${NC}"
|
|
else
|
|
echo -e "${YELLOW}Service is running but couldn't determine the port.${NC}"
|
|
fi
|
|
|
|
echo -e "${GREEN}All services are up and running!${NC}"
|
|
echo -e "To view logs: ${YELLOW}docker compose -f docker-compose.dev.yml logs -f${NC}"
|
|
echo -e "To stop: ${YELLOW}docker compose -f docker-compose.dev.yml down${NC}"
|
|
echo "Build and run completed at $(date)" >> $LOG_FILE
|
|
|
|
# Show Git workflow guidance if tests passed
|
|
if [ "$TESTS_PASSED" = true ]; then
|
|
echo -e "\n${BLUE}=== Ready to Commit and Push ===${NC}"
|
|
echo -e "${GREEN}All tests have passed! You can now commit and push your changes:${NC}"
|
|
echo -e "${YELLOW}git add .${NC}"
|
|
echo -e "${YELLOW}git commit -m \"Your descriptive commit message\"${NC}"
|
|
echo -e "${YELLOW}git push${NC}"
|
|
echo -e "\n${GREEN}Or use the convenient one-liner:${NC}"
|
|
echo -e "${YELLOW}git add . && git commit -m \"Your descriptive commit message\" && git push${NC}"
|
|
echo -e "\n${BLUE}Remember:${NC}"
|
|
echo -e "- Use descriptive commit messages"
|
|
echo -e "- Add 'HOTFIX:' prefix for emergency fixes"
|
|
echo -e "- Document significant changes in your commit message"
|
|
fi |