-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgo.hlb
55 lines (46 loc) · 1.59 KB
/
go.hlb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import go from image("openllb/go.hlb")
export binary
export crossBinaries
export lint
string versionCmd() {
"git describe --match 'v[0-9]*' --tags --dirty='.dirty' --always | sed 's/^v//'"
}
fs golang() {
image "golang:1.21-alpine"
}
fs build(fs src, string package, string verPackage) {
golang
run "apk add -U git gcc libc-dev"
env "GO111MODULE" "on"
dir "/go/src/hlb"
run "v=$(${versionCmd}) && /usr/local/go/bin/go build -o /out/binary -ldflags \"-linkmode external -extldflags -static -X ${package}.Version=$v\" -a ${verPackage}" with option {
cacheMounts src
mount scratch "/out" as binary
}
}
pipeline crossBinaries(fs src, string package, string verPackage) {
go.buildCommonWithOptions src package option::template {
stringField "base" "docker.elastic.co/beats-dev/golang-crossbuild"
stringField "goVersion" "1.21.3"
stringField "goBuildFlags" "-ldflags \"-X ${verPackage}.Version=$(${versionCmd})\""
} option::run {
env "CGO_ENABLED" "0"
}
}
fs lint(fs src) {
golang
run "apk add -U git gcc libc-dev"
run "sh /golangci/install.sh -b /usr/bin v1.55.0" with option {
mount http("https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh") "/golangci"
}
env "GO111MODULE" "on"
env "PATH" "/usr/bin:/bin:/usr/local/go/bin"
dir "/go/src/hlb"
run "go get" with cacheMounts(src)
run "/usr/bin/golangci-lint run --timeout 10m" with cacheMounts(src)
}
option::run cacheMounts(fs src) {
mount src "/go/src/hlb" with readonly
mount scratch "/root/.cache/go-build" with cache("hlb/go-build", "private")
mount scratch "/go/pkg/mod" with cache("hlb/go-mod", "private")
}