191 lines
5.5 KiB
Bash
Executable File
191 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Exit on any error
|
|
set -e
|
|
|
|
source ./podman_env_switch.sh dev
|
|
|
|
# Load environment variables
|
|
source .env
|
|
|
|
# Check if podman is available
|
|
if ! command -v podman &> /dev/null; then
|
|
echo "Error: podman not found"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Using container runtime: podman"
|
|
|
|
# Local registry
|
|
REGISTRY="registry.ask-eve-ai-local.com"
|
|
# Account prefix voor consistency met Docker Hub
|
|
ACCOUNT="josakola"
|
|
|
|
# Tag (you might want to use a version or git commit hash)
|
|
TAG="latest"
|
|
|
|
# Single platform - AMD64 only for simplicity
|
|
PLATFORM="linux/amd64"
|
|
|
|
# Default action
|
|
ACTION="both"
|
|
|
|
# Default build options
|
|
NO_CACHE=""
|
|
PROGRESS=""
|
|
DEBUG=""
|
|
|
|
# Function to display usage information
|
|
usage() {
|
|
echo "Usage: $0 [-b|-p] [--no-cache] [--progress=plain] [--debug] [service1 service2 ...]"
|
|
echo " -b: Build only"
|
|
echo " -p: Push only"
|
|
echo " --no-cache: Perform a clean build without using cache"
|
|
echo " --progress=plain: Show detailed progress of the build"
|
|
echo " --debug: Enable debug mode for the build"
|
|
echo " If no option is provided, both build and push will be performed."
|
|
echo " If no services are specified, all eveai_ services and nginx will be processed."
|
|
echo " All images are built for AMD64 platform (compatible with both x86_64 and Apple Silicon via emulation)."
|
|
}
|
|
|
|
# Parse command-line options
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-b)
|
|
ACTION="build"
|
|
shift
|
|
;;
|
|
-p)
|
|
ACTION="push"
|
|
shift
|
|
;;
|
|
--no-cache)
|
|
NO_CACHE="--no-cache"
|
|
shift
|
|
;;
|
|
--progress=plain)
|
|
PROGRESS="--progress=plain"
|
|
shift
|
|
;;
|
|
--debug)
|
|
DEBUG="--debug"
|
|
shift
|
|
;;
|
|
-*)
|
|
echo "Unknown option: $1"
|
|
usage
|
|
exit 1
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Function to build and/or push a service
|
|
process_service() {
|
|
local SERVICE="$1"
|
|
echo "Processing $SERVICE..."
|
|
|
|
# Extract the build context and dockerfile from the compose file
|
|
CONTEXT=$(yq e ".services.$SERVICE.build.context" compose_dev.yaml)
|
|
DOCKERFILE=$(yq e ".services.$SERVICE.build.dockerfile" compose_dev.yaml)
|
|
|
|
# Check if context directory exists
|
|
if [ ! -d "$CONTEXT" ]; then
|
|
echo "Error: Build context directory '$CONTEXT' for service '$SERVICE' does not exist."
|
|
return 1
|
|
fi
|
|
|
|
# Check if Dockerfile exists
|
|
if [ ! -f "$CONTEXT/$DOCKERFILE" ]; then
|
|
echo "Error: Dockerfile '$DOCKERFILE' for service '$SERVICE' does not exist in context '$CONTEXT'."
|
|
return 1
|
|
fi
|
|
|
|
# Construct image names
|
|
LOCAL_IMAGE_NAME="$ACCOUNT/$SERVICE:$TAG"
|
|
REGISTRY_IMAGE_NAME="$REGISTRY/$ACCOUNT/$SERVICE:$TAG"
|
|
|
|
echo "Building for platform: $PLATFORM"
|
|
echo "Local tag: $LOCAL_IMAGE_NAME"
|
|
echo "Registry tag: $REGISTRY_IMAGE_NAME"
|
|
|
|
# Build and/or push based on ACTION
|
|
if [ "$ACTION" = "build" ]; then
|
|
echo "Building $SERVICE for $PLATFORM..."
|
|
podman build \
|
|
--platform "$PLATFORM" \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
-t "$LOCAL_IMAGE_NAME" \
|
|
-t "$REGISTRY_IMAGE_NAME" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT"
|
|
|
|
elif [ "$ACTION" = "push" ]; then
|
|
echo "Building and pushing $SERVICE for $PLATFORM..."
|
|
podman build \
|
|
--platform "$PLATFORM" \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
-t "$LOCAL_IMAGE_NAME" \
|
|
-t "$REGISTRY_IMAGE_NAME" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT"
|
|
|
|
echo "Pushing $SERVICE to registry..."
|
|
podman push "$REGISTRY_IMAGE_NAME"
|
|
|
|
else
|
|
# Both build and push
|
|
echo "Building $SERVICE for $PLATFORM..."
|
|
podman build \
|
|
--platform "$PLATFORM" \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
-t "$LOCAL_IMAGE_NAME" \
|
|
-t "$REGISTRY_IMAGE_NAME" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT"
|
|
|
|
echo "Pushing $SERVICE to registry..."
|
|
podman push "$REGISTRY_IMAGE_NAME"
|
|
fi
|
|
}
|
|
|
|
# If no arguments are provided, process all services
|
|
if [ $# -eq 0 ]; then
|
|
SERVICES=()
|
|
while IFS= read -r line; do
|
|
SERVICES+=("$line")
|
|
done < <(yq e '.services | keys | .[]' compose_dev.yaml | grep -E '^(nginx|eveai_|flower|prometheus|grafana)')
|
|
else
|
|
SERVICES=("$@")
|
|
fi
|
|
|
|
echo "Using simplified AMD64-only approach for maximum compatibility..."
|
|
echo "Images will be tagged as: $REGISTRY/$ACCOUNT/[service]:$TAG"
|
|
|
|
# Loop through services
|
|
for SERVICE in "${SERVICES[@]}"; do
|
|
if [[ "$SERVICE" == "nginx" ]]; then
|
|
./copy_specialist_svgs.sh ../config ../nginx/static/assets 2>/dev/null || echo "Warning: copy_specialist_svgs.sh not found or failed"
|
|
fi
|
|
if [[ "$SERVICE" == "nginx" || "$SERVICE" == eveai_* || "$SERVICE" == "flower" || "$SERVICE" == "prometheus" || "$SERVICE" == "grafana" ]]; then
|
|
if process_service "$SERVICE"; then
|
|
echo "✅ Successfully processed $SERVICE"
|
|
else
|
|
echo "❌ Failed to process $SERVICE"
|
|
fi
|
|
else
|
|
echo "⏭️ Skipping $SERVICE as it's not nginx, flower, prometheus, grafana or doesn't start with eveai_"
|
|
fi
|
|
done
|
|
|
|
echo -e "\033[32m✅ All specified services processed successfully!\033[0m"
|
|
echo -e "\033[32m📦 Images are available locally and in registry\033[0m"
|
|
echo -e "\033[32m🕐 Finished at $(date +"%d/%m/%Y %H:%M:%S")\033[0m" |