# syntax=docker/dockerfile:1
# Build the compose binary from source using a Debian-based Go image
# Base image aligned with the blueprint: golang:1.25.8-bookworm
FROM golang:1.25.8-bookworm AS build
WORKDIR /src
# Install required build tools and dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
clang \
file \
findutils \
git \
make \
protobuf-compiler \
libprotobuf-dev && \
rm -rf /var/lib/apt/lists/*
# Enable Go module caching and fetch dependencies first
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download
# Copy the full source code
COPY . .
# Build the project from source
# DESTDIR=/out will place the binary at /out/docker-compose
RUN --mount=type=cache,target=/root/.cache \
GO111MODULE=on \
make build DESTDIR=/out
# Runtime image containing the built binary
FROM debian:bookworm-slim AS runtime
WORKDIR /app
# Copy the docker-compose binary from the build stage
COPY --from=build /out/docker-compose /docker-compose
# Ensure the binary is runnable
RUN chmod +x /docker-compose
# Default entrypoint is the docker-compose binary
ENTRYPOINT ["/docker-compose"]