-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
55 lines (42 loc) · 1.48 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
53
54
55
# syntax=docker/dockerfile:1.2
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.16.3-buster AS base
WORKDIR /src
# Install protobuf compilers
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
protobuf-compiler
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# Install dependencies
ENV CGO_ENABLED=0
COPY go.* .
RUN go mod download
COPY . .
RUN make -C api/
RUN go mod vendor
FROM base AS build
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/proxy cmd/proxy/main.go
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o \
/out/eventlistener cmd/eventlistener/main.go
FROM base AS unit-test
RUN --mount=type=cache,target=/root/.cache/go-build \
go test -v ./...
FROM golangci/golangci-lint:v1.27-alpine AS lint-base
FROM base AS lint
COPY --from=lint-base /usr/bin/golangci-lint /usr/bin/golangci-lint
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run --timeout 10m0s ./...
FROM scratch AS bin-unix
COPY --from=build /out/proxy /
COPY --from=build /out/eventlistener /
FROM bin-unix AS bin-linux
FROM bin-unix AS bin-darwin
FROM scratch AS bin-windows
COPY --from=build /out/proxy /proxy.exe
COPY --from=build /out/eventlistener /eventlistener.exe
FROM bin-${TARGETOS} AS bin