-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
52 lines (38 loc) · 1.21 KB
/
Dockerfile
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Dynamic Builds
ARG BUILDER_IMAGE=golang:1.23-bookworm
ARG FINAL_IMAGE=debian:bookworm-slim
# Build stage
FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE} AS builder
# Build Args
ARG GIT_REVISION=""
# Platform args
ARG TARGETOS
ARG TARGETARCH
# Ensure ca-certificates are up to date
RUN update-ca-certificates
# Use modules for dependencies
WORKDIR $GOPATH/src/go.rtnl.ai/vanity
COPY go.mod .
COPY go.sum .
ENV CGO_ENABLED=0
ENV GO111MODULE=on
RUN go mod download
RUN go mod verify
# Copy package
COPY . .
# Build binary
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags="-X 'go.rtnl.ai/vanity.GitVersion=${GIT_REVISION}'" \
-o /go/bin/vanityd \
./cmd/vanityd
# Final Stage
FROM --platform=${BUILDPLATFORM} ${FINAL_IMAGE} AS final
LABEL maintainer="Rotational Labs <[email protected]>"
LABEL description="Rotational Vanity URLs server for go modules"
# Ensure ca-certificates are up to date
RUN set -x && apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Copy the binary to the production image from the builder stage
COPY --from=builder /go/bin/vanityd /usr/local/bin/vanityd
CMD [ "/usr/local/bin/vanityd", "serve" ]