- Creating a specialized Form class for handling dynamic fields - Refinement of HTML-macros to handle dynamic fields - Introduction of dynamic fields for Catalogs
173 lines
4.6 KiB
Bash
Executable File
173 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Exit on any error
|
|
set -e
|
|
|
|
. ./docker_env_switch.sh dev
|
|
|
|
# Load environment variables
|
|
source .env
|
|
|
|
# Docker registry
|
|
REGISTRY="josakola"
|
|
|
|
# Tag (you might want to use a version or git commit hash)
|
|
TAG="latest"
|
|
|
|
# Platforms to build for
|
|
PLATFORMS="linux/amd64,linux/arm64"
|
|
|
|
# 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 (for current platform)"
|
|
echo " -p: Push only (multi-platform)"
|
|
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."
|
|
}
|
|
|
|
# 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
|
|
|
|
# Build and/or push based on ACTION
|
|
if [ "$ACTION" = "build" ]; then
|
|
echo "Building $SERVICE for current platform..."
|
|
docker build \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
-t "$REGISTRY/$SERVICE:$TAG" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT"
|
|
elif [ "$ACTION" = "push" ]; then
|
|
echo "Building and pushing $SERVICE for multiple platforms..."
|
|
docker buildx build \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
--platform "$PLATFORMS" \
|
|
-t "$REGISTRY/$SERVICE:$TAG" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT" \
|
|
--push
|
|
else
|
|
echo "Building $SERVICE for current platform..."
|
|
docker build \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
-t "$REGISTRY/$SERVICE:$TAG" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT"
|
|
|
|
echo "Building and pushing $SERVICE for multiple platforms..."
|
|
docker buildx build \
|
|
$NO_CACHE \
|
|
$PROGRESS \
|
|
$DEBUG \
|
|
--platform "$PLATFORMS" \
|
|
-t "$REGISTRY/$SERVICE:$TAG" \
|
|
-f "$CONTEXT/$DOCKERFILE" \
|
|
"$CONTEXT" \
|
|
--push
|
|
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)')
|
|
else
|
|
SERVICES=("$@")
|
|
fi
|
|
|
|
# Check if eveai_builder exists, if not create it
|
|
if ! docker buildx inspect eveai_builder > /dev/null 2>&1; then
|
|
echo "Creating eveai_builder..."
|
|
docker buildx create --name eveai_builder
|
|
fi
|
|
|
|
# Use eveai_builder
|
|
echo "Using eveai_builder..."
|
|
docker buildx use eveai_builder
|
|
|
|
# Loop through services
|
|
for SERVICE in "${SERVICES[@]}"; do
|
|
if [[ "$SERVICE" == "nginx" || "$SERVICE" == eveai_* || "$SERVICE" == "flower" ]]; 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 or doesn't start with eveai_"
|
|
fi
|
|
done
|
|
|
|
echo "All specified services processed."
|
|
echo "Finished at $(date +"%d/%m/%Y %H:%M:%S")" |