Nixius
/
template
Template
2
1
Fork 1
template/build-test-run.sh

64 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
set -e
# Colors for terminal output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
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
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}"
exit 1
fi
echo -e "${GREEN}Tests completed successfully${NC}"
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