# Use a Rust image for building the application
FROM rust:1-bookworm as builder

WORKDIR /app

# Create a dummy main.rs to build dependencies
# This layer is cached if Cargo.toml and Cargo.lock don't change
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release --locked

# Copy the actual source code
COPY src ./src

# Touch the main file to force a rebuild of the application
RUN touch src/main.rs
RUN cargo build --release --locked

# Use a minimal base image for the final stage
FROM gcr.io/distroless/cc-debian12

# Set the working directory
WORKDIR /app

# Copy the compiled binary from the builder stage
COPY --from=builder /app/target/release/ltping .

# Run the application
ENTRYPOINT ["./ltping"]
CMD ["8.8.8.8"]

