forked from earthly/earthly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
234 lines (209 loc) · 7.01 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
FROM golang:1.13-alpine3.11
RUN apk add --update --no-cache \
bash \
bash-completion \
binutils \
ca-certificates \
coreutils \
curl \
findutils \
g++ \
git \
grep \
less \
make \
openssl \
shellcheck \
util-linux
WORKDIR /earthly
deps:
RUN go get golang.org/x/tools/cmd/goimports
RUN go get golang.org/x/lint/golint
RUN go get github.com/gordonklaus/ineffassign
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
SAVE IMAGE
code:
FROM +deps
COPY --dir autocomplete buildcontext builder cleanup cmd config conslogging debugger dockertar \
domain llbutil logging secretsclient ./
COPY --dir buildkitd/buildkitd.go buildkitd/settings.go buildkitd/
COPY --dir earthfile2llb/antlrhandler earthfile2llb/dedup earthfile2llb/image \
earthfile2llb/imr earthfile2llb/variables earthfile2llb/*.go earthfile2llb/
COPY ./earthfile2llb/parser+parser/*.go ./earthfile2llb/parser/
SAVE IMAGE
lint-scripts:
FROM +deps
COPY ./earth ./buildkitd/entrypoint.sh ./earth-buildkitd-wrapper.sh \
./buildkitd/dockerd-wrapper.sh ./buildkitd/docker-auto-install.sh \
./contrib/earthfile-syntax-highlighting-vim/install.sh \
./release/envcredhelper.sh ./.buildkite/*.sh \
./shell_scripts/
RUN shellcheck shell_scripts/*
lint:
FROM +code
RUN output="$(ineffassign . | grep -v '/earthly/earthfile2llb/parser/.*\.go')" ; \
if [ -n "$output" ]; then \
echo "$output" ; \
exit 1 ; \
fi
RUN output="$(goimports -d $(find . -type f -name '*.go' | grep -v \.pb\.go) 2>&1)" ; \
if [ -n "$output" ]; then \
echo "$output" ; \
exit 1 ; \
fi
RUN golint -set_exit_status ./...
RUN output="$(go vet ./... 2>&1)" ; \
if [ -n "$output" ]; then \
echo "$output" ; \
exit 1 ; \
fi
unit-test:
FROM +code
RUN go test ./...
buildkitd:
BUILD ./buildkitd+buildkitd
shellrepeater:
FROM +code
ARG GOCACHE=/go-cache
ARG EARTHLY_TARGET_TAG
ARG VERSION=$EARTHLY_TARGET_TAG
ARG EARTHLY_GIT_HASH
RUN --mount=type=cache,target=$GOCACHE \
go build \
-ldflags "-d -X main.Version=$VERSION $GO_EXTRA_LDFLAGS -X main.GitSha=$EARTHLY_GIT_HASH $GO_EXTRA_LDFLAGS" \
-tags netgo -installsuffix netgo \
-o build/shellrepeater \
cmd/shellrepeater/*.go
SAVE ARTIFACT build/shellrepeater
debugger:
FROM +code
ARG GOCACHE=/go-cache
ARG EARTHLY_TARGET_TAG
ARG VERSION=$EARTHLY_TARGET_TAG
ARG EARTHLY_GIT_HASH
RUN --mount=type=cache,target=$GOCACHE \
go build \
-ldflags "-d -X main.Version=$VERSION $GO_EXTRA_LDFLAGS -X main.GitSha=$EARTHLY_GIT_HASH $GO_EXTRA_LDFLAGS" \
-tags netgo -installsuffix netgo \
-o build/earth_debugger \
cmd/debugger/*.go
SAVE ARTIFACT build/earth_debugger
earth:
FROM +code
ARG GOOS=linux
ARG GOARCH=amd64
ARG GO_EXTRA_LDFLAGS="-linkmode external -extldflags -static"
RUN test -n "$GOOS" && test -n "$GOARCH"
ARG EARTHLY_TARGET_TAG_DOCKER
ARG VERSION=$EARTHLY_TARGET_TAG_DOCKER
ARG EARTHLY_GIT_HASH
ARG DEFAULT_BUILDKITD_IMAGE=earthly/buildkitd:$VERSION
ARG BUILD_TAGS=dfrunmount dfrunsecurity dfsecrets dfssh dfrunnetwork
ARG GOCACHE=/go-cache
RUN mkdir -p build
RUN printf "$BUILD_TAGS" > ./build/tags && echo "$(cat ./build/tags)"
RUN printf '-X main.DefaultBuildkitdImage='"$DEFAULT_BUILDKITD_IMAGE" > ./build/ldflags && \
printf ' -X main.Version='"$VERSION" >> ./build/ldflags && \
printf ' -X main.GitSha='"$EARTHLY_GIT_HASH" >> ./build/ldflags && \
printf ' '"$GO_EXTRA_LDFLAGS" >> ./build/ldflags && \
echo "$(cat ./build/ldflags)"
# Important! If you change the go build options, you may need to also change them
# in https://github.com/Homebrew/homebrew-core/blob/master/Formula/earthly.rb.
RUN --mount=type=cache,target=$GOCACHE \
go build \
-tags "$(cat ./build/tags)" \
-ldflags "$(cat ./build/ldflags)" \
-o build/earth \
cmd/earth/*.go
SAVE ARTIFACT ./build/tags
SAVE ARTIFACT ./build/ldflags
SAVE ARTIFACT build/earth AS LOCAL "build/$GOOS/$GOARCH/earth"
earth-darwin:
COPY \
--build-arg GOOS=darwin \
--build-arg GOARCH=amd64 \
--build-arg GO_EXTRA_LDFLAGS= \
+earth/* ./
SAVE ARTIFACT ./*
earth-all:
COPY +earth/earth ./earth-linux-amd64
COPY +earth-darwin/earth ./earth-darwin-amd64
SAVE ARTIFACT ./*
earth-docker:
FROM ./buildkitd+buildkitd
RUN apk add --update --no-cache docker-cli
ENV ENABLE_LOOP_DEVICE=false
ENV FORCE_LOOP_DEVICE=false
COPY earth-buildkitd-wrapper.sh /usr/bin/earth-buildkitd-wrapper.sh
ENTRYPOINT ["/usr/bin/earth-buildkitd-wrapper.sh"]
ARG EARTHLY_TARGET_TAG_DOCKER
ARG TAG=$EARTHLY_TARGET_TAG_DOCKER
COPY --build-arg VERSION=$TAG +earth/earth /usr/bin/earth
SAVE IMAGE --push earthly/earth:$TAG
# we abuse docker here to distribute our binaries
prerelease-docker:
FROM alpine:3.11
BUILD --build-arg TAG=prerelease ./buildkitd+buildkitd
COPY --build-arg VERSION=prerelease +earth-all/* ./
SAVE IMAGE --push earthly/earthlybinaries:prerelease
dind:
BUILD +dind-alpine
BUILD +dind-ubuntu
dind-alpine:
FROM docker:dind
RUN apk add --update --no-cache docker-compose
ARG DIND_ALPINE_TAG=alpine-$EARTHLY_TARGET_TAG_DOCKER
SAVE IMAGE --push earthly/dind:$DIND_ALPINE_TAG
dind-ubuntu:
FROM ubuntu:latest
COPY ./buildkitd/docker-auto-install.sh /usr/local/bin/docker-auto-install.sh
RUN docker-auto-install.sh
ARG DIND_UBUNTU_TAG=ubuntu-$EARTHLY_TARGET_TAG_DOCKER
SAVE IMAGE --push earthly/dind:$DIND_UBUNTU_TAG
for-linux:
BUILD +buildkitd
COPY +earth/earth ./
SAVE ARTIFACT ./earth
for-darwin:
BUILD +buildkitd
COPY +earth-darwin/earth ./
SAVE ARTIFACT ./earth
all:
BUILD +buildkitd
BUILD +earth-all
BUILD +earth-docker
BUILD +prerelease-docker
BUILD +dind
test:
BUILD +lint
BUILD +lint-scripts
BUILD +unit-test
BUILD ./examples/tests+ga
test-all:
BUILD +examples
BUILD +test
BUILD ./examples/tests+experimental
examples:
BUILD ./examples/go+docker
BUILD ./examples/java+docker
BUILD ./examples/js+docker
BUILD ./examples/cpp+docker
BUILD ./examples/c+docker
BUILD ./examples/scala+docker
BUILD ./examples/dotnet+docker
BUILD ./examples/python+docker
BUILD ./examples/ruby+docker
BUILD ./examples/elixir+docker
BUILD ./examples/monorepo+all
BUILD ./examples/multirepo+docker
BUILD ./examples/integration-test+integration-test
BUILD ./examples/readme/go1+all
BUILD ./examples/readme/go2+all
BUILD ./examples/readme/go3+build
BUILD ./examples/readme/proto+docker
BUILD github.com/earthly/hello-world+hello
test-fail:
RUN false