Skip to content

Commit 1912ba8

Browse files
committed
Try cross build with target images
1 parent d17060a commit 1912ba8

File tree

2 files changed

+59
-66
lines changed

2 files changed

+59
-66
lines changed

.dagger/src/index.ts

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,58 @@ export class AtomicServer {
271271
@func()
272272
rustCrossBuild(@argument() target: string): Container {
273273
const source = this.source;
274+
const cargoCache = dag.cacheVolume("cargo");
275+
276+
// Use rust-musl-cross images which support multi-arch builds
277+
// Map target to the appropriate image tag
278+
let imageTag: string;
279+
switch (target) {
280+
case "x86_64-unknown-linux-musl":
281+
imageTag = "x86_64-musl";
282+
break;
283+
case "aarch64-unknown-linux-musl":
284+
imageTag = "aarch64-musl";
285+
break;
286+
case "armv7-unknown-linux-musleabihf":
287+
imageTag = "armv7-musleabihf";
288+
break;
289+
default:
290+
throw new Error(`Unsupported cross-compilation target: ${target}`);
291+
}
292+
274293
const rustContainer = dag
275294
.container()
276-
.from(RUST_IMAGE)
277-
.withExec(["cargo", "install", "cross"])
278-
.withMountedDirectory("/code", source)
279-
.withWorkdir("/code")
280-
.withExec(["rustup", "target", "add", target]);
295+
.from(`ghcr.io/rust-cross/rust-musl-cross:${imageTag}`)
296+
.withExec(["apt-get", "update", "-qq"])
297+
.withExec(["apt-get", "install", "-y", "nasm"])
298+
.withMountedCache("/home/rust/.cargo/registry", cargoCache);
281299

282-
return rustContainer
283-
.withExec(["cross", "build", "--target", target, "--release"])
284-
.withExec([`./target/${target}/release/atomic-server`, "--version"]);
300+
const sourceContainer = rustContainer
301+
.withFile("/home/rust/src/Cargo.toml", source.file("Cargo.toml"))
302+
.withFile("/home/rust/src/Cargo.lock", source.file("Cargo.lock"))
303+
.withDirectory("/home/rust/src/server", source.directory("server"))
304+
.withDirectory("/home/rust/src/lib", source.directory("lib"))
305+
.withDirectory("/home/rust/src/cli", source.directory("cli"))
306+
.withMountedCache("/home/rust/src/target", dag.cacheVolume("rust-target"))
307+
.withWorkdir("/home/rust/src")
308+
.withExec(["cargo", "fetch"]);
309+
310+
// Include frontend assets for the server build
311+
const browserDir = this.jsBuild().directory("/app/data-browser/dist");
312+
const containerWithAssets = sourceContainer.withDirectory(
313+
"/home/rust/src/server/assets_tmp",
314+
browserDir
315+
);
316+
317+
// Build using the pre-configured cross-compilation environment
318+
return containerWithAssets
319+
.withExec(["cargo", "build", "--target", target, "--release"])
320+
.withExec([`./target/${target}/release/atomic-server`, "--version"])
321+
.withExec([
322+
"cp",
323+
`./target/${target}/release/atomic-server`,
324+
"/atomic-server-binary",
325+
]);
285326
}
286327

287328
@func()
@@ -378,9 +419,7 @@ export class AtomicServer {
378419
const crossBuildContainer = this.rustCrossBuild(
379420
"x86_64-unknown-linux-musl"
380421
);
381-
const binaryFile = crossBuildContainer.file(
382-
"/code/target/x86_64-unknown-linux-musl/release/atomic-server"
383-
);
422+
const binaryFile = crossBuildContainer.file("/atomic-server-binary");
384423

385424
// Create deployment container with SSH client
386425
const deployContainer = dag
@@ -431,24 +470,4 @@ export class AtomicServer {
431470

432471
return `Deployment to ${remoteHost} completed successfully:\n${deployResult}`;
433472
}
434-
435-
@func()
436-
async deployStaging(
437-
@argument() remoteUser: Secret,
438-
@argument() sshPrivateKey: Secret
439-
): Promise<string> {
440-
return this.deployServer(
441-
"staging.atomicdata.dev",
442-
remoteUser,
443-
sshPrivateKey
444-
);
445-
}
446-
447-
@func()
448-
async deployProduction(
449-
@argument() remoteUser: Secret,
450-
@argument() sshPrivateKey: Secret
451-
): Promise<string> {
452-
return this.deployServer("atomicdata.dev", remoteUser, sshPrivateKey);
453-
}
454473
}

.github/workflows/deployment.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,15 @@ jobs:
2020
environment: ${{ inputs.environment }}
2121
runs-on: ubuntu-latest
2222
env:
23-
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
23+
REMOTE_USER: ${{ secrets.REMOTE_USER }}
24+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
2425
steps:
25-
- uses: actions/checkout@v2
26-
27-
- uses: earthly/actions-setup@v1
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- name: Deploy using Dagger
29+
uses: dagger/[email protected]
2830
with:
29-
github-token: ${{ secrets.GITHUB_TOKEN }}
3031
version: "latest"
31-
32-
- name: Set env
33-
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF#refs/*/})" >> $GITHUB_ENV
34-
35-
- name: Earthly build
36-
run: earthly --org ontola --sat henk -P +cross-build -TARGET=x86_64-unknown-linux-musl
37-
38-
- name: Transfer binary rsync
39-
uses: easingthemes/ssh-deploy@v3
40-
env:
41-
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
42-
ARGS: "-rltgoDzvO"
43-
SOURCE: "./artifact/bin/atomic-server-x86_64-unknown-linux-musl"
44-
REMOTE_HOST: ${{ inputs.remote_host }}
45-
REMOTE_USER: ${{ secrets.REMOTE_USER }}
46-
TARGET: ~/
47-
48-
- name: executing remote ssh commands using ssh key
49-
uses: appleboy/ssh-action@master
50-
with:
51-
host: ${{ inputs.remote_host }}
52-
username: ${{ secrets.REMOTE_USER }}
53-
key: ${{ secrets.SSH_PRIVATE_KEY }}
54-
script: |
55-
mv ~/atomic-server-x86_64-unknown-linux-musl ~/atomic-server
56-
cp ~/atomic-server ~/atomic-server-$(date +'%Y-%m-%dT%H:%M:%S')
57-
systemctl stop atomic
58-
./atomic-server export &&
59-
systemctl start atomic
60-
systemctl status atomic
32+
verb: call
33+
args: deploy-server --remote-host ${{ inputs.remote_host }} --remote-user env://REMOTE_USER --ssh-private-key env://SSH_PRIVATE_KEY
34+
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}

0 commit comments

Comments
 (0)