Add env docker meta (#83)

* experiment

* Fix building

* Fix script
This commit is contained in:
ChristopherHX
2023-01-19 19:15:47 +01:00
committed by GitHub
parent c21a1af5c4
commit 9cc06ea302
+55 -6
View File
@@ -37,20 +37,22 @@ param(
[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 += $push -eq $True ? @("--push") : @()
$arguments += $progress -ne 'plain' ? @("--progress=$progress") : @("--progress=plain")
$tags.Count -ne 0 ? ($tags | ForEach-Object { $arguments += @("--tag=$_") }) : ""
$arguments += $tag -ne '' ? @("--tag=$tag") : @()
$intermediatetag = "localhost:8192/intermediate:$($platform.Replace("/", "-"))"
$arguments += @(
"--tag=${intermediatetag}",
"--build-arg=NODE_VERSION=${node}",
"--build-arg=DISTRO=${distro}",
"--build-arg=TYPE=${type}",
@@ -65,8 +67,55 @@ $arguments += @(
"--build-arg=FROM_IMAGE=${from_image}",
"--build-arg=FROM_TAG=${from_tag}",
"--file=./linux/${image}/Dockerfile",
"--platform=${platforms}",
"--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 'plain' ? @("--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