|
7 | 7 | argument, |
8 | 8 | Secret, |
9 | 9 | File, |
| 10 | + Platform, |
10 | 11 | } from "@dagger.io/dagger"; |
11 | 12 |
|
12 | 13 | const NODE_IMAGE = "node:24"; |
@@ -522,4 +523,52 @@ export class AtomicServer { |
522 | 523 |
|
523 | 524 | return outputDir; |
524 | 525 | } |
| 526 | + |
| 527 | + @func() |
| 528 | + /** Creates a Docker image for a specific target architecture */ |
| 529 | + createDockerImage( |
| 530 | + @argument() target: string = "x86_64-unknown-linux-musl" |
| 531 | + ): Container { |
| 532 | + const binary = this.rustBuild(true, target).file("/atomic-server-binary"); |
| 533 | + |
| 534 | + // Map targets to their corresponding platform strings |
| 535 | + const platformMap = { |
| 536 | + "x86_64-unknown-linux-musl": "linux/amd64" as Platform, |
| 537 | + "aarch64-unknown-linux-musl": "linux/arm64" as Platform, |
| 538 | + "armv7-unknown-linux-musleabihf": "linux/arm/v7" as Platform, |
| 539 | + }; |
| 540 | + |
| 541 | + const platform = platformMap[target as keyof typeof platformMap]; |
| 542 | + if (!platform) { |
| 543 | + throw new Error(`Unknown platform for target: ${target}`); |
| 544 | + } |
| 545 | + |
| 546 | + return dag |
| 547 | + .container({ platform }) |
| 548 | + .from("alpine:latest") |
| 549 | + .withFile("/usr/local/bin/atomic-server", binary) |
| 550 | + .withExec(["chmod", "+x", "/usr/local/bin/atomic-server"]) |
| 551 | + .withEntrypoint(["/usr/local/bin/atomic-server"]) |
| 552 | + .withDefaultArgs([]); |
| 553 | + } |
| 554 | + |
| 555 | + @func() |
| 556 | + /** Creates Docker images for all supported architectures */ |
| 557 | + async createDockerImages(): Promise<void> { |
| 558 | + const targets = Object.keys(TARGET_IMAGE_MAP); |
| 559 | + const tag = "latest"; |
| 560 | + |
| 561 | + // Build the amd64 variant first (this will be our base) |
| 562 | + const amd64Image = this.createDockerImage("x86_64-unknown-linux-musl"); |
| 563 | + |
| 564 | + // Build other variants |
| 565 | + const otherVariants = targets |
| 566 | + .filter((target) => target !== "x86_64-unknown-linux-musl") |
| 567 | + .map((target) => this.createDockerImage(target)); |
| 568 | + |
| 569 | + // Publish the multi-platform image with all variants |
| 570 | + await amd64Image.publish(`joepmeneer/atomic-server:${tag}`, { |
| 571 | + platformVariants: otherVariants, |
| 572 | + }); |
| 573 | + } |
525 | 574 | } |
0 commit comments