Skip to content

Commit 90c8a76

Browse files
committed
Improve NVIDIA toolkit install and add tests for Windows
1 parent 4878164 commit 90c8a76

File tree

3 files changed

+514
-38
lines changed

3 files changed

+514
-38
lines changed

src/main/java/io/github/intisy/docker/MacDockerProvider.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class MacDockerProvider extends DockerProvider {
4646

4747
private final String instanceId;
4848
private final String vmName;
49-
49+
5050
private final Path instanceDir;
5151

5252
private DockerClient dockerClient;
@@ -72,11 +72,11 @@ public void ensureInstalled() throws IOException {
7272
log.info("Lima not found. Downloading Lima {}...", LIMA_VERSION);
7373
downloadAndInstallLima();
7474
}
75-
75+
7676
if (!isLimaInstalled()) {
7777
throw new IOException("Failed to install Lima. Please install manually: brew install lima");
7878
}
79-
79+
8080
log.info("Lima is ready");
8181
}
8282

@@ -101,7 +101,7 @@ private boolean isLimaInstalled() {
101101
Process process = pb.start();
102102
byte[] output = readAllBytes(process.getInputStream());
103103
int exitCode = process.waitFor();
104-
104+
105105
if (exitCode == 0) {
106106
log.debug("Local Lima version: {}", new String(output).trim());
107107
return true;
@@ -110,14 +110,14 @@ private boolean isLimaInstalled() {
110110
log.debug("Local Lima check failed: {}", e.getMessage());
111111
}
112112
}
113-
113+
114114
try {
115115
ProcessBuilder pb = new ProcessBuilder("limactl", "--version");
116116
pb.redirectErrorStream(true);
117117
Process process = pb.start();
118118
byte[] output = readAllBytes(process.getInputStream());
119119
int exitCode = process.waitFor();
120-
120+
121121
if (exitCode == 0) {
122122
log.debug("System Lima version: {}", new String(output).trim());
123123
return true;
@@ -136,9 +136,9 @@ private boolean isLimaInstalled() {
136136
private void downloadAndInstallLima() throws IOException {
137137
String arch = getArch();
138138
String downloadUrl = String.format(LIMA_DOWNLOAD_URL, LIMA_VERSION, LIMA_VERSION, arch);
139-
139+
140140
log.info("Downloading Lima from {}...", downloadUrl);
141-
141+
142142
if (Files.exists(LIMA_DIR)) {
143143
try (java.util.stream.Stream<Path> walk = Files.walk(LIMA_DIR)) {
144144
walk.sorted(java.util.Comparator.reverseOrder())
@@ -147,17 +147,17 @@ private void downloadAndInstallLima() throws IOException {
147147
}
148148
}
149149
Files.createDirectories(LIMA_DIR);
150-
150+
151151
URL url = new URL(downloadUrl);
152152
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
153153
connection.setInstanceFollowRedirects(true);
154154
connection.setRequestMethod("GET");
155-
155+
156156
int responseCode = connection.getResponseCode();
157157
if (responseCode != 200) {
158158
throw new IOException("Failed to download Lima from " + downloadUrl + ". Status code: " + responseCode);
159159
}
160-
160+
161161
try (InputStream is = connection.getInputStream();
162162
GzipCompressorInputStream gzis = new GzipCompressorInputStream(is);
163163
TarArchiveInputStream tis = new TarArchiveInputStream(gzis)) {
@@ -176,9 +176,9 @@ private void downloadAndInstallLima() throws IOException {
176176
}
177177
}
178178
}
179-
179+
180180
Files.write(LIMA_VERSION_FILE, LIMA_VERSION.getBytes());
181-
181+
182182
log.info("Lima {} installed successfully", LIMA_VERSION);
183183
}
184184

@@ -202,20 +202,20 @@ private String getArch() {
202202
@Override
203203
public void start() throws IOException, InterruptedException {
204204
log.info("Starting Docker via Lima VM (instance: {})...", instanceId);
205-
205+
206206
ensureInstalled();
207207
Files.createDirectories(instanceDir);
208-
208+
209209
dockerPort = 2375 + Math.abs(instanceId.hashCode() % 1000);
210-
210+
211211
createAndStartLimaVm();
212-
212+
213213
if (!waitForDocker()) {
214214
String logs = getLimaLogs();
215215
log.error("Lima VM logs:\n{}", logs);
216216
throw new RuntimeException("Docker daemon in Lima VM failed to start. See logs above.");
217217
}
218-
218+
219219
log.info("Docker daemon started in Lima VM (instance: {}, port: {})", instanceId, dockerPort);
220220
}
221221

@@ -224,10 +224,10 @@ public void start() throws IOException, InterruptedException {
224224
*/
225225
private void createAndStartLimaVm() throws IOException, InterruptedException {
226226
String limactl = getLimactlPath();
227-
227+
228228
String vmStatus = runLimaCommand(limactl, "list", "--format", "{{.Name}}:{{.Status}}");
229229
boolean vmExists = vmStatus.contains(vmName + ":");
230-
230+
231231
if (vmExists) {
232232
log.info("Lima VM {} already exists, checking status...", vmName);
233233
if (vmStatus.contains(vmName + ":Running")) {
@@ -243,30 +243,30 @@ private void createAndStartLimaVm() throws IOException, InterruptedException {
243243
return;
244244
}
245245
}
246-
246+
247247
Path configPath = instanceDir.resolve("lima.yaml");
248248
String limaConfig = createLimaConfig();
249249
Files.write(configPath, limaConfig.getBytes());
250-
250+
251251
log.info("Creating Lima VM {} with Docker...", vmName);
252-
252+
253253
ProcessBuilder pb = new ProcessBuilder(limactl, "start", "--name=" + vmName, configPath.toString());
254254
pb.redirectErrorStream(true);
255255
pb.inheritIO();
256256
Process process = pb.start();
257-
257+
258258
boolean completed = process.waitFor(10, TimeUnit.MINUTES);
259259
if (!completed) {
260260
process.destroyForcibly();
261261
throw new RuntimeException("Lima VM creation timed out after 10 minutes");
262262
}
263-
263+
264264
if (process.exitValue() != 0) {
265265
throw new RuntimeException("Failed to create Lima VM. Exit code: " + process.exitValue());
266266
}
267-
267+
268268
vmStartedByUs = true;
269-
269+
270270
ensureDockerRunning();
271271
}
272272

@@ -336,13 +336,13 @@ private String createLimaConfig() {
336336
*/
337337
private void ensureDockerRunning() throws IOException, InterruptedException {
338338
log.debug("Ensuring Docker is running in Lima VM {}...", vmName);
339-
339+
340340
String result = runLimaShellCommand("systemctl is-active docker || true");
341341
if (!"active".equals(result.trim())) {
342342
log.info("Starting Docker in Lima VM...");
343343
runLimaShellCommand("sudo systemctl start docker");
344344
}
345-
345+
346346
String tcpCheck = runLimaShellCommand("ss -tlnp | grep 2375 || true");
347347
if (tcpCheck.trim().isEmpty()) {
348348
log.info("Configuring Docker to listen on TCP...");
@@ -401,16 +401,16 @@ private boolean waitForDocker() throws InterruptedException {
401401
long timeoutMillis = TimeUnit.SECONDS.toMillis(120);
402402
long startTime = System.currentTimeMillis();
403403
int attempts = 0;
404-
404+
405405
while (System.currentTimeMillis() - startTime < timeoutMillis) {
406406
attempts++;
407-
407+
408408
try {
409409
Socket socket = new Socket();
410410
socket.connect(new InetSocketAddress("localhost", dockerPort), 1000);
411411
socket.close();
412412
log.debug("Docker daemon is listening on localhost:{} after {} attempts", dockerPort, attempts);
413-
413+
414414
try {
415415
DockerClient testClient = DockerClient.builder()
416416
.withHost("tcp://localhost:" + dockerPort)
@@ -423,12 +423,12 @@ private boolean waitForDocker() throws InterruptedException {
423423
}
424424
} catch (IOException e) {
425425
}
426-
426+
427427
if (attempts % 20 == 0) {
428-
log.debug("Still waiting for Docker... ({} seconds elapsed)",
428+
log.debug("Still waiting for Docker... ({} seconds elapsed)",
429429
(System.currentTimeMillis() - startTime) / 1000);
430430
}
431-
431+
432432
Thread.sleep(500);
433433
}
434434

@@ -458,17 +458,17 @@ public void stop() {
458458
}
459459
dockerClient = null;
460460
}
461-
461+
462462
if (vmStartedByUs) {
463463
try {
464464
String limactl = getLimactlPath();
465-
465+
466466
log.info("Stopping Lima VM {}...", vmName);
467467
ProcessBuilder pb = new ProcessBuilder(limactl, "stop", vmName);
468468
pb.redirectErrorStream(true);
469469
Process process = pb.start();
470470
process.waitFor(30, TimeUnit.SECONDS);
471-
471+
472472
log.info("Deleting Lima VM {}...", vmName);
473473
pb = new ProcessBuilder(limactl, "delete", vmName, "--force");
474474
pb.redirectErrorStream(true);

0 commit comments

Comments
 (0)