Skip to content

Commit 2efd3cc

Browse files
authored
[Internal] Rework runner/.justfile as a module (#4139)
1 parent 9804a7c commit 2efd3cc

3 files changed

Lines changed: 99 additions & 89 deletions

File tree

.justfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
# * website/.justfile – Building and previewing the React landing page
1212
# * .tox.justfile – Running Python tests via tox
1313

14-
# Run tests via tox
15-
mod tox '.tox.justfile'
14+
set minimum-version := '1.55.0'
1615

17-
set allow-duplicate-recipes
16+
[doc("Building and uploading dstack runner and shim")]
17+
mod runner "runner/.justfile"
18+
19+
[doc("Running Python tests via tox")]
20+
mod tox ".tox.justfile"
1821

19-
import "runner/.justfile"
22+
set allow-duplicate-recipes
2023

2124
import "frontend/.justfile"
2225

runner/.justfile

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# Build Process:
1111
# - Runner and shim are always built for linux (GOOS=linux is the only supported OS)
12-
# - The target architecture is configurable via DSTACK_SHIM_BUILD_ARCH (or `just --set arch ...`)
12+
# - The target architecture is configurable via DSTACK_SHIM_BUILD_ARCH (or `just build --arch ...`)
1313
# - CGO is enabled only for native builds (Linux host with a matching architecture);
1414
# otherwise it is disabled and DCGM support is dropped
1515
#
@@ -24,114 +24,115 @@
2424
# * See README.md for instructions on running dstack server with uploaded binaries
2525
# * Upload is required for testing with standard backends (including SSH fleets)
2626

27-
default:
28-
@just --list
29-
3027
# Version of the runner and shim to upload
31-
export version := env("DSTACK_SHIM_UPLOAD_VERSION", "0.0.0")
28+
version := env("DSTACK_SHIM_UPLOAD_VERSION", "0.0.0")
3229

3330
# S3 bucket to upload binaries to
34-
export s3_bucket := env("DSTACK_SHIM_UPLOAD_S3_BUCKET", "dstack-runner-downloads-stgn")
31+
s3_bucket := env("DSTACK_SHIM_UPLOAD_S3_BUCKET", "dstack-runner-downloads-stgn")
3532

3633
# Target architecture for runner and shim (GOOS is always linux)
37-
export arch := env("DSTACK_SHIM_BUILD_ARCH", "amd64")
38-
39-
# Download URLs
40-
export runner_download_url := "s3://" + s3_bucket + "/" + version + "/binaries/dstack-runner-linux-" + arch
41-
export shim_download_url := "s3://" + s3_bucket + "/" + version + "/binaries/dstack-shim-linux-" + arch
34+
arch := env("DSTACK_SHIM_BUILD_ARCH", "amd64")
4235

4336
# Go toolchain image for running tests in a container (keep in sync with go.mod)
44-
export go_version := env("DSTACK_GO_VERSION", "1.25")
37+
go_version := env("DSTACK_GO_VERSION", "1.25")
38+
39+
[doc("Build both runner and shim")]
40+
[arg("arch", long)]
41+
build arch=arch: (build-runner-binary arch) (build-shim-binary arch)
42+
@echo "Build complete! linux/{{arch}} binaries are in their respective cmd directories."
43+
44+
[doc("Clean build artifacts")]
45+
clean:
46+
rm -f ./cmd/runner/runner
47+
rm -f ./cmd/shim/shim
48+
@echo "Build artifacts cleaned!"
49+
50+
[doc("Run tests for runner and shim (native; requires a Linux host)")]
51+
test:
52+
go test -v ./...
53+
54+
# Examples:
55+
# just test-in-container # short suite, all packages
56+
# just test-in-container -run TestPullImage ./internal/shim/
57+
[doc("Run tests for runner and shim in a Linux container (use on macOS/Windows, where native builds are not available)")]
58+
test-in-container *args="-short ./...":
59+
docker run --rm -t \
60+
-v .:/src -w /src \
61+
-v dstack-go-mod:/go/pkg/mod \
62+
-v dstack-go-build:/root/.cache/go-build \
63+
-v /var/run/docker.sock:/var/run/docker.sock \
64+
golang:{{go_version}} \
65+
go test -race {{args}}
66+
67+
[doc("Upload both runner and shim to S3")]
68+
[arg("arch", long)]
69+
upload arch=arch: (upload-runner-binary arch) (upload-shim-binary arch)
4570

46-
# Build runner
4771
[private]
48-
build-runner-binary:
49-
#!/usr/bin/env bash
50-
set -e
51-
echo "Building runner for linux/$arch"
52-
cd {{source_directory()}}/cmd/runner && CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"
53-
echo "Runner build complete!"
72+
[doc("Build runner")]
73+
[arg("arch", long)]
74+
[working-directory: "./cmd/runner"]
75+
build-runner-binary arch=arch:
76+
@echo "Building runner for linux/{{arch}}"
77+
CGO_ENABLED=0 GOOS=linux GOARCH={{arch}} go build -ldflags "-X 'main.Version={{version}}' -extldflags '-static'"
78+
@echo "Runner build (version: {{version}}) complete!"
5479

55-
# Build shim
5680
[private]
57-
build-shim-binary:
81+
[doc("Build shim")]
82+
[arg("arch", long)]
83+
[working-directory: "./cmd/shim"]
84+
build-shim-binary arch=arch:
5885
#!/usr/bin/env bash
5986
set -e
60-
cd {{source_directory()}}/cmd/shim
61-
echo "Building shim for linux/$arch"
87+
echo "Building shim for linux/{{arch}}"
6288
host_arch=$(uname -m)
6389
case "$host_arch" in
6490
x86_64) host_arch=amd64 ;;
6591
aarch64 | arm64) host_arch=arm64 ;;
6692
esac
67-
if [ "$(uname -s)" = "Linux" ] && [ "$host_arch" = "$arch" ]; then
68-
CGO_ENABLED=1 GOOS=linux GOARCH=$arch go build -ldflags "-X 'main.Version=$version'"
93+
if [ "$(uname -s)" = "Linux" ] && [ "$host_arch" = "{{arch}}" ]; then
94+
CGO_ENABLED=1 GOOS=linux GOARCH={{arch}} go build -ldflags "-X 'main.Version={{version}}'"
6995
else
70-
echo "WARNING: Cross-compiling to linux/$arch, disabling CGO (DCGM unavailable)"
71-
CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -ldflags "-X 'main.Version=$version' -extldflags '-static'"
96+
echo "WARNING: Cross-compiling to linux/{{arch}}, disabling CGO (DCGM unavailable)"
97+
CGO_ENABLED=0 GOOS=linux GOARCH={{arch}} go build -ldflags "-X 'main.Version={{version}}' -extldflags '-static'"
7298
fi
73-
echo "Shim build (version: $version) complete!"
74-
75-
# Build both runner and shim
76-
build-runner: build-runner-binary build-shim-binary
77-
echo "Build complete! linux/$arch binaries are in their respective cmd directories."
99+
echo "Shim build (version: {{version}}) complete!"
78100
79-
# Clean build artifacts
80-
clean-runner:
81-
rm -f {{source_directory()}}/cmd/runner/runner
82-
rm -f {{source_directory()}}/cmd/shim/shim
83-
echo "Build artifacts cleaned!"
84-
85-
# Run tests for runner and shim (native; requires a Linux host)
86-
test-runner:
87-
cd {{source_directory()}} && go test -v ./...
88-
89-
# Run tests for runner and shim in a Linux container (use on macOS/Windows, where native builds are not available)
90-
# Examples:
91-
# just test-runner-in-container # short suite, all packages
92-
# just test-runner-in-container -run TestPullImage ./internal/shim/
93-
test-runner-in-container *args="-short ./...":
94-
docker run --rm -t \
95-
-v {{source_directory()}}:/src -w /src \
96-
-v dstack-go-mod:/go/pkg/mod \
97-
-v dstack-go-build:/root/.cache/go-build \
98-
-v /var/run/docker.sock:/var/run/docker.sock \
99-
golang:{{go_version}} \
100-
go test -race {{args}}
101-
102-
# Validate shim is built for the configured linux architecture
103101
[private]
104-
validate-shim-binary:
102+
[doc("Validate shim is built for the configured linux architecture")]
103+
[arg("arch", long)]
104+
validate-shim-binary arch=arch:
105105
#!/usr/bin/env bash
106106
set -e
107-
case "$arch" in
107+
case "{{arch}}" in
108108
amd64) expected="x86-64" ;;
109109
arm64) expected="ARM aarch64" ;;
110-
*) echo "Error: Unsupported arch '$arch'"; exit 1 ;;
110+
*) echo "Error: Unsupported arch '{{arch}}'"; exit 1 ;;
111111
esac
112-
if ! file {{source_directory()}}/cmd/shim/shim | grep -q "ELF 64-bit LSB executable, $expected"; then
113-
echo "Error: Shim must be built for linux/$arch for upload"
112+
if [[ ! -f ./cmd/shim/shim ]]; then
113+
echo "Error: Shim binary not found"
114+
exit 1
115+
fi
116+
if ! file ./cmd/shim/shim | grep -q "ELF 64-bit LSB executable, $expected"; then
117+
echo "Error: Shim must be built for linux/{{arch}} for upload"
114118
exit 1
115119
fi
116120
117-
# Upload both runner and shim to S3
118-
upload-runner: upload-runner-binary upload-shim-binary
121+
[private]
122+
[doc("Upload runner to S3")]
123+
[arg("arch", long)]
124+
upload-runner-binary arch=arch: (build-runner-binary arch)
125+
aws s3 cp ./cmd/runner/runner s3://{{s3_bucket}}/{{version}}/binaries/dstack-runner-linux-{{arch}} --acl public-read
126+
@echo "Uploaded runner to S3"
119127

120-
# Upload runner to S3
121128
[private]
122-
upload-runner-binary:
123-
#!/usr/bin/env bash
124-
set -e
125-
just build-runner-binary
126-
aws s3 cp {{source_directory()}}/cmd/runner/runner "{{runner_download_url}}" --acl public-read
127-
echo "Uploaded runner to S3"
129+
[doc("Upload shim to S3")]
130+
[arg("arch", long)]
131+
upload-shim-binary arch=arch: (build-shim-binary arch) (validate-shim-binary arch)
132+
aws s3 cp ./cmd/shim/shim s3://{{s3_bucket}}/{{version}}/binaries/dstack-shim-linux-{{arch}} --acl public-read
133+
@echo "Uploaded shim to S3"
128134

129-
# Upload shim to S3
135+
[default]
130136
[private]
131-
upload-shim-binary:
132-
#!/usr/bin/env bash
133-
set -e
134-
just build-shim-binary
135-
just validate-shim-binary
136-
aws s3 cp {{source_directory()}}/cmd/shim/shim "{{shim_download_url}}" --acl public-read
137-
echo "Uploaded shim to S3"
137+
default:
138+
@just --list --unsorted

runner/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For overview of `dstack-shim` and `dstack-runner`, see [/contributing/RUNNER-AND
99
Run shim and runner tests on any OS inside a Docker container:
1010

1111
```shell
12-
just test-runner-in-container
12+
just test-in-container
1313
```
1414

1515
## Running locally (standalone)
@@ -55,27 +55,33 @@ You can test the built shim and runner with `dstack` using standard backends (in
5555
> [!NOTE]
5656
> To run with standard backends, both the runner and shim must be built for linux.
5757

58-
Build the runner and shim and upload them to S3 using `just` (see [`justfile`](justfile)).
58+
Build the runner and shim and upload them to S3 using `just` (see [`.justfile`](.justfile)).
5959

6060
> [!IMPORTANT]
61-
> Before running any `just` commands that upload to S3, you must set the following environment variables:
61+
> Before running any `just` commands that upload to S3, configure the upload via environment variables:
6262
>
6363
> ```shell
6464
> export DSTACK_SHIM_UPLOAD_VERSION="your-version"
6565
> export DSTACK_SHIM_UPLOAD_S3_BUCKET="your-bucket"
66+
> export DSTACK_SHIM_BUILD_ARCH="arm64" # Defaults to amd64 if not set
6667
> ```
6768
>
68-
> These variables are required and must be set before running any upload commands.
69+
> `DSTACK_SHIM_UPLOAD_VERSION` and `DSTACK_SHIM_UPLOAD_S3_BUCKET` are required and must be set before
70+
> running any upload commands. `DSTACK_SHIM_BUILD_ARCH` is optional.
71+
>
72+
> Set the target architecture via `DSTACK_SHIM_BUILD_ARCH`, not via `just upload --arch ...` — the
73+
> download URLs below are derived from the environment variable, so `--arch` would upload to one
74+
> architecture while the URLs point at another.
6975

7076
```shell
71-
just upload-runner
77+
just upload
7278
```
7379

7480
To use the built shim and runner with the `dstack` server, pass the URLs via `DSTACK_SHIM_DOWNLOAD_URL` and `DSTACK_RUNNER_DOWNLOAD_URL`:
7581

7682
```shell
77-
export DSTACK_SHIM_DOWNLOAD_URL="https://${DSTACK_SHIM_UPLOAD_S3_BUCKET}.s3.amazonaws.com/${DSTACK_SHIM_UPLOAD_VERSION}/binaries/dstack-shim-linux-amd64"
78-
export DSTACK_RUNNER_DOWNLOAD_URL="https://${DSTACK_SHIM_UPLOAD_S3_BUCKET}.s3.amazonaws.com/${DSTACK_SHIM_UPLOAD_VERSION}/binaries/dstack-runner-linux-amd64"
83+
export DSTACK_SHIM_DOWNLOAD_URL="https://${DSTACK_SHIM_UPLOAD_S3_BUCKET}.s3.amazonaws.com/${DSTACK_SHIM_UPLOAD_VERSION}/binaries/dstack-shim-linux-${DSTACK_SHIM_BUILD_ARCH:-amd64}"
84+
export DSTACK_RUNNER_DOWNLOAD_URL="https://${DSTACK_SHIM_UPLOAD_S3_BUCKET}.s3.amazonaws.com/${DSTACK_SHIM_UPLOAD_VERSION}/binaries/dstack-runner-linux-${DSTACK_SHIM_BUILD_ARCH:-amd64}"
7985
8086
dstack server --log-level=debug
8187
```

0 commit comments

Comments
 (0)