# Ultra-optimized Alpine-based image for Woodpecker CI
# Size: ~400-500MB (vs 2.47GB original)
#
# Build: docker build -t your-registry/typedialog-ci:alpine -f .woodpecker/Dockerfile.alpine .
# Push: docker push your-registry/typedialog-ci:alpine

# Stage 1: Builder
FROM rust:1.92-alpine AS builder

# Install build dependencies
RUN apk add --no-cache \
    musl-dev \
    openssl-dev \
    openssl-libs-static \
    pkgconfig

# Set static linking for smaller binaries
ENV RUSTFLAGS="-C target-feature=+crt-static"

# Install Rust tools
RUN cargo install \
    cargo-audit \
    cargo-deny \
    cargo-sbom \
    nickel-lang-cli \
    nu \
    --locked

# Stage 2: Final image
FROM rust:1.92-alpine

# Install runtime dependencies
RUN apk add --no-cache \
    shellcheck \
    git \
    curl \
    ca-certificates \
    openssl \
    libgcc

# Install just
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | sh -s -- --to /usr/local/bin

# Install Rust components
RUN rustup component add clippy rustfmt

# Copy compiled binaries from builder
COPY --from=builder /usr/local/cargo/bin/cargo-audit /usr/local/cargo/bin/
COPY --from=builder /usr/local/cargo/bin/cargo-deny /usr/local/cargo/bin/
COPY --from=builder /usr/local/cargo/bin/cargo-sbom /usr/local/cargo/bin/
COPY --from=builder /usr/local/cargo/bin/nickel /usr/local/cargo/bin/
COPY --from=builder /usr/local/cargo/bin/nu /usr/local/cargo/bin/

# Set working directory
WORKDIR /workspace

# Verify installations
RUN just --version && \
    cargo --version && \
    cargo audit --version && \
    cargo deny --version && \
    cargo sbom --version && \
    nickel --version && \
    nu --version
