-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmosml.ps1
More file actions
56 lines (50 loc) · 1.96 KB
/
mosml.ps1
File metadata and controls
56 lines (50 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env pwsh
if (Get-Command podman -ErrorAction SilentlyContinue) {
$CONTAINER_ENGINE = "podman"
} else {
$CONTAINER_ENGINE = "docker"
}
$IMAGE_NAME = "ghcr.io/francesco146/mosml:latest"
$DOCKERHUB_IMAGE = "docker.io/francescom0/mosml:latest"
$LOCAL_IMAGE_NAME = "mosml:latest"
if (-not (Test-Path -Path "src")) {
New-Item -ItemType Directory -Path "src" | Out-Null
}
$localId = $CONTAINER_ENGINE images -q $LOCAL_IMAGE_NAME 2>$null
$dockerhubId = $CONTAINER_ENGINE images -q $DOCKERHUB_IMAGE 2>$null
$remoteId = $CONTAINER_ENGINE images -q $IMAGE_NAME 2>$null
$selectedImage = $null
if ($localId -ne "") {
Write-Host "Using local image: $LOCAL_IMAGE_NAME" -ForegroundColor Green
$selectedImage = $LOCAL_IMAGE_NAME
} elseif ($dockerhubId -ne "") {
Write-Host "Using Docker Hub image: $DOCKERHUB_IMAGE" -ForegroundColor Green
$selectedImage = $DOCKERHUB_IMAGE
} elseif ($remoteId -ne "") {
Write-Host "Using GHCR image: $IMAGE_NAME" -ForegroundColor Green
$selectedImage = $IMAGE_NAME
} else {
# Prova Docker Hub, poi GHCR, infine build locale
$CONTAINER_ENGINE pull $DOCKERHUB_IMAGE 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Pulled $DOCKERHUB_IMAGE" -ForegroundColor Green
$selectedImage = $DOCKERHUB_IMAGE
} else {
$CONTAINER_ENGINE pull $IMAGE_NAME 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Pulled $IMAGE_NAME" -ForegroundColor Green
$selectedImage = $IMAGE_NAME
} else {
Write-Host "Failed to pull image from registries. Building locally..." -ForegroundColor Yellow
$CONTAINER_ENGINE compose build --quiet
$selectedImage = $LOCAL_IMAGE_NAME
}
}
}
$currentPath = (Get-Location).Path.Replace('\', '/')
# Esegue con il container engine per evitare pull non necessari
$CONTAINER_ENGINE run --rm -it `
--pull=never `
--platform linux/amd64 `
-v "${currentPath}/src:/workspace:Z" `
$selectedImage @args