Changes for init/tidy
This commit is contained in:
27
Dockerfile
27
Dockerfile
@@ -2,12 +2,17 @@
|
|||||||
|
|
||||||
FROM --platform=${BUILDPLATFORM} golang:1.16.5-alpine AS base
|
FROM --platform=${BUILDPLATFORM} golang:1.16.5-alpine AS base
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=1
|
||||||
|
RUN apk update
|
||||||
|
RUN apk add gcc g++
|
||||||
|
RUN mkdir /out
|
||||||
|
|
||||||
|
FROM base AS buildbase
|
||||||
COPY go.* .
|
COPY go.* .
|
||||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
FROM base AS build
|
FROM buildbase AS build
|
||||||
ARG TARGETOS
|
ARG TARGETOS
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
RUN --mount=target=. \
|
RUN --mount=target=. \
|
||||||
@@ -31,6 +36,24 @@ RUN --mount=target=. \
|
|||||||
--mount=type=cache,target=/root/.cache/golangci-lint \
|
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||||
golangci-lint run --timeout 10m0s ./...
|
golangci-lint run --timeout 10m0s ./...
|
||||||
|
|
||||||
|
FROM base as mod-init-base
|
||||||
|
WORKDIR /out
|
||||||
|
COPY . .
|
||||||
|
ENV MODNAME example
|
||||||
|
RUN rm -f go.sum go.mod ; go mod init "${MODNAME}" && go mod tidy
|
||||||
|
|
||||||
|
FROM base AS mod-tidy
|
||||||
|
WORKDIR /out
|
||||||
|
COPY . .
|
||||||
|
RUN go mod tidy
|
||||||
|
|
||||||
|
FROM scratch AS mod-init
|
||||||
|
COPY --from=mod-init-base /out/go.mod /go.mod
|
||||||
|
COPY --from=mod-init-base /out/go.sum /go.sum
|
||||||
|
|
||||||
|
FROM scratch AS tidy
|
||||||
|
COPY --from=mod-tidy /out/go.sum /go.sum
|
||||||
|
|
||||||
FROM scratch AS unit-test-coverage
|
FROM scratch AS unit-test-coverage
|
||||||
COPY --from=unit-test /out/cover.out /cover.out
|
COPY --from=unit-test /out/cover.out /cover.out
|
||||||
|
|
||||||
|
|||||||
6
Makefile
6
Makefile
@@ -28,8 +28,10 @@ lint:
|
|||||||
|
|
||||||
.PHONY: tidy
|
.PHONY: tidy
|
||||||
tidy:
|
tidy:
|
||||||
@docker run -t -i -v `pwd`:/src --workdir /src --rm golang:${UTIL_TAG} /usr/local/go/bin/go mod tidy
|
export DOCKER_BUILDKIT=1
|
||||||
|
@docker build . --target tidy --output .
|
||||||
|
|
||||||
.PHONY: init
|
.PHONY: init
|
||||||
init:
|
init:
|
||||||
@docker run -t -i -v `pwd`:/src --workdir /src --rm golang:${UTIL_TAG} /usr/local/go/bin/go mod init
|
export DOCKER_BUILDKIT=1
|
||||||
|
@docker build . --target mod-init --output .
|
||||||
|
|||||||
Reference in New Issue
Block a user