Skip to content

Commit 6c5d1fd

Browse files
committed
Remove some duplication
1 parent d4ba316 commit 6c5d1fd

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

.dagger/src/index.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ import {
77
argument,
88
Secret,
99
File,
10-
type Platform,
1110
} from "@dagger.io/dagger";
1211

1312
const NODE_IMAGE = "node:24";
1413
const RUST_IMAGE = "rust:bookworm";
1514

15+
// See https://github.com/rust-cross/rust-musl-cross?tab=readme-ov-file#prebuilt-images
16+
const TARGET_IMAGE_MAP = {
17+
"x86_64-unknown-linux-musl": "ghcr.io/rust-cross/rust-musl-cross:x86_64-musl",
18+
"aarch64-unknown-linux-musl":
19+
"ghcr.io/rust-cross/rust-musl-cross:aarch64-musl",
20+
"armv7-unknown-linux-musleabihf":
21+
"ghcr.io/rust-cross/rust-musl-cross:armv7-musleabihf",
22+
} as const;
23+
1624
@object()
1725
export class AtomicServer {
1826
source: Directory;
@@ -198,18 +206,7 @@ export class AtomicServer {
198206
const source = this.source;
199207
const cargoCache = dag.cacheVolume("cargo");
200208

201-
let image = RUST_IMAGE;
202-
if (target === "x86_64-unknown-linux-musl") {
203-
image = "ghcr.io/rust-cross/rust-musl-cross:x86_64-musl";
204-
} else if (target === "aarch64-unknown-linux-musl") {
205-
image = "ghcr.io/rust-cross/rust-musl-cross:aarch64-musl";
206-
} else if (target === "armv7-unknown-linux-musleabihf") {
207-
image = "ghcr.io/rust-cross/rust-musl-cross:armv7-musleabihf";
208-
} else {
209-
throw new Error(
210-
`Unknown target: ${target}. Supported targets are: x86_64-unknown-linux-musl, aarch64-unknown-linux-musl, armv7-unknown-linux-musleabihf.`
211-
);
212-
}
209+
const image = TARGET_IMAGE_MAP[target as keyof typeof TARGET_IMAGE_MAP];
213210

214211
const rustContainer = dag
215212
.container()
@@ -502,14 +499,9 @@ export class AtomicServer {
502499
}
503500

504501
@func()
505-
async releaseAssets(
506-
@argument()
507-
targets: string[] = [
508-
"x86_64-unknown-linux-musl",
509-
"aarch64-unknown-linux-musl",
510-
"armv7-unknown-linux-musleabihf",
511-
]
512-
): Promise<Directory> {
502+
async releaseAssets(): Promise<Directory> {
503+
const targets = Object.keys(TARGET_IMAGE_MAP);
504+
513505
const builds = targets.map((target) => {
514506
const container = this.rustBuild(true, target);
515507
return {

CONTRIBUTING.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ That doesn't mean that you should, too, but it means you're less likely to run i
6464
Dagger is a tool that's used for building the project.
6565
The `.dagger` directory and the `dagger.json` file contain most of the configuration.
6666
Install the Dagger CLI from [here](https://docs.dagger.io/install/) and run the `dagger` command in the root of the project.
67-
Then you can run the commands from the `.dagger/src/index.ts` file, e.g. `dagger call build-browser`.
68-
Add `-i` to the command to run in interactive mode, add `--output` to save the output to a folder.
67+
Then you can run the commands from the `.dagger/src/index.ts` file, e.g.
68+
`dagger call build-browser`
69+
70+
If you want to output artifacts (e.g. binaries), use:
71+
`dagger call --interactive release-assets export --pa
72+
th="./build"`
73+
6974
You can pass secrets / ENVS to dagger like so:
7075
`dagger call typedoc-publish --netlify-auth-token="env://NETLIFY_AUTH_TOKEN"`
71-
If Dagger is taking up a lot of storage, run `dagger core engine local-cache prune`.
76+
77+
If Dagger is taking up a lot of storage, run:
78+
`dagger core engine local-cache prune`
79+
80+
Add `-i` to the command to run in interactive mode, add `--output` to save the output to a folder.
7281
Note that the camelCase functions in the `index.ts` file are converted to kebab-case commands in the Dagger API.
7382
Check out the [Dagger docs](https://docs.dagger.io/) for more information.
7483

0 commit comments

Comments
 (0)