94 lines
2.9 KiB
Bash
Executable File
94 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# docker-build.sh — Baut negative-converter in Docker
|
|
#
|
|
# Verwendung:
|
|
# ./scripts/docker-build.sh [linux|windows|all] [--no-cache] [--run]
|
|
#
|
|
# Optionen:
|
|
# linux Linux CLI-Build (Standard)
|
|
# windows Windows Cross-Compilation via MXE
|
|
# all Beide Targets bauen
|
|
# --no-cache Docker-Cache ignorieren
|
|
# --run Nach dem Build direkt ausführen (nur linux)
|
|
|
|
set -euo pipefail
|
|
|
|
RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; NC='\033[0m'
|
|
log_info() { echo -e "${BLUE}[docker]${NC} $*"; }
|
|
log_ok() { echo -e "${GREEN}[ok]${NC} $*"; }
|
|
log_error(){ echo -e "${RED}[error]${NC} $*"; exit 1; }
|
|
|
|
TARGET="linux"
|
|
NO_CACHE=""
|
|
RUN_AFTER=0
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
linux) TARGET="linux" ;;
|
|
windows) TARGET="windows" ;;
|
|
all) TARGET="all" ;;
|
|
--no-cache) NO_CACHE="--no-cache" ;;
|
|
--run) RUN_AFTER=1 ;;
|
|
--help|-h) sed -n '2,9p' "$0" | sed 's/^# \?//'; exit 0 ;;
|
|
*) log_error "Unbekannte Option: $arg" ;;
|
|
esac
|
|
done
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
cd "$PROJECT_ROOT"
|
|
|
|
command -v docker &>/dev/null || log_error "Docker nicht gefunden. Installieren: https://docs.docker.com/get-docker/"
|
|
|
|
mkdir -p output dist-windows
|
|
|
|
build_linux() {
|
|
log_info "Baue Linux-Image (negative-converter:linux) ..."
|
|
docker build $NO_CACHE \
|
|
--target linux-builder \
|
|
-t negative-converter:linux \
|
|
-f docker/Dockerfile \
|
|
.
|
|
log_ok "Linux-Image gebaut"
|
|
|
|
if [[ $RUN_AFTER -eq 1 ]]; then
|
|
log_info "Starte Konvertierung ..."
|
|
docker run --rm \
|
|
-v "$PROJECT_ROOT/import:/project/import:ro" \
|
|
-v "$PROJECT_ROOT/output:/project/output" \
|
|
-v "$PROJECT_ROOT/config.ini:/project/config.ini:ro" \
|
|
negative-converter:linux \
|
|
--batch --config config.ini
|
|
log_ok "Konvertierung abgeschlossen. Ergebnisse in: output/"
|
|
fi
|
|
}
|
|
|
|
build_windows() {
|
|
log_info "Baue Windows-Cross-Compilation-Image (negative-converter:windows-builder) ..."
|
|
log_info "Hinweis: Erster Build lädt ~3 GB MXE-Pakete herunter (~20-30 Min)"
|
|
docker build $NO_CACHE \
|
|
--target windows-builder \
|
|
-t negative-converter:windows-builder \
|
|
-f docker/Dockerfile \
|
|
.
|
|
log_ok "Windows-Builder-Image gebaut"
|
|
|
|
log_info "Extrahiere negative-converter.exe ..."
|
|
mkdir -p dist-windows
|
|
docker run --rm \
|
|
-v "$PROJECT_ROOT/dist-windows:/project/dist-windows" \
|
|
negative-converter:windows-builder \
|
|
-c "cp -r /project/dist-windows/. /project/dist-windows/ && echo 'Fertig'"
|
|
|
|
log_ok "Windows-Build abgeschlossen: dist-windows/"
|
|
ls -lh dist-windows/bin/ 2>/dev/null || true
|
|
}
|
|
|
|
case "$TARGET" in
|
|
linux) build_linux ;;
|
|
windows) build_windows ;;
|
|
all) build_linux; build_windows ;;
|
|
esac
|
|
|
|
log_ok "Fertig."
|