-
Notifications
You must be signed in to change notification settings - Fork 15
/
Dockerfile
37 lines (27 loc) · 1.02 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
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18 as build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG GO111MODULE
ENV CGO_ENABLED=0
ARG GIT_COMMIT
ARG VERSION
WORKDIR /go/src/github.com/openfaas/nats-connector
COPY go.mod .
COPY go.sum .
COPY config config
COPY version version
COPY nats nats
COPY main.go .
# Run a gofmt and exclude all vendored code.
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))"
RUN go test -v ./...
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -ldflags "-s -w" -installsuffix cgo \
--ldflags "-s -w -X 'github.com/openfaas/nats-connector/version.GitCommit=${GIT_COMMIT}' -X 'github.com/openfaas/nats-connector/version.Version=${VERSION}'" \
-a -installsuffix cgo -o /usr/bin/connector
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.2 as ship
RUN apk add --no-cache ca-certificates
COPY --from=build /usr/bin/connector /usr/bin/connector
WORKDIR /root/
CMD ["/usr/bin/connector"]