Skip to content

Commit e7e9118

Browse files
committed
Dockerfile: add test stage
Signed-off-by: CrazyMax <[email protected]>
1 parent 0e5dbc6 commit e7e9118

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ FROM gobase AS base
3030
ARG TARGETPLATFORM
3131
RUN xx-apk add musl-dev gcc libsecret-dev pass
3232

33+
FROM base AS test
34+
RUN --mount=type=bind,target=. \
35+
--mount=type=cache,target=/root/.cache \
36+
--mount=type=cache,target=/go/pkg/mod <<EOT
37+
set -e
38+
xx-go test -short -v -coverprofile=/tmp/coverage.txt -covermode=atomic ./...
39+
xx-go tool cover -func=/tmp/coverage.txt
40+
EOT
41+
42+
FROM scratch AS test-coverage
43+
COPY --from=test /tmp/coverage.txt /coverage.txt
44+
3345
FROM base AS build-linux
3446
ARG TARGETOS
3547
ARG TARGETARCH

docker-bake.hcl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
variable "GO_VERSION" {
22
default = "1.16.7"
33
}
4+
5+
# Defines the output folder
46
variable "DESTDIR" {
5-
default = "./bin"
7+
default = ""
8+
}
9+
function "bindir" {
10+
params = [defaultdir]
11+
result = DESTDIR != "" ? DESTDIR : "./bin/${defaultdir}"
612
}
713

814
target "_common" {
@@ -15,10 +21,16 @@ group "default" {
1521
targets = ["binaries"]
1622
}
1723

24+
target "test" {
25+
inherits = ["_common"]
26+
target = "test-coverage"
27+
output = [bindir("coverage")]
28+
}
29+
1830
target "binaries" {
1931
inherits = ["_common"]
2032
target = "binaries"
21-
output = [DESTDIR]
33+
output = [bindir("build")]
2234
platforms = [
2335
"darwin/amd64",
2436
"darwin/arm64",

0 commit comments

Comments
 (0)