Files
logcorrelator/build.sh
2026-02-27 15:31:46 +01:00

76 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Build script - everything runs in Docker containers
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
VERSION="${VERSION:-1.0.0}"
OUTPUT_DIR="${SCRIPT_DIR}/dist"
echo "=============================================="
echo " logcorrelator - Docker Build Pipeline"
echo "=============================================="
echo ""
# Create output directory
mkdir -p "${OUTPUT_DIR}"
# Step 1: Build and test
echo "[1/4] Building and running tests in container..."
docker build \
--target builder \
-t logcorrelator-builder:latest \
-f Dockerfile .
# Step 2: Build runtime image
echo "[2/4] Building runtime image..."
docker build \
--target runtime \
-t logcorrelator:${VERSION} \
-t logcorrelator:latest \
-f Dockerfile .
# Step 3: Build packages (DEB + RPM)
echo "[3/4] Building DEB and RPM packages in container..."
docker build \
--target output \
--build-arg VERSION="${VERSION}" \
-t logcorrelator-packager:latest \
-f Dockerfile.package .
# Extract packages from builder container
echo "[4/4] Extracting packages..."
mkdir -p "${OUTPUT_DIR}/deb" "${OUTPUT_DIR}/rpm"
docker run --rm -v "${OUTPUT_DIR}:/output" logcorrelator-packager:latest \
sh -c 'cp -r /packages/deb /output/ && cp -r /packages/rpm /output/'
echo ""
echo "=============================================="
echo " Build Complete!"
echo "=============================================="
echo ""
echo "Artifacts:"
echo " - Runtime image: logcorrelator:${VERSION}"
echo " - DEB package: ${OUTPUT_DIR}/deb/logcorrelator_${VERSION}_amd64.deb"
echo " - RPM package: ${OUTPUT_DIR}/rpm/logcorrelator-${VERSION}-1.x86_64.rpm"
echo ""
echo "Usage:"
echo " # Run with Docker:"
echo " docker run -d --name logcorrelator \\"
echo " -v /var/run/logcorrelator:/var/run/logcorrelator \\"
echo " -v /var/log/logcorrelator:/var/log/logcorrelator \\"
echo " -v ./config.conf:/etc/logcorrelator/logcorrelator.conf \\"
echo " logcorrelator:latest"
echo ""
echo " # Install DEB on Debian/Ubuntu:"
echo " sudo dpkg -i ${OUTPUT_DIR}/deb/logcorrelator_${VERSION}_amd64.deb"
echo " sudo systemctl enable logcorrelator"
echo " sudo systemctl start logcorrelator"
echo ""
echo " # Install RPM on Rocky Linux:"
echo " sudo rpm -ivh ${OUTPUT_DIR}/rpm/logcorrelator-${VERSION}-1.x86_64.rpm"
echo " sudo systemctl enable logcorrelator"
echo " sudo systemctl start logcorrelator"
echo ""