-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from crazy-max/dockerfile
container based dev flow
- Loading branch information
Showing
4 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
ARG GO_VERSION="1.18" | ||
ARG GOLANGCI_LINT_VERSION="v1.45" | ||
|
||
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint | ||
|
||
FROM golang:${GO_VERSION}-alpine AS base | ||
RUN apk add --no-cache gcc git linux-headers musl-dev | ||
ENV CGO_ENABLED=0 | ||
ENV GO111MODULE=on | ||
WORKDIR /src | ||
|
||
FROM base AS vendored | ||
RUN --mount=type=bind,target=.,rw \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
go mod tidy && go mod download && \ | ||
mkdir /out && cp go.mod go.sum /out | ||
|
||
FROM scratch AS vendor-update | ||
COPY --from=vendored /out / | ||
|
||
FROM vendored AS vendor-validate | ||
RUN --mount=type=bind,target=.,rw <<EOT | ||
set -e | ||
git add -A | ||
cp -rf /out/* . | ||
diff=$(git status --porcelain -- go.mod go.sum) | ||
if [ -n "$diff" ]; then | ||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"' | ||
echo "$diff" | ||
exit 1 | ||
fi | ||
EOT | ||
|
||
FROM base AS lint | ||
RUN --mount=type=bind,target=. \ | ||
--mount=type=cache,target=/root/.cache \ | ||
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ | ||
golangci-lint run ./... | ||
|
||
FROM vendored AS test | ||
ENV CGO_ENABLED=1 | ||
RUN --mount=type=bind,target=. \ | ||
--mount=type=cache,target=/root/.cache \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic -race ./... && \ | ||
go tool cover -func=/tmp/coverage.txt | ||
|
||
FROM scratch AS test-coverage | ||
COPY --from=test /tmp/coverage.txt /coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
variable "GO_VERSION" { | ||
default = "1.18" | ||
} | ||
|
||
target "_common" { | ||
args = { | ||
GO_VERSION = GO_VERSION | ||
} | ||
} | ||
|
||
group "default" { | ||
targets = ["test"] | ||
} | ||
|
||
group "validate" { | ||
targets = ["lint", "vendor-validate"] | ||
} | ||
|
||
target "lint" { | ||
inherits = ["_common"] | ||
target = "lint" | ||
output = ["type=cacheonly"] | ||
} | ||
|
||
target "vendor-validate" { | ||
inherits = ["_common"] | ||
target = "vendor-validate" | ||
output = ["type=cacheonly"] | ||
} | ||
|
||
target "vendor-update" { | ||
inherits = ["_common"] | ||
target = "vendor-update" | ||
output = ["."] | ||
} | ||
|
||
target "test" { | ||
inherits = ["_common"] | ||
target = "test-coverage" | ||
output = ["."] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters