-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
119 lines (107 loc) · 3.42 KB
/
Earthfile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
VERSION 0.6
FROM alpine:3.16
deps:
FROM golang:1.19-alpine3.16
RUN apk add --update --no-cache \
bash \
bash-completion \
binutils \
ca-certificates \
coreutils \
curl \
findutils \
g++ \
git \
grep \
less \
make \
openssl \
util-linux
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.0
# no external dependencies, so no need to call go mod download
WORKDIR /code
COPY go.mod .
# otherwise, this would be needed
#COPY go.mod go.sum .
#RUN go mod download
#SAVE ARTIFACT go.mod AS LOCAL go.mod
#SAVE ARTIFACT go.sum AS LOCAL go.sum
code:
FROM +deps
COPY --dir cmd ./
SAVE IMAGE
lint:
FROM +code
COPY ./.golangci.yaml ./
RUN golangci-lint run
colorgrep:
FROM +code
ARG RELEASE_TAG="dev"
ARG GOOS
ARG GO_EXTRA_LDFLAGS
ARG GOARCH
RUN test -n "$GOOS" && test -n "$GOARCH"
ARG GOCACHE=/go-cache
RUN mkdir -p build
ENV CGO_ENABLED=0
RUN --mount=type=cache,target=$GOCACHE \
go build \
-o build/colorgrep \
-ldflags "-X main.Version=$RELEASE_TAG $GO_EXTRA_LDFLAGS" \
cmd/main.go
SAVE ARTIFACT build/colorgrep AS LOCAL "build/$GOOS/$GOARCH/colorgrep"
colorgrep-darwin-amd64:
COPY \
--build-arg GOOS=darwin \
--build-arg GOARCH=amd64 \
--build-arg GO_EXTRA_LDFLAGS= \
+colorgrep/colorgrep /build/colorgrep
SAVE ARTIFACT /build/colorgrep AS LOCAL "build/darwin/amd64/colorgrep"
colorgrep-darwin-arm64:
COPY \
--build-arg GOOS=darwin \
--build-arg GOARCH=arm64 \
--build-arg GO_EXTRA_LDFLAGS= \
+colorgrep/colorgrep /build/colorgrep
SAVE ARTIFACT /build/colorgrep AS LOCAL "build/darwin/arm64/colorgrep"
colorgrep-linux-amd64:
COPY \
--build-arg GOOS=linux \
--build-arg GOARCH=amd64 \
--build-arg GO_EXTRA_LDFLAGS="-linkmode external -extldflags -static" \
+colorgrep/colorgrep /build/colorgrep
SAVE ARTIFACT /build/colorgrep AS LOCAL "build/linux/amd64/colorgrep"
colorgrep-linux-arm64:
COPY \
--build-arg GOOS=linux \
--build-arg GOARCH=arm64 \
--build-arg GO_EXTRA_LDFLAGS= \
+colorgrep/colorgrep /build/colorgrep
SAVE ARTIFACT /build/colorgrep AS LOCAL "build/linux/arm64/colorgrep"
colorgrep-all:
BUILD +colorgrep-linux-amd64
BUILD +colorgrep-linux-arm64
BUILD +colorgrep-darwin-amd64
BUILD +colorgrep-darwin-arm64
release:
FROM node:13.10.1-alpine3.11
RUN npm install -g github-release-cli@v1.3.1
WORKDIR /release
COPY +colorgrep-linux-amd64/colorgrep ./colorgrep-linux-amd64
COPY +colorgrep-linux-arm64/colorgrep ./colorgrep-linux-arm64
COPY +colorgrep-darwin-amd64/colorgrep ./colorgrep-darwin-amd64
COPY +colorgrep-darwin-arm64/colorgrep ./colorgrep-darwin-arm64
ARG --required RELEASE_TAG
ARG EARTHLY_GIT_HASH
ARG BODY="No details provided"
RUN --secret GITHUB_TOKEN=+secrets/GITHUB_TOKEN test -n "$GITHUB_TOKEN"
RUN --push \
--secret GITHUB_TOKEN=+secrets/GITHUB_TOKEN \
github-release upload \
--owner alexcb \
--repo colorgrep \
--commitish "$EARTHLY_GIT_HASH" \
--tag "$RELEASE_TAG" \
--name "$RELEASE_TAG" \
--body "$BODY" \
./colorgrep-*