forked from earthly/earthly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.earth
242 lines (222 loc) · 7.01 KB
/
build.earth
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
235
236
237
238
239
240
241
242
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 \
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 buildcontext builder cleanup cmd conslogging dockertar domain \
llbutil logging ./
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:
FROM +code
RUN output="$(ineffassign . | grep -v '/earthly/earthfile2llb/parser/.*\.go')" ; \
if [ -n "$output" ]; then \
echo "$output" ; \
exit 1 ; \
fi
RUN output="$(goimports -d . 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
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
ARG VERSION=$EARTHLY_TARGET_TAG
ARG DEFAULT_BUILDKITD_IMAGE=earthly/buildkitd:$VERSION
ARG GOCACHE=/go-cache
RUN --mount=type=cache,target=$GOCACHE \
go build \
-ldflags "-X main.DefaultBuildkitdImage=$DEFAULT_BUILDKITD_IMAGE -X main.Version=$VERSION $GO_EXTRA_LDFLAGS" \
-o build/earth \
cmd/earth/*.go
SAVE ARTIFACT build/earth AS LOCAL "build/$GOOS/$GOARCH/earth"
earth-all:
BUILD +earth
BUILD \
--build-arg GOOS=darwin \
--build-arg GOARCH=amd64 \
--build-arg GO_EXTRA_LDFLAGS= \
+earth
earth-docker:
FROM ./buildkitd+buildkitd
RUN apk add --update --no-cache docker-cli
ENV ENABLE_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
ARG TAG=$EARTHLY_TARGET_TAG
COPY --build-arg VERSION=$TAG +earth/earth /usr/bin/earth
SAVE IMAGE --push earthly/earth:$TAG
all:
BUILD +earth-all
BUILD +earth-docker
BUILD ./buildkitd+buildkitd
test:
BUILD +lint
BUILD ./examples/tests+all
BUILD +examples
examples:
BUILD ./examples/go+docker
BUILD ./examples/java+docker
BUILD ./examples/js+docker
BUILD ./examples/monorepo+all
BUILD ./examples/multirepo+docker
BUILD ./examples/readme+parallel
BUILD ./examples/readme+final-success-target
test-experimental:
BUILD ./examples/tests+experimental
release:
ARG RELEASE_TAG
RUN test -n "$RELEASE_TAG"
BUILD +test
BUILD --build-arg RELEASE_TAG="$RELEASE_TAG" +release-dockerhub
BUILD --build-arg RELEASE_TAG="$RELEASE_TAG" +release-github
release-dockerhub:
ARG RELEASE_TAG
RUN test -n "$RELEASE_TAG"
BUILD --build-arg TAG="$RELEASE_TAG" +earth-docker
BUILD --build-arg TAG="$RELEASE_TAG" ./buildkitd+buildkitd
BUILD --build-arg TAG=latest +earth-docker
BUILD --build-arg TAG=latest ./buildkitd+buildkitd
release-github:
FROM node:13.10.1-alpine3.11
RUN npm install -g github-release-cli
WORKDIR /earthly
ARG RELEASE_TAG
ARG EARTHLY_GIT_HASH
RUN test -n "$RELEASE_TAG" && test -n "$EARTHLY_GIT_HASH"
COPY --build-arg VERSION=$RELEASE_TAG \
+earth/earth ./earth-linux-amd64
COPY --build-arg VERSION=$RELEASE_TAG \
--build-arg GOOS=darwin \
--build-arg GOARCH=amd64 \
--build-arg GO_EXTRA_LDFLAGS= \
+earth/earth ./earth-darwin-amd64
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 earthly \
--repo earthly \
--commitish "$EARTHLY_GIT_HASH" \
--tag "$RELEASE_TAG" \
--name "$RELEASE_TAG" \
--body "$BODY" \
earth-linux-amd64 earth-darwin-amd64
release-homebrew:
# Deps and preconditions.
RUN apk add --update --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing hub
ARG RELEASE_TAG
ARG GIT_USERNAME
ARG GIT_NAME
ARG GIT_EMAIL
ARG REPO_OWNER=Homebrew
ARG HOMEBREW_CORE_URL="https://github.com/$REPO_OWNER/homebrew-core"
RUN test -n "$RELEASE_TAG" && \
test -n "$GIT_USERNAME" && \
test -n "$GIT_NAME" && \
test -n "$GIT_EMAIL" && \
test -n "$REPO_OWNER" && \
test -n "$HOMEBREW_CORE_URL"
ARG NEW_URL=https://github.com/earthly/earthly/archive/"$RELEASE_TAG".tar.gz
RUN test -n "$NEW_URL"
GIT CLONE "$HOMEBREW_CORE_URL" homebrew-core
WORKDIR /earthly/homebrew-core
# Git setup.
# Force use of https.
RUN git remote set-url origin "$HOMEBREW_CORE_URL" && \
git remote -v
RUN --secret GIT_PASSWORD=+secrets/GITHUB_TOKEN \
git fetch origin master
RUN git branch -f master && \
git checkout master && \
git branch -u origin/master
RUN git config --global user.name "$GIT_NAME" && \
git config --global user.email "$GIT_EMAIL"
# TODO: Move this script to a more common location.
COPY ./buildkitd/envcredhelper.sh /usr/bin/envcredhelper.sh
RUN git config --global credential.helper "/bin/sh /usr/bin/envcredhelper.sh"
# Make the change in a new branch.
RUN git checkout -b "release-$RELEASE_TAG"
RUN curl -L "$NEW_URL" | sha256sum | cut -f 1 -d ' ' > /downloadsha256.txt
RUN sed -i \
-e 's/sha256 ".*"$/sha256 "'$(cat /downloadsha256.txt)'"/' \
-e 's#url ".*"#url "'"$NEW_URL"'"#' \
./Formula/earthly.rb
RUN echo "Resulting formula:" && cat ./Formula/earthly.rb && \
echo "Diff:" && git diff
RUN version=${RELEASE_TAG#v} ;\
echo version=$version ;\
git commit -a -m "earthly $version"
# Fork, push branch to fork and create upstream PR.
RUN --secret GITHUB_TOKEN=+secrets/GITHUB_TOKEN test -n "$GITHUB_TOKEN"
RUN --push \
--secret GITHUB_TOKEN=+secrets/GITHUB_TOKEN \
-- \
hub fork
# Force use of https st we can use GITHUB_TOKEN via envcredhelper.sh.
RUN --push \
-- \
git remote set-url "$GIT_USERNAME" "https://github.com/$GIT_USERNAME/homebrew-core.git" && \
git remote -v
RUN --push \
--secret GIT_PASSWORD=+secrets/GITHUB_TOKEN \
-- \
git push "$GIT_USERNAME" "release-$RELEASE_TAG"
RUN --push \
--secret GIT_PASSWORD=+secrets/GITHUB_TOKEN \
--secret GITHUB_TOKEN=+secrets/GITHUB_TOKEN \
-- \
version=${RELEASE_TAG#v} ;\
echo version=$version ;\
hub pull-request --no-edit \
-h "$GIT_USERNAME":"release-$RELEASE_TAG" \
-b "$REPO_OWNER:master" \
-m "earthly $version" \
-m '-------------' \
-m '#### Debug data' \
-m 'PR generated by the [Earthly build](https://github.com/earthly/earthly/blob/master/build.earth) (target +release-homebrew)' \
-m '* `RELEASE_TAG='"$RELEASE_TAG"'`' \
-m '* `GIT_USERNAME='"$GIT_USERNAME"'`' \
-m '* `NEW_URL='"$NEW_URL"'`' \
-m '* `NEW_SHA256='"$(cat /downloadsha256.txt)"'`'
release-vscode-syntax-highlighting:
BUILD ./contrib/earthfile-syntax-highlighting+release