custom-nas/build.sh

37 lines
994 B
Bash
Executable File

#!/usr/bin/env bash
set -e
# Configuration with smart defaults (overridable via environment variables)
REGISTRY=${REGISTRY:-"quay.atyg.org"}
NAMESPACE=${NAMESPACE:-"library"}
IMAGE_NAME=${IMAGE_NAME:-"custom-nas-web"}
TAG=${TAG:-"latest"}
FULL_IMAGE_NAME="$REGISTRY/$NAMESPACE/$IMAGE_NAME:$TAG"
# Auto-detect container engine (podman or docker)
if command -v podman &> /dev/null; then
ENGINE="podman"
elif command -v docker &> /dev/null; then
ENGINE="docker"
else
echo "❌ Error: Neither podman nor docker found in PATH."
exit 1
fi
echo "🚀 Building image using $ENGINE..."
echo "📦 Target: $FULL_IMAGE_NAME"
# Build the image
$ENGINE build -t "$FULL_IMAGE_NAME" .
# Handle optional push flag
if [[ "$1" == "--push" || "$2" == "--push" ]]; then
echo "☁️ Pushing to registry..."
$ENGINE push "$FULL_IMAGE_NAME"
echo "✅ Push complete!"
else
echo "✅ Build complete!"
echo "💡 Tip: To build and push in one step, run: ./build.sh --push"
fi