#!/bin/bash# Default valuesbuild_type="full"enable_security="false"run_compose="true"# Function to parse command line argumentsparse_args() {case "1ドル" in""|-lite|-ultra-lite) build_type="1ドル";;esaccase "2ドル" intrue|false) enable_security="2ドル";;esaccase "3ドル" intrue|false) run_compose="3ドル";;esac}# Function to check the health of the service with a timeout of 80 secondscheck_health() {local service_name=1ドルlocal compose_file=2ドルlocal end=$((SECONDS+80)) # Fixed the timeout to be 80 seconds as per the function commentecho -n "Waiting for $service_name to become healthy..."until [ "$(docker inspect --format='{{json .State.Health.Status}}' "$service_name")" == '"healthy"' ] || [ $SECONDS -ge $end ]; dosleep 3echo -n "."if [ $SECONDS -ge $end ]; thenecho -e "\n$service_name health check timed out after 80 seconds."echo "Printing logs for $service_name:"docker logs "$service_name"return 1fidoneecho -e "\n$service_name is healthy!"echo "Printing logs for $service_name:"docker logs "$service_name"return 0}# Function to build and test a Docker Compose configuration# Function to build and test a Docker Compose configuration# Function to build and test a Docker Compose configurationbuild_and_test() {local version_tag="alpha"local dockerfile_name="./Dockerfile"local image_base="frooodle/s-pdf"local security_suffix=""local docker_compose_base="./exampleYmlFiles/docker-compose-latest"local compose_suffix=".yml"local service_name_base="Stirling-PDF"if [ "$enable_security" == "true" ]; thensecurity_suffix="-Security"docker_compose_base+="-security" # Append to base name for Docker Compose files with securityficase "$build_type" infull)dockerfile_name="./Dockerfile";;ultra-lite)dockerfile_name="./Dockerfile-ultra-lite";;esac# Dynamic image tag and service name based on build type and securitylocal image_tag="${image_base}:latest${build_type}${security_suffix}"local service_name="${service_name_base}${build_type^}${security_suffix}"local compose_file="${docker_compose_base}${build_type}${compose_suffix}"# Gradle build with or without securityecho "Running ./gradlew clean build with security=$enable_security..."./gradlew clean buildif [ $? -ne 0 ]; thenecho "Gradle build failed, exiting script."exit 1fi# Building Docker imageecho "Building Docker image $image_tag with Dockerfile $dockerfile_name..."docker build --build-arg VERSION_TAG=$version_tag -t $image_tag -f $dockerfile_name .if [ "$run_compose" == "true" ]; thenecho "Running Docker Compose for $build_type with security=$enable_security..."docker-compose -f "$compose_file" up -d# Health check using the dynamic service nameif ! check_health "$service_name" "$compose_file"; thenecho "$service_name health check failed."docker-compose -f "$compose_file" downexit 1else# If the health check passes, prompt the user to press any key to tear down the serviceread -n 1 -s -r -p "Health check passed. Press any key to tear down the service."echo "" # Move to a new line# Tear down the servicedocker-compose -f "$compose_file" downfi# Tear down the service after the health check passes#docker-compose -f "$compose_file" downfi}# Main functionmain() {SECONDS=0parse_args "$@"build_and_testecho "All operations completed in $SECONDS seconds."}main "$@"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。