Updates Containerize
This commit is contained in:
71
Dockerfile
Normal file
71
Dockerfile
Normal file
@@ -0,0 +1,71 @@
|
||||
# Containerized-go dockerfile
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} golang:1.24.3-alpine AS base
|
||||
WORKDIR /src
|
||||
ENV CGO_ENABLED=1
|
||||
RUN apk update
|
||||
RUN apk add gcc g++
|
||||
RUN mkdir /out
|
||||
|
||||
FROM base AS buildbase
|
||||
COPY go.* .
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
go mod download
|
||||
|
||||
FROM buildbase AS build
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
--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=. \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
go test -v -coverprofile=/out/cover.out ./...
|
||||
|
||||
FROM golangci/golangci-lint:v2.1.6-alpine AS lint-base
|
||||
|
||||
FROM base AS lint
|
||||
RUN --mount=target=. \
|
||||
--mount=from=lint-base,src=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||
golangci-lint run --timeout 10m0s ./...
|
||||
|
||||
FROM base AS mod-init-base
|
||||
WORKDIR /out
|
||||
COPY . .
|
||||
ENV MODNAME tastytrade
|
||||
RUN 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.mod /go.mod
|
||||
COPY --from=mod-tidy /out/go.sum /go.sum
|
||||
COPY --from=mod-tidy /out/go.mod /go.mod
|
||||
|
||||
FROM scratch AS unit-test-coverage
|
||||
COPY --from=unit-test /out/cover.out /cover.out
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user