173 lines
4.8 KiB
Bash
Executable File
173 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Default values
|
|
IMAGE_NAME="rideaware-frontend"
|
|
IMAGE_TAG="latest"
|
|
NO_CACHE=false
|
|
RUN_CONTAINER=false
|
|
CONTAINER_NAME="rideaware-frontend"
|
|
API_URL="http://127.0.0.1:5000"
|
|
|
|
# Help function
|
|
show_help() {
|
|
cat << EOF
|
|
Usage: $0 [OPTIONS]
|
|
|
|
OPTIONS:
|
|
-t, --tag TAG Image tag (default: latest)
|
|
-n, --name NAME Image name (default: rideaware-frontend)
|
|
-r, --run Run container after build
|
|
-c, --container NAME Container name (default: rideaware-frontend)
|
|
-a, --api-url URL Backend API URL (default: http://127.0.0.1:5000)
|
|
--no-cache Build without cache
|
|
-h, --help Show this help message
|
|
|
|
EXAMPLES:
|
|
$0 # Build as rideaware-frontend:latest
|
|
$0 -t v1.0 # Build as rideaware-frontend:v1.0
|
|
$0 -t dev --run # Build and run
|
|
$0 --no-cache -t prod --run # Build without cache and run
|
|
|
|
EOF
|
|
exit 0
|
|
}
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-t|--tag)
|
|
IMAGE_TAG="$2"
|
|
shift 2
|
|
;;
|
|
-n|--name)
|
|
IMAGE_NAME="$2"
|
|
shift 2
|
|
;;
|
|
-r|--run)
|
|
RUN_CONTAINER=true
|
|
shift
|
|
;;
|
|
-c|--container)
|
|
CONTAINER_NAME="$2"
|
|
shift 2
|
|
;;
|
|
-a|--api-url)
|
|
API_URL="$2"
|
|
shift 2
|
|
;;
|
|
--no-cache)
|
|
NO_CACHE=true
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_help
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown option: $1${NC}"
|
|
show_help
|
|
;;
|
|
esac
|
|
done
|
|
|
|
FULL_IMAGE="$IMAGE_NAME:$IMAGE_TAG"
|
|
BUILD_ARGS=""
|
|
|
|
if [ "$NO_CACHE" = true ]; then
|
|
BUILD_ARGS="--no-cache"
|
|
fi
|
|
|
|
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
|
|
echo -e "${BLUE}║ Building Frontend Podman Image ║${NC}"
|
|
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
|
|
echo -e "${YELLOW}Image: $FULL_IMAGE${NC}"
|
|
echo -e "${YELLOW}API URL: $API_URL${NC}"
|
|
echo ""
|
|
|
|
if ! podman build $BUILD_ARGS -f docker/Dockerfile -t "$FULL_IMAGE" \
|
|
--build-arg VUE_API_URL="$API_URL" .; then
|
|
echo -e "${RED}✗ Build failed${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Image built successfully${NC}"
|
|
echo ""
|
|
|
|
# Show image info
|
|
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
|
|
echo -e "${BLUE}║ Image Details ║${NC}"
|
|
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
|
|
podman images "$IMAGE_NAME:$IMAGE_TAG" --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}\t{{.Created}}"
|
|
echo ""
|
|
|
|
if [ "$RUN_CONTAINER" = true ]; then
|
|
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
|
|
echo -e "${BLUE}║ Starting Container ║${NC}"
|
|
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
|
|
echo ""
|
|
|
|
# Check if container already exists
|
|
if podman ps -a --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}\$"; then
|
|
echo -e "${YELLOW}Removing existing container: $CONTAINER_NAME${NC}"
|
|
|
|
# Stop if running
|
|
if podman ps --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}\$"; then
|
|
echo " Stopping container..."
|
|
podman kill "$CONTAINER_NAME" 2>/dev/null || true
|
|
fi
|
|
|
|
# Remove
|
|
echo " Removing container..."
|
|
if podman rm "$CONTAINER_NAME" 2>/dev/null; then
|
|
echo -e "${GREEN} ✓ Container removed${NC}"
|
|
else
|
|
echo -e "${RED} ✗ Failed to remove container${NC}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "Starting new container: $CONTAINER_NAME"
|
|
echo ""
|
|
|
|
if podman run -d \
|
|
--name "$CONTAINER_NAME" \
|
|
-p 3000:3000 \
|
|
-e VUE_API_URL="$API_URL" \
|
|
"$FULL_IMAGE"; then
|
|
echo -e "${GREEN}✓ Container started: $CONTAINER_NAME${NC}"
|
|
sleep 2
|
|
echo ""
|
|
|
|
echo -e "${YELLOW}Container logs:${NC}"
|
|
podman logs "$CONTAINER_NAME" 2>/dev/null || echo "No logs yet"
|
|
echo ""
|
|
|
|
echo -e "${GREEN}Frontend available at: http://localhost:3000${NC}"
|
|
echo -e "${YELLOW}API configured at: $API_URL${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}To view logs:${NC}"
|
|
echo " podman logs -f $CONTAINER_NAME"
|
|
echo ""
|
|
echo -e "${YELLOW}To stop:${NC}"
|
|
echo " podman kill $CONTAINER_NAME"
|
|
else
|
|
echo -e "${RED}✗ Failed to start container${NC}"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo -e "${YELLOW}To run the container:${NC}"
|
|
echo " podman run -d --name $CONTAINER_NAME -p 3000:3000 -e VUE_API_URL='$API_URL' $FULL_IMAGE"
|
|
echo ""
|
|
echo -e "${YELLOW}Or use this script with --run:${NC}"
|
|
echo " $0 -t $IMAGE_TAG --run -a '$API_URL'"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}✓ Done!${NC}" |