# syntax=docker/dockerfile:1

# Build the application from source
FROM golang:1.21 AS build-stage

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY cmd ./cmd
COPY internal ./internal
COPY pkg ./pkg
COPY gen ./gen

RUN CGO_ENABLED=0 GOOS=linux go build -o /signaler ./cmd/signaler

# Run the tests in the container
FROM build-stage AS run-test-stage
RUN go test -v ./...

# Deploy the application binary into a lean image
FROM golang:1.21 AS build-release-stage

WORKDIR /
COPY --from=build-stage /signaler /
COPY server.crt /server.crt
COPY server.key /server.key

EXPOSE 8080

ENTRYPOINT ["/signaler"]