all repos — cameraman @ 3a770ca6153b7f66da3bdce12cae18c1bed29cfd

Dockerfile (view raw)

 1# syntax=docker/dockerfile:1
 2
 3FROM golang:alpine AS builder
 4
 5WORKDIR /build
 6
 7# Install gcc and musl-dev
 8RUN apk add --no-cache gcc musl-dev
 9
10# Download Go modules
11COPY go.mod go.sum ./
12RUN go mod download
13
14# Transfer source code
15COPY templates ./templates
16COPY *.go ./
17
18# Build
19RUN CGO_ENABLED=1 go build -ldflags='-s -w' -trimpath -o /dist/app
20RUN ldd /dist/app | tr -s [:blank:] '\n' | grep ^/ | xargs -I % install -D % /dist/%
21RUN ln -s ld-musl-x86_64.so.1 /dist/lib/libc.musl-x86_64.so.1
22
23# Test
24FROM builder AS run-test-stage
25RUN go test -v ./...
26
27FROM scratch AS build-release-stage
28
29COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
30COPY --from=builder /dist /
31
32ENTRYPOINT ["/app"]