#!/bin/bash # Wine CSP Docker Build and Test # # Builds the Wine CSP Docker image and runs the full test suite. # This script is designed for local development and CI/CD pipelines. # # Usage: # ./docker-test.sh # Build and test # ./docker-test.sh --no-build # Test existing image # ./docker-test.sh --push # Build, test, and push if tests pass set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)" # Configuration IMAGE_NAME="${WINE_CSP_IMAGE:-wine-csp}" IMAGE_TAG="${WINE_CSP_TAG:-test}" FULL_IMAGE="${IMAGE_NAME}:${IMAGE_TAG}" DOCKERFILE="${PROJECT_ROOT}/ops/wine-csp/Dockerfile" DO_BUILD=true DO_PUSH=false VERBOSE=false # Parse arguments while [[ $# -gt 0 ]]; do case $1 in --no-build) DO_BUILD=false shift ;; --push) DO_PUSH=true shift ;; --verbose|-v) VERBOSE=true shift ;; --image) IMAGE_NAME="$2" FULL_IMAGE="${IMAGE_NAME}:${IMAGE_TAG}" shift 2 ;; --tag) IMAGE_TAG="$2" FULL_IMAGE="${IMAGE_NAME}:${IMAGE_TAG}" shift 2 ;; *) echo "Unknown option: $1" exit 1 ;; esac done log() { echo "[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] $*" } # Build image if [[ "${DO_BUILD}" == "true" ]]; then log "Building Wine CSP Docker image: ${FULL_IMAGE}" log "Dockerfile: ${DOCKERFILE}" log "Context: ${PROJECT_ROOT}" build_args="" if [[ "${VERBOSE}" == "true" ]]; then build_args="--progress=plain" fi docker build \ ${build_args} \ -f "${DOCKERFILE}" \ -t "${FULL_IMAGE}" \ "${PROJECT_ROOT}" log "Build completed successfully" fi # Verify image exists if ! docker image inspect "${FULL_IMAGE}" > /dev/null 2>&1; then echo "Error: Image ${FULL_IMAGE} not found" exit 1 fi # Run tests log "Running integration tests..." test_args="" if [[ "${VERBOSE}" == "true" ]]; then test_args="--verbose" fi "${SCRIPT_DIR}/run-tests.sh" --image "${FULL_IMAGE}" ${test_args} --ci # Check test results if [[ $? -ne 0 ]]; then log "Tests failed!" exit 1 fi log "All tests passed!" # Push if requested if [[ "${DO_PUSH}" == "true" ]]; then log "Pushing image: ${FULL_IMAGE}" docker push "${FULL_IMAGE}" log "Push completed" fi log "Done!"