Dockerfile 955 B

123456789101112131415161718192021222324252627282930
  1. # Define argument for linker flags
  2. ARG LDFLAGS=-s -w
  3. # Use a temporary build image based on Golang 1.20-alpine
  4. FROM golang:1.24-alpine as builder
  5. # Set environment variables: linker flags and disable CGO
  6. ENV LDFLAGS=$LDFLAGS CGO_ENABLED=0
  7. # Add the current directory contents to the work directory in the container
  8. ADD . /work
  9. # Set the current work directory inside the container
  10. WORKDIR /work
  11. # Install git and build the edgevpn binary with the provided linker flags
  12. # --no-cache flag ensures the package cache isn't stored in the layer, reducing image size
  13. RUN apk add --no-cache git && \
  14. go build -ldflags="$LDFLAGS" -o edgevpn
  15. # TODO: move to distroless
  16. # Use a new, clean alpine image for the final stage
  17. FROM alpine
  18. # Copy the edgevpn binary from the builder stage to the final image
  19. COPY --from=builder /work/edgevpn /usr/bin/edgevpn
  20. # Define the command that will be run when the container is started
  21. ENTRYPOINT ["/usr/bin/edgevpn"]