Skip to content

Commit 7c726fb

Browse files
committed
WIP dagger
1 parent e08d538 commit 7c726fb

File tree

1 file changed

+64
-37
lines changed

1 file changed

+64
-37
lines changed

.dagger/src/index.ts

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,45 @@ const RUST_IMAGE = "rust:bookworm";
1313

1414
@object()
1515
export class AtomicServer {
16+
source: Directory;
17+
18+
constructor(
19+
@argument({
20+
defaultPath: ".",
21+
ignore: [
22+
"**/node_modules",
23+
"**/.git",
24+
"**/target",
25+
"**/tmp",
26+
"**/.DS_Store",
27+
"**/.vscode",
28+
"**/dist",
29+
"**/build",
30+
],
31+
})
32+
source: Directory
33+
) {
34+
this.source = source;
35+
}
36+
1637
@func()
17-
async ci(
18-
@argument() netlifyAuthToken: Secret
19-
): Promise<(string | Container)[]> {
20-
return Promise.all([
38+
async ci(@argument() netlifyAuthToken: Secret): Promise<string> {
39+
await Promise.all([
2140
this.docsPublish(netlifyAuthToken),
22-
this.buildBrowser(),
2341
this.lintBrowser(),
2442
this.testBrowser(),
2543
this.ee(netlifyAuthToken),
2644
this.rustTest(),
2745
this.rustClippy(),
2846
this.rustFmt(),
2947
]);
48+
49+
return "CI pipeline completed successfully";
3050
}
3151

3252
@func()
3353
buildBrowser(): Container {
34-
const source = dag.currentModule().source().directory("browser");
54+
const source = this.source.directory("browser");
3555
const depsContainer = this.getDeps(source.directory("."));
3656

3757
const buildContainer = depsContainer
@@ -43,7 +63,7 @@ export class AtomicServer {
4363

4464
@func()
4565
async lintBrowser(): Promise<string> {
46-
const source = dag.currentModule().source().directory("browser");
66+
const source = this.source.directory("browser");
4767
const depsContainer = this.getDeps(source.directory("."));
4868
return depsContainer
4969
.withWorkdir("/app")
@@ -53,7 +73,7 @@ export class AtomicServer {
5373

5474
@func()
5575
async testBrowser(): Promise<string> {
56-
const source = dag.currentModule().source().directory("browser");
76+
const source = this.source.directory("browser");
5777
const depsContainer = this.getDeps(source.directory("."));
5878
return depsContainer
5979
.withWorkdir("/app")
@@ -82,23 +102,21 @@ export class AtomicServer {
82102

83103
@func()
84104
docsFolder(): Directory {
85-
const moduleSource = dag.currentModule().source();
86-
const actualDocsDirectory = moduleSource.directory("docs");
105+
const actualDocsDirectory = this.source.directory("docs");
87106

88107
const docsContainer = dag
89108
.container()
90109
.from(RUST_IMAGE)
91110
.withExec(["cargo", "install", "mdbook"])
92111
.withExec(["cargo", "install", "mdbook-linkcheck"]);
93112
return docsContainer
94-
.withDirectory("/docs", actualDocsDirectory) // Use the derived path
113+
.withMountedDirectory("/docs", actualDocsDirectory)
95114
.withWorkdir("/docs")
96115
.withExec(["mdbook", "build"])
97116
.directory("/docs/book/html");
98117
}
99118
@func()
100119
typedocPublish(@argument() netlifyAuthToken: Secret): Promise<string> {
101-
const source = dag.currentModule().source().directory("browser");
102120
const browserDir = this.buildBrowser();
103121
return browserDir
104122
.withWorkdir("/app")
@@ -139,13 +157,13 @@ export class AtomicServer {
139157
"yes | pnpm install --frozen-lockfile --shamefully-hoist",
140158
]);
141159

142-
// Copy the rest of the source
160+
// Copy the source so installed dependencies persist in the container
143161
return depsContainer.withDirectory("/app", source);
144162
}
145163

146164
@func()
147165
rustBuild(): Container {
148-
const source = dag.currentModule().source();
166+
const source = this.source;
149167
const cargoCache = dag.cacheVolume("cargo");
150168

151169
const rustContainer = dag
@@ -173,7 +191,12 @@ export class AtomicServer {
173191

174192
return sourceContainer
175193
.withExec(["cargo", "build", "--release"])
176-
.withExec(["./target/release/atomic-server", "--version"]);
194+
.withExec(["./target/release/atomic-server", "--version"])
195+
.withExec([
196+
"cp",
197+
"/code/target/release/atomic-server",
198+
"/atomic-server-binary",
199+
]);
177200
}
178201

179202
@func()
@@ -183,12 +206,12 @@ export class AtomicServer {
183206

184207
@func()
185208
rustClippy(): Promise<string> {
186-
const source = dag.currentModule().source();
209+
const source = this.source;
187210
const rustContainer = dag
188211
.container()
189212
.from(RUST_IMAGE)
190213
.withExec(["rustup", "component", "add", "clippy"])
191-
.withDirectory("/code", source)
214+
.withMountedDirectory("/code", source)
192215
.withWorkdir("/code");
193216

194217
return rustContainer
@@ -204,25 +227,25 @@ export class AtomicServer {
204227

205228
@func()
206229
rustFmt(): Promise<string> {
207-
const source = dag.currentModule().source();
230+
const source = this.source;
208231
const rustContainer = dag
209232
.container()
210233
.from(RUST_IMAGE)
211234
.withExec(["rustup", "component", "add", "rustfmt"])
212-
.withDirectory("/code", source)
235+
.withMountedDirectory("/code", source)
213236
.withWorkdir("/code");
214237

215238
return rustContainer.withExec(["cargo", "fmt", "--check"]).stdout();
216239
}
217240

218241
@func()
219242
rustCrossBuild(@argument() target: string): Container {
220-
const source = dag.currentModule().source();
243+
const source = this.source;
221244
const rustContainer = dag
222245
.container()
223246
.from(RUST_IMAGE)
224247
.withExec(["cargo", "install", "cross"])
225-
.withDirectory("/code", source)
248+
.withMountedDirectory("/code", source)
226249
.withWorkdir("/code");
227250

228251
return rustContainer
@@ -232,7 +255,8 @@ export class AtomicServer {
232255

233256
@func()
234257
ee(@argument() netlifyAuthToken: Secret): Promise<string> {
235-
const source = dag.currentModule().source();
258+
const e2eSource = this.source.directory("browser/e2e");
259+
236260
// Setup Playwright container - debug and fix package manager
237261
const playwrightContainer = dag
238262
.container()
@@ -249,20 +273,13 @@ export class AtomicServer {
249273
.withExec(["pnpm", "dlx", "playwright", "install", "--with-deps"])
250274
.withExec(["npm", "install", "-g", "netlify-cli"]);
251275

252-
// Get the atomic-server binary from the build
253-
const atomicServerBinary = this.rustBuild().file(
254-
"/code/target/release/atomic-server"
255-
);
276+
// Get the atomic-server binary from the build (copied out of cache)
277+
const atomicServerBinary = this.rustBuild().file("/atomic-server-binary");
256278

257279
// Setup e2e test environment
258280
const e2eContainer = playwrightContainer
259-
.withFile(
260-
"/app/e2e/package.json",
261-
source.file("browser/e2e/package.json")
262-
)
263-
.withWorkdir("/app/e2e")
264-
.withExec(["pnpm", "install"])
265-
.withDirectory("/app", source.directory("browser/e2e"))
281+
.withMountedDirectory("/app", e2eSource)
282+
.withWorkdir("/app")
266283
.withExec(["pnpm", "install"])
267284
.withEnvVariable("LANGUAGE", "en_GB")
268285
.withEnvVariable("DELETE_PREVIOUS_TEST_DRIVES", "false")
@@ -272,13 +289,23 @@ export class AtomicServer {
272289
})
273290
.withSecretVariable("NETLIFY_AUTH_TOKEN", netlifyAuthToken);
274291

275-
// Run the tests with atomic-server in background
276-
const testResult = e2eContainer
292+
// Start atomic-server in background
293+
const serverStarted = e2eContainer
294+
.withExec([
295+
"/bin/sh",
296+
"-c",
297+
"nohup /atomic-server-bin --initialize > /dev/null 2>&1 & echo 'Server started'",
298+
])
299+
.withExec(["sleep", "3"]);
300+
301+
// Run the tests from the correct directory (always succeed to collect artifacts)
302+
const testResult = serverStarted
277303
.withExec([
278304
"/bin/sh",
279305
"-c",
280-
"nohup /atomic-server-bin --initialize & pnpm run test-e2e && zip -r test.zip /app/e2e/playwright-report",
306+
"pnpm run test-e2e || echo 'Tests completed with failures, but continuing to collect artifacts'",
281307
])
308+
.withExec(["zip", "-r", "test.zip", "playwright-report"])
282309
.withExec(["unzip", "-o", "test.zip", "-d", "/artifact"]);
283310

284311
// Upload test results to Netlify
@@ -287,7 +314,7 @@ export class AtomicServer {
287314
"netlify",
288315
"deploy",
289316
"--dir",
290-
"/artifact/app/e2e/playwright-report",
317+
"/artifact/app/playwright-report",
291318
"--prod",
292319
"--site",
293320
"atomic-tests",

0 commit comments

Comments
 (0)