# Stage 1: build tippecanoe from source
FROM alpine:3.20 AS builder
RUN apk add --no-cache git g++ make sqlite-dev zlib-dev bash
RUN git clone --depth 1 https://github.com/felt/tippecanoe.git /src/tippecanoe
WORKDIR /src/tippecanoe
RUN make -j$(nproc) && make install

# Stage 2: runtime with GDAL + tippecanoe + mc
FROM ghcr.io/osgeo/gdal:alpine-normal-latest

COPY --from=builder /usr/local/bin/tippecanoe /usr/local/bin/tippecanoe
COPY --from=builder /usr/local/bin/tile-join /usr/local/bin/tile-join

# Install MinIO client
RUN apk add --no-cache curl bash && \
    curl -fsSL https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc && \
    chmod +x /usr/local/bin/mc

COPY scripts/rebuild-overview-tiles.sh /opt/rebuild.sh
RUN chmod +x /opt/rebuild.sh

ENTRYPOINT ["/opt/rebuild.sh"]
