Skip to content

Commit 5e60ade

Browse files
committed
Docker images
1 parent 6c5d1fd commit 5e60ade

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.dagger/src/index.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
argument,
88
Secret,
99
File,
10+
Platform,
1011
} from "@dagger.io/dagger";
1112

1213
const NODE_IMAGE = "node:24";
@@ -522,4 +523,52 @@ export class AtomicServer {
522523

523524
return outputDir;
524525
}
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+
}
525574
}

0 commit comments

Comments
 (0)