-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile.dev
37 lines (29 loc) · 1.26 KB
/
Dockerfile.dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
FROM golang:1.19 as builder
# Create and change to the app directory.
WORKDIR /app
# Retrieve application dependencies using go modules.
# Allows container builds to reuse downloaded dependencies.
COPY go.* ./
RUN go mod download
# Copy local code to the container image.
COPY . ./
RUN go mod tidy
# Build the binary.
# -mod=readonly ensures immutable go.mod and go.sum in container builds.
RUN export LDFLAG_LOCATION="go.infratographer.com/x/versionx" && \
CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o serverservice \
-ldflags \
"-X ${LDFLAG_LOCATION}.appName=serverservice \
-X ${LDFLAG_LOCATION}.commit=$(git rev-parse --short HEAD) \
-X ${LDFLAG_LOCATION}.version=$(git describe --tags 2>/dev/null) \
-X ${LDFLAG_LOCATION}.date=$(date -u '+%H:%M:%S-%Y-%m-%d')"
# Use the official Alpine image for a lean production container.
# https://hub.docker.com/_/alpine
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine:3.18.3
RUN apk add --no-cache ca-certificates
# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/serverservice /serverservice
# Run the web service on container startup.
ENTRYPOINT ["/serverservice"]
CMD ["serve"]