-
Notifications
You must be signed in to change notification settings - Fork 48
/
Earthfile
300 lines (270 loc) · 9.85 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
VERSION 0.7
FROM 84codes/crystal:1.10.0-ubuntu-22.04
WORKDIR /workdir
# gh-action-essential runs only the necessary recipes
gh-action-essential:
BUILD +format-check
BUILD +lint
BUILD +specs
# gh-action-integration runs all integration specs
gh-action-integration:
BUILD +integration-specs
# gh-action-e2e runs all end-to-end specs
gh-action-e2e:
BUILD +e2e-full-web-app
BUILD +e2e-full-web-app-noauth
BUILD +e2e-full-web-app-api
BUILD +e2e-full-web-app-api-noauth
# gh-action-e2e-security runs all security tests (requires secrets)
gh-action-e2e-security:
BUILD +e2e-sec-tester
# gh-action-weekly runs all weekly tests
gh-action-weekly:
BUILD +weekly-latest-full-web-app
BUILD +weekly-nightly-full-web-app
# format-check checks the format of source files
format-check:
FROM +base-image
RUN crystal tool format --check src spec
# specs runs unit tests
specs:
FROM +base-specs-image
RUN crystal spec --tag "~integration"
# update-snapshot updates spec fixtures
update-snapshot:
FROM +base-specs-image
ARG spec
ENV SPEC_UPDATE_SNAPSHOT=1
RUN crystal spec --tag "~integration" $spec
SAVE ARTIFACT ./fixtures AS LOCAL ./fixtures
# lint runs ameba code linter
lint:
FROM ghcr.io/crystal-ameba/ameba:1.5.0
COPY --dir src ./
COPY --dir spec ./
RUN ameba
# integration-specs runs integration tests
integration-specs:
FROM +base-image
COPY +build-lucky/lucky /usr/bin/lucky
COPY fixtures/hello_world.cr fixtures/
COPY fixtures/hello_crystal.cr bin/lucky.hello_crystal.cr
COPY fixtures/tasks.cr fixtures/
RUN shards build lucky.hello_world --without-development
RUN crystal spec --tag integration
# e2e-full-web-app tests lucky full web app
e2e-full-web-app:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+e2e-image
RUN docker run --network=host lucky-image:latest
END
# e2e-full-web-app-noauth tests lucky full web app with no auth
e2e-full-web-app-noauth:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+e2e-image-noauth
RUN docker run --network=host lucky-image:latest
END
# e2e-full-web-app-api tests lucky full web app with api
e2e-full-web-app-api:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+e2e-image-api
RUN docker run --network=host lucky-image:latest
END
# e2e-full-web-app-api-noauth tests lucky full web app with api and no auth
e2e-full-web-app-api-noauth:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+e2e-image-api-noauth
RUN docker run --network=host lucky-image:latest
END
# e2e-sec-tester tests lucky full app with security tester enabled
e2e-sec-tester:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+e2e-image-security
RUN --secret BRIGHT_TOKEN --secret BRIGHT_PROJECT_ID -- \
docker run \
--network=host \
-e BRIGHT_TOKEN \
-e BRIGHT_PROJECT_ID \
lucky-image:latest
END
# weekly-latest-full-web-app tests lucky full web app (crystal: latest) for catching potential issues on newer versions of packages
weekly-latest-full-web-app:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+weekly-latest-image
RUN docker run --network=host lucky-image:latest
END
# weekly-nightly-full-web-app tests lucky full web app (crystal: nightly) for more insight into upcoming crystal versions
weekly-nightly-full-web-app:
FROM earthly/dind:alpine
COPY docker-compose.yml ./
WITH DOCKER \
--compose docker-compose.yml \
--load lucky-image:latest=+weekly-nightly-image
RUN docker run --network=host lucky-image:latest
END
# release-static builds an executable statically linked
release-static:
FROM 84codes/crystal:latest-alpine
WORKDIR /workdir
COPY --dir src ./
COPY shard.yml ./
RUN apk add yaml-static
RUN shards build lucky --without-development --no-debug --release --static
SAVE ARTIFACT ./bin/lucky
build-lucky:
WORKDIR /lucky_cli
COPY --dir src ./
COPY fixtures/hello_world.cr fixtures/
COPY shard.yml ./
RUN shards build lucky --without-development
SAVE ARTIFACT ./bin/lucky
base-image:
COPY --dir src ./
COPY --dir spec ./
COPY shard.yml ./
base-specs-image:
FROM +base-image
COPY --dir fixtures ./
RUN shards install
e2e-base-image:
RUN apt-get update \
&& apt-get install -y postgresql-client ca-certificates curl gnupg libnss3 libnss3-dev wget \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& npm install --global yarn \
&& wget -O /tmp/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y /tmp/google-chrome-stable_current_amd64.deb
ENV CHROME_BIN=/usr/bin/google-chrome
COPY +build-lucky/lucky /usr/bin/lucky
e2e-image:
FROM +e2e-base-image
RUN lucky init.custom test-project
WORKDIR /workdir/test-project
RUN crystal tool format --check src spec config
RUN yarn install --no-progress \
&& yarn dev \
&& shards install
RUN crystal build src/start_server.cr
RUN crystal build src/test_project.cr
RUN crystal run src/app.cr
ENTRYPOINT ["crystal", "spec"]
SAVE IMAGE lucky-image:base
e2e-image-noauth:
FROM +e2e-base-image
RUN lucky init.custom test-project --no-auth
WORKDIR /workdir/test-project
RUN yarn install --no-progress \
&& yarn dev \
&& shards install
RUN lucky gen.action.api Api::Users::Show \
&& lucky gen.action.browser Users::Show \
&& lucky gen.migration CreateThings \
&& lucky gen.model User \
&& lucky gen.page Users::IndexPage \
&& lucky gen.component Users::Header \
&& lucky gen.resource.browser Comment title:String \
&& lucky gen.task email.monthly_update \
&& lucky gen.secret_key
RUN crystal tool format --check src spec config
RUN crystal build src/start_server.cr
RUN crystal build src/test_project.cr
RUN crystal run src/app.cr
ENTRYPOINT ["crystal", "spec"]
SAVE IMAGE lucky-image:noauth
e2e-image-api:
FROM +e2e-base-image
RUN lucky init.custom test-project --api
WORKDIR /workdir/test-project
RUN crystal tool format --check src spec config
RUN shards install
RUN crystal build src/start_server.cr
RUN crystal build src/test_project.cr
RUN crystal run src/app.cr
ENTRYPOINT ["crystal", "spec"]
SAVE IMAGE lucky-image:api
e2e-image-api-noauth:
FROM +e2e-base-image
RUN lucky init.custom test-project --api --no-auth
WORKDIR /workdir/test-project
RUN crystal tool format --check src spec config
RUN shards install
RUN crystal build src/start_server.cr
RUN crystal build src/test_project.cr
RUN crystal run src/app.cr
ENTRYPOINT ["crystal", "spec"]
SAVE IMAGE lucky-image:api-noauth
e2e-image-security:
FROM +e2e-base-image
ARG github_ref
ARG github_sha
ARG github_run_id
RUN lucky init.custom test-project --with-sec-test
WORKDIR /workdir/test-project
RUN crystal tool format --check src spec config
RUN yarn install --no-progress \
&& yarn dev \
&& shards install
ENV LUCKY_ENV=test
ENV RUN_SEC_TESTER_SPECS=1
ENV GITHUB_REF=$github_ref
ENV GITHUB_SHA=$github_sha
ENV GITHUB_RUN_ID=$github_run_id
ENTRYPOINT ["crystal", "spec", "-Dwith_sec_tests"]
SAVE IMAGE lucky-image:security
weekly-latest-image:
FROM 84codes/crystal:latest-ubuntu-22.04
DO +WEEKLY_IMAGE --shard_file=shard.edge.yml
SAVE IMAGE lucky-image:weekly-latest
weekly-nightly-image:
FROM 84codes/crystal:master-ubuntu-22.04
DO +WEEKLY_IMAGE --shard_file=shard.override.yml
SAVE IMAGE lucky-image:weekly-nightly
WEEKLY_IMAGE:
COMMAND
ARG shard_file
WORKDIR /workdir
RUN apt-get update \
&& apt-get install -y postgresql-client ca-certificates curl gnupg libnss3 libnss3-dev wget \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& npm install --global yarn \
&& wget -O /tmp/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y /tmp/google-chrome-stable_current_amd64.deb
ENV CHROME_BIN=/usr/bin/google-chrome
COPY +build-lucky/lucky /usr/bin/lucky
RUN lucky init.custom test-project
WORKDIR /workdir/test-project
COPY $shard_file ./
ENV SHARDS_OVERRIDE=/workdir/test-project/$shard_file
RUN crystal tool format --check src spec config
RUN yarn install --no-progress \
&& yarn dev \
&& shards install
RUN crystal build src/start_server.cr
RUN crystal build src/test_project.cr
RUN crystal run src/app.cr
ENTRYPOINT ["crystal", "spec"]