# syntax=docker/dockerfile:1

FROM golang:1.24-alpine AS builder

WORKDIR /workspace/iop
RUN apk add --no-cache git

# docker-compose builds this Dockerfile with /config/workspace as context so
# the local ../proto-socket/go replace in go.mod is available.
COPY iop/go.mod iop/go.sum ./
COPY proto-socket/go /workspace/proto-socket/go
RUN go mod download

COPY iop/ ./
RUN CGO_ENABLED=0 GOFLAGS=-trimpath go build -o /out/edge ./apps/edge/cmd/edge

FROM alpine:3.22

RUN apk add --no-cache gettext && addgroup -S iop && adduser -S iop -G iop
WORKDIR /app

COPY --from=builder /out/edge /usr/local/bin/edge
COPY --from=builder /workspace/iop/configs/edge-compose.yaml.tmpl /app/configs/edge-compose.yaml.tmpl

EXPOSE 9090

USER iop
ENTRYPOINT ["/bin/sh", "-c"]
CMD ["envsubst < /app/configs/edge-compose.yaml.tmpl > /tmp/edge-compose.yaml && exec edge serve --config /tmp/edge-compose.yaml"]
