118 lines
3.2 KiB
Bash
Executable File
118 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
CARGO_VERSION=$(grep -m1 'version' "${PROJECT_ROOT}/Cargo.toml" | sed 's/.*"\(.*\)".*/\1/')
|
|
|
|
REGISTRY=${REGISTRY:-"harbor.gitdata.me/app"}
|
|
TAG=${TAG:-"${CARGO_VERSION:-latest}"}
|
|
PLATFORM=${PLATFORM:-"linux/amd64"}
|
|
TARGET_DIR=${CARGO_TARGET_DIR:-target}
|
|
|
|
if command -v podman &>/dev/null; then
|
|
DOCKER=podman
|
|
elif command -v docker &>/dev/null; then
|
|
DOCKER=docker
|
|
else
|
|
echo "ERROR: neither podman nor docker found"
|
|
exit 1
|
|
fi
|
|
|
|
RUST_BINS=("gitdata" "gitpod" "gitsync" "email-service")
|
|
ALL_SERVICES=("gitdata" "gitpod" "gitsync" "email" "web")
|
|
|
|
log_info() { echo -e "\033[0;32m[INFO]\033[0m $1"; }
|
|
log_error() { echo -e "\033[0;31m[ERROR]\033[0m $1"; }
|
|
|
|
build_rust() {
|
|
log_info "Building Rust binaries: $*"
|
|
cd "$PROJECT_ROOT"
|
|
cargo build --release "$@"
|
|
}
|
|
|
|
build_image() {
|
|
local service=$1
|
|
local dockerfile="${PROJECT_ROOT}/docker/${service}.Dockerfile"
|
|
local image_name="${REGISTRY}/gitdata-${service}"
|
|
|
|
log_info "Building image ${image_name}:${TAG}"
|
|
|
|
$DOCKER build \
|
|
-f "$dockerfile" \
|
|
-t "${image_name}:${TAG}" \
|
|
--platform "$PLATFORM" \
|
|
--build-arg TARGET_DIR="$TARGET_DIR" \
|
|
"$PROJECT_ROOT"
|
|
}
|
|
|
|
svc_to_bin() {
|
|
case $1 in
|
|
gitdata) echo "gitdata" ;;
|
|
gitpod) echo "gitpod" ;;
|
|
gitsync) echo "gitsync" ;;
|
|
email) echo "email-service" ;;
|
|
web) echo "" ;;
|
|
*) echo "" ;;
|
|
esac
|
|
}
|
|
|
|
BUILD_SERVICES=()
|
|
BUILD_ALL=true
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--tag|-t) TAG="$2"; shift 2 ;;
|
|
--registry|-r) REGISTRY="$2"; shift 2 ;;
|
|
--platform|-p) PLATFORM="$2"; shift 2 ;;
|
|
--help|-h)
|
|
echo "Usage: $0 [OPTIONS] [SERVICE...]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -t, --tag TAG Image tag (default: from Cargo.toml)"
|
|
echo " -r, --registry REG Registry prefix (default: harbor.gitdata.me/app)"
|
|
echo " -p, --platform PLAT Target platform (default: linux/amd64)"
|
|
echo ""
|
|
echo "Services:"
|
|
echo " gitdata gitpod gitsync email web"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 # Build all"
|
|
echo " $0 gitdata gitpod # Build specific services"
|
|
echo " $0 -t v1.2.0 # Build with custom tag"
|
|
echo " $0 -r myreg.io/app -t dev # Build with custom registry and tag"
|
|
exit 0
|
|
;;
|
|
*) BUILD_SERVICES+=("$1"); BUILD_ALL=false; shift ;;
|
|
esac
|
|
done
|
|
|
|
if [ "$BUILD_ALL" = true ]; then
|
|
log_info "Building all services (registry=${REGISTRY}, tag=${TAG})"
|
|
|
|
build_rust
|
|
|
|
for svc in "${ALL_SERVICES[@]}"; do
|
|
build_image "$svc"
|
|
done
|
|
else
|
|
log_info "Building services: ${BUILD_SERVICES[*]} (registry=${REGISTRY}, tag=${TAG})"
|
|
|
|
rust_bins=()
|
|
for svc in "${BUILD_SERVICES[@]}"; do
|
|
bin=$(svc_to_bin "$svc")
|
|
if [ -n "$bin" ]; then
|
|
rust_bins+=("--bin" "$bin")
|
|
fi
|
|
done
|
|
|
|
if [ ${#rust_bins[@]} -gt 0 ]; then
|
|
build_rust "${rust_bins[@]}"
|
|
fi
|
|
|
|
for svc in "${BUILD_SERVICES[@]}"; do
|
|
build_image "$svc"
|
|
done
|
|
fi
|
|
|
|
log_info "Done."
|