-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrun-docker-build.ps1
More file actions
60 lines (46 loc) · 1.74 KB
/
run-docker-build.ps1
File metadata and controls
60 lines (46 loc) · 1.74 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
57
58
59
60
[CmdletBinding(PositionalBinding = $false)]
param(
[Parameter()] [string] $Image = "libass/jassub",
# Extra args forwarded to `docker run` after the image name.
# You can pass these either via -DockerRunArgs or as trailing args.
[Parameter()] [string[]] $DockerRunArgs,
[Parameter(ValueFromRemainingArguments = $true)] [string[]] $RemainingArgs
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Invoke-Checked([string] $Command, [string[]] $Arguments) {
Write-Verbose ("$Command {0}" -f ($Arguments -join ' '))
& $Command @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed ($LASTEXITCODE): $Command $($Arguments -join ' ')"
}
}
function Resolve-FullPath([string] $Path) {
return (Resolve-Path -LiteralPath $Path).Path
}
function Ensure-Tool([string] $Name) {
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "Required tool not found in PATH: $Name"
}
}
$repoRoot = (Get-Location).Path
Ensure-Tool git
Ensure-Tool docker
# Write-Host "Syncing & updating submodules..."
# Invoke-Checked git @("submodule", "sync")
# Invoke-Checked git @("submodule", "update", "--init", "--recursive", "--force")
Write-Host "Building Docker image $Image ..."
Invoke-Checked docker @("build", "-t", $Image, ".")
# Workflow equivalent:
# docker run --rm -v "${PWD}":/code libass/jassub:latest
$mountPath = Resolve-FullPath $repoRoot
$dockerArgs = @(
"run",
"--rm",
"-v", "${mountPath}:/code",
"${Image}:latest"
)
if ($DockerRunArgs) { $dockerArgs += $DockerRunArgs }
if ($RemainingArgs) { $dockerArgs += $RemainingArgs }
Write-Host "Running build container..."
Invoke-Checked docker $dockerArgs