ARG GO_VERSION=1.24
FROM rust:bookworm AS rust-builder

WORKDIR /src/radial_sugiyama

COPY radial_sugiyama /src/radial_sugiyama

RUN cargo build --release --bin radial_sugiyama_go_bridge

FROM golang:${GO_VERSION}-alpine AS go-builder

WORKDIR /src/backend_go

COPY backend_go/go.mod /src/backend_go/go.mod

RUN go mod download

COPY backend_go /src/backend_go

RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/backend ./

FROM debian:bookworm-slim

RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=go-builder /out/backend /app/backend
COPY --from=rust-builder /src/radial_sugiyama/target/release/radial_sugiyama_go_bridge /app/radial_sugiyama_go_bridge

EXPOSE 8000

CMD ["/app/backend"]
