forked from catthehacker/docker_images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
121 lines (97 loc) · 3.66 KB
/
build.ps1
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
param(
[Parameter(ValueFromPipeline)]
[string]$progress,
[Parameter(ValueFromPipeline)]
[string]$owner = "${env:IMAGE_LABEL_OWNER}",
[Parameter(ValueFromPipeline)]
[string]$repository = "${env:IMAGE_LABEL_REPO}",
[Parameter(ValueFromPipeline)]
[string]$slug = 'catthehacker/ubuntu',
[Parameter(ValueFromPipeline)]
[string[]]$tags,
[Parameter(ValueFromPipeline)]
[string]$tag,
[Parameter(ValueFromPipeline)]
[string]$node = "${env:NODE}",
[Parameter(ValueFromPipeline)]
[string]$distro = 'ubuntu',
[Parameter(ValueFromPipeline)]
[string]$type = "${env:TYPE}",
[Parameter(ValueFromPipeline)]
[string]$runner = "${env:RUNNER}",
[Parameter(ValueFromPipeline)]
[string]$image = 'ubuntu',
[Parameter(ValueFromPipeline)]
[string]$platforms = "${env:PLATFORMS}",
[Parameter(ValueFromPipeline)]
[string]$build_tag = "${env:BUILD_TAG}",
[Parameter(ValueFromPipeline)]
[string]$build_tag_version = "${env:BUILD_TAG_VERSION}",
[Parameter(ValueFromPipeline)]
[string]$build_ref = "${env:BUILD_REF}",
[Parameter(ValueFromPipeline)]
[string]$from_image = "${env:FROM_IMAGE}",
[Parameter(ValueFromPipeline)]
[string]$from_tag = "${env:FROM_TAG}",
[Parameter(ValueFromPipeline)]
[switch]$push
)
$basetags = @()
$regstryid = $(& (Get-Command 'docker').source run --rm -d -p 8192:5000 registry:2)
ForEach($platform in $platforms.Split(",")) {
$arguments = @(
'buildx',
'build'
)
$arguments += $progress -ne '' ? @("--progress=$progress") : @("--progress=plain")
$intermediatetag = "localhost:8192/intermediate:$($platform.Replace("/", "-"))"
$arguments += @(
"--tag=${intermediatetag}",
"--build-arg=NODE_VERSION=${node}",
"--build-arg=DISTRO=${distro}",
"--build-arg=TYPE=${type}",
"--build-arg=RUNNER=${runner}",
"--build-arg=BUILD_DATE=$((Get-Date).ToString('u'))",
"--build-arg=BUILD_OWNER=${owner}",
"--build-arg=BUILD_OWNER_MAIL=${owner}",
"--build-arg=BUILD_REPO=${repository}",
"--build-arg=BUILD_TAG=${build_tag}",
"--build-arg=BUILD_TAG_VERSION=${build_tag_version}",
"--build-arg=BUILD_REF=${build_ref}",
"--build-arg=FROM_IMAGE=${from_image}",
"--build-arg=FROM_TAG=${from_tag}",
"--file=./linux/${image}/Dockerfile",
"--platform=${platform}",
"--load",
'.'
)
& (Get-Command 'docker').source $arguments
# Not using buildx here, because buildx doesn't like a localhost registry
$arguments = @(
'build'
)
$arguments += $progress -ne '' ? @("--progress=$progress") : @("--progress=plain")
$imageid = $(& (Get-Command 'docker').source create "${intermediatetag}")
$envfileContent = $(& (Get-Command 'docker').source cp "${imageid}:/etc/environment" - | tar x --to-stdout)
& (Get-Command 'docker').source rm "${imageid}"
echo "FROM ${intermediatetag}" > Dockerfile.tmp
ForEach($envline in $envfileContent.Split("\n")) {
echo "ENV $envline" >> Dockerfile.tmp
}
$arguments += @(
"--tag=${intermediatetag}",
"--file=./Dockerfile.tmp",
'.'
)
& (Get-Command 'docker').source $arguments
& (Get-Command 'docker').source push ${intermediatetag}
$basetags += @("${intermediatetag}")
}
$arguments = @()
if($push -ne $true) {
$arguments += @("--dry-run")
}
$tags.Count -ne 0 ? ($tags | ForEach-Object { $arguments += @("--tag=$_") }) : ""
$arguments += $tag -ne '' ? @("--tag=$tag") : @()
& (Get-Command 'docker').source buildx imagetools create $arguments $basetags
& (Get-Command 'docker').source stop $regstryid