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:
11
Dockerfile
11
Dockerfile
@@ -27,12 +27,12 @@ RUN apk add --no-cache \
|
|||||||
# Install musl-dev for Rust musl targeting (Alpine handles this differently than rustup)
|
# Install musl-dev for Rust musl targeting (Alpine handles this differently than rustup)
|
||||||
RUN apk add --no-cache musl-dev
|
RUN apk add --no-cache musl-dev
|
||||||
|
|
||||||
# Create non-root user for builds
|
# Create non-root user for builds matching host user
|
||||||
RUN adduser -D -s /bin/bash builder && \
|
RUN adduser -D -s /bin/bash builder
|
||||||
chown -R builder:builder /home/builder
|
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory with proper permissions
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
RUN chown builder:builder /workspace
|
||||||
|
|
||||||
# Set environment variables for musl static linking with Alpine's Rust
|
# Set environment variables for musl static linking with Alpine's Rust
|
||||||
ENV RUSTFLAGS="-C target-feature=+crt-static -C linker=musl-gcc"
|
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 TARGET_CC="musl-gcc"
|
||||||
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="musl-gcc"
|
||||||
|
|
||||||
# Default to builder user
|
# Don't switch to builder user yet - let the runtime handle it
|
||||||
USER builder
|
|
||||||
|
|
||||||
CMD ["/bin/bash"]
|
CMD ["/bin/bash"]
|
||||||
@@ -52,8 +52,6 @@ Zero OS Alpine Initramfs Builder
|
|||||||
Usage: $0 [OPTIONS]
|
Usage: $0 [OPTIONS]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--container Force container build
|
|
||||||
--no-container Force native build
|
|
||||||
--clean Clean build (remove all artifacts first)
|
--clean Clean build (remove all artifacts first)
|
||||||
--skip-tests Skip boot tests
|
--skip-tests Skip boot tests
|
||||||
--keep-artifacts Keep build artifacts after completion
|
--keep-artifacts Keep build artifacts after completion
|
||||||
@@ -78,14 +76,6 @@ EOF
|
|||||||
function parse_arguments() {
|
function parse_arguments() {
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--container)
|
|
||||||
USE_CONTAINER="true"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--no-container)
|
|
||||||
USE_CONTAINER="false"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--clean)
|
--clean)
|
||||||
CLEAN_BUILD="true"
|
CLEAN_BUILD="true"
|
||||||
shift
|
shift
|
||||||
@@ -286,26 +276,29 @@ function main() {
|
|||||||
# Setup environment
|
# Setup environment
|
||||||
setup_build_environment
|
setup_build_environment
|
||||||
|
|
||||||
# Determine build method
|
# Always use container builds for consistency
|
||||||
if [[ "$USE_CONTAINER" == "auto" ]]; then
|
|
||||||
if in_container; then
|
if in_container; then
|
||||||
log_info "Already in container, using native build"
|
log_info "Already in container, proceeding with build"
|
||||||
main_build_process
|
main_build_process
|
||||||
elif command_exists "podman" || command_exists "docker"; then
|
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_detect_runtime
|
||||||
docker_build_container
|
docker_build_container
|
||||||
docker_run_build "./scripts/build.sh --no-container"
|
|
||||||
else
|
# Pass through relevant arguments to container
|
||||||
log_info "No container runtime, using native build"
|
local container_args=""
|
||||||
main_build_process
|
if [[ "$SKIP_TESTS" == "true" ]]; then
|
||||||
|
container_args="$container_args --skip-tests"
|
||||||
fi
|
fi
|
||||||
elif [[ "$USE_CONTAINER" == "true" ]]; then
|
if [[ "$KEEP_ARTIFACTS" == "true" ]]; then
|
||||||
docker_detect_runtime
|
container_args="$container_args --keep-artifacts"
|
||||||
docker_build_container
|
fi
|
||||||
docker_run_build "./scripts/build.sh --no-container"
|
|
||||||
|
docker_run_build "./scripts/build.sh${container_args}"
|
||||||
else
|
else
|
||||||
main_build_process
|
log_error "Container runtime required (podman or docker)"
|
||||||
|
log_error "Install with: apt-get install podman"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup if requested
|
# Cleanup if requested
|
||||||
|
|||||||
Reference in New Issue
Block a user