Maintenance: better layer caching
- Install g++ in base image before copying code - Install xcputranslate in base image before copying code - Install golangci-lint in base image before copying code - Install golangci-lint using go get directly
This commit is contained in:
12
Dockerfile
12
Dockerfile
@@ -3,8 +3,11 @@ ARG GO_VERSION=1.16
|
|||||||
ARG BUILDPLATFORM=linux/amd64
|
ARG BUILDPLATFORM=linux/amd64
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
|
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
|
||||||
RUN apk --update add git
|
RUN apk --update add git g++
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
|
COPY --from=qmcgaw/xcputranslate:v0.4.0 /xcputranslate /usr/local/bin/xcputranslate
|
||||||
|
ARG GOLANGCI_LINT_VERSION=v1.40.1
|
||||||
|
RUN go get github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
|
||||||
WORKDIR /tmp/gobuild
|
WORKDIR /tmp/gobuild
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
@@ -14,15 +17,11 @@ COPY internal/ ./internal/
|
|||||||
FROM --platform=$BUILDPLATFORM base AS test
|
FROM --platform=$BUILDPLATFORM base AS test
|
||||||
# Note on the go race detector:
|
# Note on the go race detector:
|
||||||
# - we set CGO_ENABLED=1 to have it enabled
|
# - we set CGO_ENABLED=1 to have it enabled
|
||||||
# - we install g++ to support the race detector
|
# - we installed g++ to support the race detector
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
RUN apk --update --no-cache add g++
|
|
||||||
ENTRYPOINT go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./...
|
ENTRYPOINT go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./...
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM base AS lint
|
FROM --platform=$BUILDPLATFORM base AS lint
|
||||||
ARG GOLANGCI_LINT_VERSION=v1.40.1
|
|
||||||
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
|
|
||||||
sh -s -- -b /usr/local/bin ${GOLANGCI_LINT_VERSION}
|
|
||||||
COPY .golangci.yml ./
|
COPY .golangci.yml ./
|
||||||
RUN golangci-lint run --timeout=10m
|
RUN golangci-lint run --timeout=10m
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ RUN git init && \
|
|||||||
git diff --exit-code -- go.mod
|
git diff --exit-code -- go.mod
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM base AS build
|
FROM --platform=$BUILDPLATFORM base AS build
|
||||||
COPY --from=qmcgaw/xcputranslate:v0.4.0 /xcputranslate /usr/local/bin/xcputranslate
|
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
ARG VERSION=unknown
|
ARG VERSION=unknown
|
||||||
ARG BUILD_DATE="an unknown date"
|
ARG BUILD_DATE="an unknown date"
|
||||||
|
|||||||
Reference in New Issue
Block a user