Skip to content

Commit

Permalink
Improve multi tags
Browse files Browse the repository at this point in the history
  • Loading branch information
thohng committed Mar 22, 2024
1 parent 4b231fa commit 35e5920
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 63 deletions.
87 changes: 69 additions & 18 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,81 @@ jobs:
matrix:
image: [
# { ver: "6.0", arch: alpine3.17, matching: "6.0" },
{ ver: "6.0", arch: alpine3.18, matching: "6.0" },
{ ver: "6.0", arch: alpine3.19, matching: "6.0" },
{ ver: "6.0", arch: bullseye-slim, matching: "6.0" },
{ ver: "6.0", arch: bookworm-slim, matching: "6.0" },
{ ver: "6.0", arch: focal, matching: "6.0" },
{ ver: "6.0", arch: jammy, matching: "6.0" },
{ ver: "6.0", arch: alpine3.18, matching: "6.0", tags: "6.0-alpine3.18" },
{
ver: "6.0",
arch: alpine3.19,
matching: "6.0",
tags: "6.0-alpine3.19,6.0-alpine,latest",
},
{
ver: "6.0",
arch: bullseye-slim,
matching: "6.0",
tags: "6.0-bullseye-slim",
},
{
ver: "6.0",
arch: bookworm-slim,
matching: "6.0",
tags: "6.0-bookworm-slim",
},
{ ver: "6.0", arch: focal, matching: "6.0", tags: "6.0-focal" },
{ ver: "6.0", arch: jammy, matching: "6.0", tags: "6.0-jammy" },
# { ver: "7.0", arch: alpine3.17, matching: "7.0" },
{ ver: "7.0", arch: alpine3.18, matching: "7.0" },
{ ver: "7.0", arch: alpine3.19, matching: "7.0" },
{ ver: "7.0", arch: bullseye-slim, matching: "7.0" },
{ ver: "7.0", arch: bookworm-slim, matching: "7.0" },
{ ver: "7.0", arch: jammy, matching: "7.0" },
{ ver: "8.0", arch: alpine3.18, matching: "8.0" },
{ ver: "8.0", arch: alpine3.19, matching: "8.0" },
{ ver: "8.0", arch: bookworm-slim, matching: "8.0" },
{ ver: "8.0", arch: jammy, matching: "8.0" },
{ ver: "7.0", arch: alpine3.18, matching: "7.0", tags: "7.0-alpine3.18" },
{
ver: "7.0",
arch: alpine3.19,
matching: "7.0",
tags: "7.0-alpine,7.0-alpine3.19",
},
{
ver: "7.0",
arch: bullseye-slim,
matching: "7.0",
tags: "7.0-bullseye-slim",
},
{
ver: "7.0",
arch: bookworm-slim,
matching: "7.0",
tags: "7.0-bookworm-slim",
},
{ ver: "7.0", arch: jammy, matching: "7.0", tags: "7.0-jammy" },
{ ver: "8.0", arch: alpine3.18, matching: "8.0", tags: "8.0-alpine3.18" },
{
ver: "8.0",
arch: alpine3.19,
matching: "8.0",
tags: "8.0-alpine,8.0-alpine3.19",
},
{
ver: "8.0",
arch: bookworm-slim,
matching: "8.0",
tags: "8.0-bookworm-slim",
},
{ ver: "8.0", arch: jammy, matching: "8.0", tags: "8.0-jammy" },
# { ver: 8.0-preview, arch: jammy-chiseled, matching: "8.0.0-preview" },
{ ver: 9.0-preview, arch: alpine3.19, matching: "9.0.0-preview" },
{
ver: 9.0-preview,
arch: alpine3.19,
matching: "9.0.0-preview",
tags: "9.0-alpine,9.0-alpine3.19",
},
{
ver: 9.0-preview,
arch: bookworm-slim,
matching: "9.0.0-preview",
tags: "9.0-bookworm-slim",
},
{
ver: 9.0-preview,
arch: jammy,
matching: "9.0.0-preview",
tags: "9.0-jammy",
},
{ ver: 9.0-preview, arch: jammy, matching: "9.0.0-preview" },
# { ver: 8.0-preview, arch: jammy-chiseled, matching: "8.0.0-preview" },
]
name: ${{ matrix.image.ver }}-${{ matrix.image.arch }}
Expand Down Expand Up @@ -167,4 +218,4 @@ jobs:
$repos += @('${{ secrets.DOCKER_HUB_REPOS }}')
./docker-build.ps1 -imageTag ${{ env.IMAGE_TAG }} -dockerRepository $repos -Squash -Labels $(@'
${{ steps.meta.outputs.labels }}
'@.Trim()) -Verbose
'@.Trim()) -Tags '${{ matrix.image.tags }}' -Verbose
59 changes: 14 additions & 45 deletions docker-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ param (
[Parameter(Mandatory = $false)] [string] $Path = 'src',
[Parameter(Mandatory = $false)] [string[]] $dockerRepository = @('netlah/aspnet-webssh'),
[Parameter(Mandatory = $false)] [string] $Labels,
[Parameter(Mandatory = $false)] [string] $Tags,
[Parameter(Mandatory = $false)] [switch] $Squash,
[Parameter(Mandatory = $false)] [switch] $WhatIf
)
Expand Down Expand Up @@ -51,24 +52,6 @@ $mappingVersionArch = @{
'^9\.0(\.\d+)?-jammy-chiseled$' = '9.0-jammy-chiseled', 'jammy-chiseled'
}

$mappingMajorRc = @{
'^8\.0\.0-rc[^-]+-alpine(.*)$' = '8.0-alpine'
'^8\.0\.0-rc[^-]+-bookworm-slim$' = '8.0-bookworm-slim'
'^8\.0\.0-rc[^-]+-jammy$' = '8.0-jammy'
'^8\.0\.0-rc[^-]+-jammy-chiseled$' = '8.0-jammy-chiseled'

'^9\.0(\.\d+)?-preview[^-]*-alpine(.*)$' = '9.0-alpine'
'^9\.0(\.\d+)?-preview[^-]*-bookworm-slim$' = '9.0-bookworm-slim'
'^9\.0(\.\d+)?-preview[^-]*-jammy$' = '9.0-jammy'
'^9\.0(\.\d+)?-preview[^-]*-jammy-chiseled$' = '9.0-jammy-chiseled'

'^9\.0(\.\d+)?-rc[^-]*-alpine(.*)$' = '9.0-alpine'
'^9\.0(\.\d+)?-rc[^-]*-bookworm-slim$' = '9.0-bookworm-slim'
'^9\.0(\.\d+)?-rc[^-]*-jammy$' = '9.0-jammy'
'^9\.0(\.\d+)?-rc[^-]*-jammy-chiseled$' = '9.0-jammy-chiseled'
}

$latestTag = '6.0-alpine'

# sdkMajor mappings arch
$mappingArch = @{
Expand Down Expand Up @@ -107,50 +90,36 @@ $mappingArch = @{
'9.0-jammy-chiseled' = 'debian' #ubuntu 22.04 LTS
}

function getVersionArch($imageTag) {
foreach ($entry in $mappingVersionArch.GetEnumerator()) {
if ($imageTag -match $entry.Key) {
return [string[]] $entry.Value
}
}
}

function getMajorRc($imageTag) {
foreach ($entry in $mappingMajorRc.GetEnumerator()) {
if ($imageTag -match $entry.Key) {
return [string] $entry.Value
}
}
function private:AddDockerImage($image) {
if ($image -And !($script:dockerImages -Contains $image)) {
$script:dockerImages += @($image)
}
}


$versionArches = getVersionArch $imageTag
foreach ($entry in $mappingVersionArch.GetEnumerator()) {
if ($imageTag -match $entry.Key) {
$versionArches = [string[]] $entry.Value
}
}

$imageTagMajor = $versionArches | Select-Object -Index 0
if ($imageTagMajor) {
$imageArch = $mappingArch[$imageTagMajor]
}

$imageTagMajorRc = getMajorRc $imageTag

if (!$imageTag -or !$imageTagMajor -or !$imageArch) {
Write-Error "SDK Image Tag '$imageTag' is not supported" -ErrorAction Stop
}

Write-Output "Labels (raw): $Labels"
$labelStrs = $Labels.Trim() -split '\r|\n|;|,' | Where-Object { $_ }
$tagStrs = $Tags.Trim() -split '\r|\n|;|,' | Where-Object { $_ }

$dockerImages = @()
foreach ($dockerRepos in $dockerRepository) {
$dockerImages += @("$($dockerRepos):$($imageTag)")
if ($imageTag -ne $imageTagMajor) {
$dockerImages += @("$($dockerRepos):$($imageTagMajor)")
}
if ($imageTagMajorRc -and $imageTag -ne $imageTagMajorRc) {
$dockerImages += @("$($dockerRepos):$($imageTagMajorRc)")
}
if ($latestTag -eq $imageTagMajor -or $latestTag -eq $imageTag) {
$dockerImages += @("$($dockerRepos):latest")
AddDockerImage "$($dockerRepos):$($imageTag)"
foreach ($tag1 in $tagStrs) {
AddDockerImage "$($dockerRepos):$($tag1)"
}
}

Expand Down

0 comments on commit 35e5920

Please sign in to comment.