Log times in local timezone, run as unprivileged user in Docker image, shrink Docker image

This commit is contained in:
Matthew Edwards
2019-10-03 19:49:59 +13:00
parent 7eb8ce016f
commit f47dec6ad3
2 changed files with 15 additions and 5 deletions
+11 -5
View File
@@ -1,6 +1,8 @@
ARG GO_VERSION=1.13
FROM golang:${GO_VERSION} AS builder
RUN useradd ztdns
WORKDIR /go/src/github.com/mje-nz/ztdns
# Fetch and cache dependencies
@@ -9,18 +11,22 @@ RUN go mod download
# Build static binary
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go install
RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-w -s"
FROM alpine:3.10
FROM scratch
# We need to add ca-certificates in order to make HTTPS API calls
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
# We need ca-certificates for HTTPS, /etc/passwd to log in, and zoneinfo for
# time zones
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
WORKDIR /app
# Copy binary
COPY --from=builder /go/bin/ztdns .
USER ztdns
ENTRYPOINT ["./ztdns"]
CMD ["server"]
EXPOSE 53/udp
+4
View File
@@ -75,6 +75,10 @@ var serverCmd = &cobra.Command{
}
func init() {
log.SetFormatter(&log.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05 -07:00",
})
RootCmd.AddCommand(serverCmd)
serverCmd.Flags().String("interface", "zt0", "network interface to bind to")
serverCmd.Flags().Int("port", 53, "port to listen on")