# Define argument for linker flags
ARG LDFLAGS=-s -w

# Use a temporary build image based on Golang 1.20-alpine
FROM golang:1.22-alpine as builder

# Set environment variables: linker flags and disable CGO
ENV LDFLAGS=$LDFLAGS CGO_ENABLED=0

# Install git and build the edgevpn binary with the provided linker flags
# --no-cache flag ensures the package cache isn't stored in the layer, reducing image size
RUN apk add --no-cache git

# Add the current directory contents to the work directory in the container
COPY . /work

# Set the current work directory inside the container
WORKDIR /work

RUN go build -ldflags="$LDFLAGS" -o webui ./example/webui

FROM scratch

# Copy the webui binary from the builder stage to the final image
COPY --from=builder /work/webui /webui
COPY --from=builder /etc/ssl/ /etc/ssl/

# Define the command that will be run when the container is started
ENTRYPOINT ["/webui"]