Files
docker-go-dev/Dockerfile

47 lines
1.3 KiB
Docker
Raw Normal View History

2020-05-28 13:29:02 +02:00
# syntax = docker/dockerfile:1-experimental
2021-06-28 13:48:16 -04:00
FROM --platform=${BUILDPLATFORM} golang:1.16.5-alpine AS base
2020-05-28 13:29:02 +02:00
WORKDIR /src
ENV CGO_ENABLED=0
COPY go.* .
2020-10-03 10:48:43 +02:00
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
2020-05-28 13:29:02 +02:00
FROM base AS build
ARG TARGETOS
ARG TARGETARCH
RUN --mount=target=. \
2020-10-03 10:48:43 +02:00
--mount=type=cache,target=/go/pkg/mod \
2020-05-28 13:29:02 +02:00
--mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/example .
FROM base AS unit-test
RUN --mount=target=. \
2020-10-03 10:48:43 +02:00
--mount=type=cache,target=/go/pkg/mod \
2020-05-28 13:29:02 +02:00
--mount=type=cache,target=/root/.cache/go-build \
2020-08-12 18:52:18 +02:00
mkdir /out && go test -v -coverprofile=/out/cover.out ./...
2020-05-28 13:29:02 +02:00
2020-10-03 10:48:12 +02:00
FROM golangci/golangci-lint:v1.31.0-alpine AS lint-base
2020-05-28 13:29:02 +02:00
FROM base AS lint
RUN --mount=target=. \
--mount=from=lint-base,src=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
2020-10-03 10:48:43 +02:00
--mount=type=cache,target=/go/pkg/mod \
2020-05-28 13:29:02 +02:00
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run --timeout 10m0s ./...
2020-08-12 18:52:18 +02:00
FROM scratch AS unit-test-coverage
COPY --from=unit-test /out/cover.out /cover.out
2020-05-28 13:29:02 +02:00
FROM scratch AS bin-unix
COPY --from=build /out/example /
FROM bin-unix AS bin-linux
FROM bin-unix AS bin-darwin
FROM scratch AS bin-windows
COPY --from=build /out/example /example.exe
FROM bin-${TARGETOS} as bin