|
9 | 9 | # |
10 | 10 | # Build Process: |
11 | 11 | # - 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 ...`) |
13 | 13 | # - CGO is enabled only for native builds (Linux host with a matching architecture); |
14 | 14 | # otherwise it is disabled and DCGM support is dropped |
15 | 15 | # |
|
24 | 24 | # * See README.md for instructions on running dstack server with uploaded binaries |
25 | 25 | # * Upload is required for testing with standard backends (including SSH fleets) |
26 | 26 |
|
27 | | -default: |
28 | | - @just --list |
29 | | - |
30 | 27 | # 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") |
32 | 29 |
|
33 | 30 | # 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") |
35 | 32 |
|
36 | 33 | # 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") |
42 | 35 |
|
43 | 36 | # 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) |
45 | 70 |
|
46 | | -# Build runner |
47 | 71 | [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!" |
54 | 79 |
|
55 | | -# Build shim |
56 | 80 | [private] |
57 | | -build-shim-binary: |
| 81 | +[doc("Build shim")] |
| 82 | +[arg("arch", long)] |
| 83 | +[working-directory: "./cmd/shim"] |
| 84 | +build-shim-binary arch=arch: |
58 | 85 | #!/usr/bin/env bash |
59 | 86 | set -e |
60 | | - cd {{source_directory()}}/cmd/shim |
61 | | - echo "Building shim for linux/$arch" |
| 87 | + echo "Building shim for linux/{{arch}}" |
62 | 88 | host_arch=$(uname -m) |
63 | 89 | case "$host_arch" in |
64 | 90 | x86_64) host_arch=amd64 ;; |
65 | 91 | aarch64 | arm64) host_arch=arm64 ;; |
66 | 92 | 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}}'" |
69 | 95 | 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'" |
72 | 98 | 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!" |
78 | 100 |
|
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 |
103 | 101 | [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: |
105 | 105 | #!/usr/bin/env bash |
106 | 106 | set -e |
107 | | - case "$arch" in |
| 107 | + case "{{arch}}" in |
108 | 108 | amd64) expected="x86-64" ;; |
109 | 109 | arm64) expected="ARM aarch64" ;; |
110 | | - *) echo "Error: Unsupported arch '$arch'"; exit 1 ;; |
| 110 | + *) echo "Error: Unsupported arch '{{arch}}'"; exit 1 ;; |
111 | 111 | 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" |
114 | 118 | exit 1 |
115 | 119 | fi |
116 | 120 |
|
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" |
119 | 127 |
|
120 | | -# Upload runner to S3 |
121 | 128 | [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" |
128 | 134 |
|
129 | | -# Upload shim to S3 |
| 135 | +[default] |
130 | 136 | [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 |
0 commit comments