- Added user mapping (UID:GID) to Docker Compose services to prevent root-owned files - Export current user's UID/GID in build.sh for Docker Compose - Enhanced clean build to handle permission issues gracefully: * Try normal cleanup first * Fallback to container-based cleanup for root-owned files * Ultimate fallback to sudo if needed - Added cleanup for all Docker volumes (build, source, kernel, target caches) Fixes 'Permission denied' errors when cleaning output files created by Docker containers.
138 lines
4.2 KiB
YAML
138 lines
4.2 KiB
YAML
services:
|
|
# Cached builder using multi-stage Dockerfile
|
|
builder:
|
|
build:
|
|
context: ..
|
|
dockerfile: build/Dockerfile.cached
|
|
target: final-builder
|
|
args:
|
|
BUILDMODE: "${BUILDMODE:-debug}"
|
|
TARGETARCH: "${TARGETARCH:-amd64}"
|
|
MINIMAL_MODE: "${MINIMAL_MODE:-false}"
|
|
image: zero-os-alpine-builder:cached-${BUILDMODE:-debug}
|
|
container_name: zero-os-alpine-builder-cached
|
|
privileged: true
|
|
user: "${UID:-1000}:${GID:-1000}"
|
|
volumes:
|
|
# Mount source configs and scripts (read-only for cache efficiency)
|
|
- ../configs:/build/configs:ro
|
|
- ../scripts:/build/scripts:ro
|
|
# Mount Zero-OS components (writable for cargo build)
|
|
- ../components:/build/components
|
|
# Mount output directory
|
|
- ../output:/build/output
|
|
# Persistent cache directories for maximum caching
|
|
- build-cache:/build/cache
|
|
- source-cache:/build/source
|
|
- kernel-cache:/build/kernel
|
|
# Mount existing zinit config from main project
|
|
- ../configs/zinit:/mnt/zinit:ro
|
|
environment:
|
|
- BUILDMODE=${BUILDMODE:-debug}
|
|
- TARGETARCH=${TARGETARCH:-amd64}
|
|
- MINIMAL_MODE=${MINIMAL_MODE:-false}
|
|
working_dir: /build
|
|
command: ["/build/scripts/build-smart.sh"]
|
|
|
|
# Legacy builder for comparison/fallback
|
|
builder-legacy:
|
|
build:
|
|
context: ..
|
|
dockerfile: build/Dockerfile.alpine
|
|
args:
|
|
BUILDMODE: "${BUILDMODE:-debug}"
|
|
TARGETARCH: "${TARGETARCH:-amd64}"
|
|
MINIMAL_MODE: "${MINIMAL_MODE:-false}"
|
|
image: zero-os-alpine-builder:legacy
|
|
container_name: zero-os-alpine-builder-legacy
|
|
privileged: true
|
|
user: "${UID:-1000}:${GID:-1000}"
|
|
volumes:
|
|
- ../configs:/build/configs:ro
|
|
- ../scripts:/build/scripts:ro
|
|
- ../components:/build/components
|
|
- ../output:/build/output
|
|
- github-cache:/build/github
|
|
- kernel-cache-legacy:/build/kernel
|
|
- ../configs/zinit:/mnt/zinit:ro
|
|
environment:
|
|
- BUILDMODE=${BUILDMODE:-debug}
|
|
- TARGETARCH=${TARGETARCH:-amd64}
|
|
- MINIMAL_MODE=${MINIMAL_MODE:-false}
|
|
working_dir: /build
|
|
command: ["/build/scripts/build-initramfs.sh"]
|
|
|
|
# Quick shell access for debugging (uses cached builder)
|
|
shell:
|
|
extends: builder
|
|
container_name: zero-os-alpine-shell
|
|
command: /bin/sh
|
|
stdin_open: true
|
|
tty: true
|
|
|
|
# Development shell with full caches
|
|
dev-shell:
|
|
extends: builder
|
|
container_name: zero-os-alpine-dev-shell
|
|
command: /bin/sh -l
|
|
stdin_open: true
|
|
tty: true
|
|
environment:
|
|
- PATH=/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
- CARGO_TARGET_DIR=/build/target-cache
|
|
volumes:
|
|
- ../configs:/build/configs
|
|
- ../scripts:/build/scripts
|
|
- ../components:/build/components
|
|
- ../output:/build/output
|
|
- build-cache:/build/cache
|
|
- source-cache:/build/source
|
|
- kernel-cache:/build/kernel
|
|
- target-cache:/build/target-cache
|
|
- ../configs/zinit:/mnt/zinit:ro
|
|
|
|
# Test build with minimal caching (for testing clean builds)
|
|
test:
|
|
extends: builder
|
|
container_name: zero-os-alpine-test
|
|
volumes:
|
|
- ../configs:/build/configs:ro
|
|
- ../scripts:/build/scripts:ro
|
|
- ../components:/build/components
|
|
- ../output:/build/output
|
|
- ../configs/zinit:/mnt/zinit:ro
|
|
environment:
|
|
- BUILDMODE=debug
|
|
- TARGETARCH=amd64
|
|
- MINIMAL_MODE=${MINIMAL_MODE:-false}
|
|
|
|
# Cache management service
|
|
cache-info:
|
|
extends: builder
|
|
container_name: zero-os-alpine-cache-info
|
|
command: |
|
|
sh -c "
|
|
echo 'Build Cache Information:'
|
|
echo 'Cache directory: /build/cache'
|
|
ls -la /build/cache/ 2>/dev/null || echo 'No cache markers found'
|
|
echo ''
|
|
echo 'Source cache: /build/source'
|
|
ls -la /build/source/ 2>/dev/null || echo 'No source cache found'
|
|
echo ''
|
|
echo 'Kernel cache: /build/kernel'
|
|
ls -la /build/kernel/ 2>/dev/null || echo 'No kernel cache found'
|
|
echo ''
|
|
echo 'Cache sizes:'
|
|
du -sh /build/cache /build/source /build/kernel 2>/dev/null || true
|
|
"
|
|
|
|
volumes:
|
|
# New cached volumes
|
|
build-cache:
|
|
source-cache:
|
|
kernel-cache:
|
|
target-cache:
|
|
|
|
# Legacy volumes (for fallback)
|
|
github-cache:
|
|
kernel-cache-legacy: |