# Etapa de compilación
FROM golang:1.23.1-bookworm AS builder

ENV TZ=Europe/Madrid

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD celsa2048.crt /usr/local/share/ca-certificates/celsa2048.crt
RUN chmod 644 /usr/local/share/ca-certificates/celsa2048.crt
RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates

RUN update-ca-certificates
WORKDIR /app

COPY . .

RUN go get -d -v ./...

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=mod -ldflags "-s -w" -o cml04-falcon-ui main.go

# Etapa de producción

FROM debian:stable
ENV TZ=Europe/Madrid

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD celsa2048.crt /usr/local/share/ca-certificates/celsa2048.crt
RUN chmod 644 /usr/local/share/ca-certificates/celsa2048.crt
RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates
ADD assets /root/assets
ADD templates /root/templates
RUN update-ca-certificates
WORKDIR /root/

COPY --from=builder /app/cml04-falcon-ui .

CMD ["./cml04-falcon-ui"]