refactor: Container-only builds for consistency

- Remove --no-container option (never build on real host)
- Simplify build.sh to always use containers
- Fix Dockerfile user permissions
- Update help text and argument parsing
- Pass arguments correctly to container builds
This commit is contained in:
2025-08-31 12:58:30 +02:00
parent 1db6185454
commit 6fbaa95725
2 changed files with 25 additions and 33 deletions

View File

@@ -27,12 +27,12 @@ RUN apk add --no-cache \
# Install musl-dev for Rust musl targeting (Alpine handles this differently than rustup)
RUN apk add --no-cache musl-dev
# Create non-root user for builds
RUN adduser -D -s /bin/bash builder && \
chown -R builder:builder /home/builder
# Create non-root user for builds matching host user
RUN adduser -D -s /bin/bash builder
# Set working directory
# Set working directory with proper permissions
WORKDIR /workspace
RUN chown builder:builder /workspace
# Set environment variables for musl static linking with Alpine's Rust
ENV RUSTFLAGS="-C target-feature=+crt-static -C linker=musl-gcc"
@@ -40,7 +40,6 @@ ENV CC="musl-gcc"
ENV TARGET_CC="musl-gcc"
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
# Default to builder user
USER builder
# Don't switch to builder user yet - let the runtime handle it
CMD ["/bin/bash"]

View File

@@ -52,8 +52,6 @@ Zero OS Alpine Initramfs Builder
Usage: $0 [OPTIONS]
Options:
--container Force container build
--no-container Force native build
--clean Clean build (remove all artifacts first)
--skip-tests Skip boot tests
--keep-artifacts Keep build artifacts after completion
@@ -78,14 +76,6 @@ EOF
function parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
--container)
USE_CONTAINER="true"
shift
;;
--no-container)
USE_CONTAINER="false"
shift
;;
--clean)
CLEAN_BUILD="true"
shift
@@ -286,26 +276,29 @@ function main() {
# Setup environment
setup_build_environment
# Determine build method
if [[ "$USE_CONTAINER" == "auto" ]]; then
# Always use container builds for consistency
if in_container; then
log_info "Already in container, using native build"
log_info "Already in container, proceeding with build"
main_build_process
elif command_exists "podman" || command_exists "docker"; then
log_info "Container runtime available, using container build"
log_info "Starting container build"
docker_detect_runtime
docker_build_container
docker_run_build "./scripts/build.sh --no-container"
else
log_info "No container runtime, using native build"
main_build_process
# Pass through relevant arguments to container
local container_args=""
if [[ "$SKIP_TESTS" == "true" ]]; then
container_args="$container_args --skip-tests"
fi
elif [[ "$USE_CONTAINER" == "true" ]]; then
docker_detect_runtime
docker_build_container
docker_run_build "./scripts/build.sh --no-container"
if [[ "$KEEP_ARTIFACTS" == "true" ]]; then
container_args="$container_args --keep-artifacts"
fi
docker_run_build "./scripts/build.sh${container_args}"
else
main_build_process
log_error "Container runtime required (podman or docker)"
log_error "Install with: apt-get install podman"
return 1
fi
# Cleanup if requested