FROM golang:1.23-alpine AS builder

WORKDIR /app

COPY ./gateway/src/go.mod ./gateway/src/go.sum ./
RUN go mod tidy

COPY ./gateway/src .
#RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /gateway .
RUN go build -o /gateway .


FROM alpine:latest AS certs
RUN apk --no-cache add ca-certificates

FROM scratch AS final
LABEL   org.opencontainers.image.authors="remi.heredero@hevs.ch" \
        org.opencontainers.image.title="Gateway for SoftwEng course" \
        org.opencontainers.image.description="This container is an application for the lab on SoftwEng course" \
        org.opencontainers.image.source="https://gitlab.forge.hefr.ch/team-raclette/project-softweng/-/tree/main/gateway?ref_type=heads"

COPY --from=builder /gateway /gateway
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 8080

ENTRYPOINT ["/gateway"]