-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.psm1
56 lines (44 loc) · 1.34 KB
/
common.psm1
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
function Build-DockerImage {
[CmdletBinding()]
param (
[string] $ContextDir,
[string] $CurrentGitCommit
)
$parentWorkingDir = Get-Location
$relativePath = $ContextDir.Replace($parentWorkingDir, "")
# Remove the first character, as it's a '\'
$imageName = "robertsmieja/" + $relativePath.Remove(0, 1).Replace("\", "-").ToLower()
Write-Verbose "docker build .${relativePath} --tag ${imageName}:latest --tag ${imageName}:${CurrentGitCommit}"
docker build ".${relativePath}" --tag ${imageName}:latest --tag ${imageName}:${CurrentGitCommit}
docker push "${imageName}:latest"
docker push "${imageName}:${CurrentGitCommit}"
}
function Invoke-Hadolint {
[CmdletBinding()]
param (
[string] $Dockerfile
)
Write-Host "Linting... ${Dockerfile}"
Get-Content $Dockerfile | docker run --rm -i hadolint/hadolint
}
function Get-Dockerfiles {
[CmdletBinding()]
param ()
Get-ChildItem -Recurse -Filter Dockerfile
}
function Get-DirectoriesWithDockerfiles {
[CmdletBinding()]
param()
Get-Dockerfiles | ForEach-Object { $_.Directory.ToString() }
}
function Get-CurrentGitCommit {
[CmdletBinding()]
param(
[boolean] $short = $true
)
[string[]] $args
if ($short) {
$args += "--short"
}
git rev-parse "${args}" HEAD
}