Build Image manually #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Image manually | |
on: | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v1 | |
- uses: azure/docker-login@v1 | |
with: | |
login-server: ghcr.io | |
username: ${{ secrets.docker_user }} | |
password: ${{ secrets.docker_pwd }} | |
- name: Extract branch name | |
run: | | |
$branch = $env:GITHUB_REF.replace('refs/heads/', ''); | |
if ($branch -eq "master") { $branch = "" } else { $branch = "-$branch" }; | |
echo "branch=$branch" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
id: extract_branch | |
- name: Set up commands | |
run: | | |
$images = @("azdevops-build-agent:dev$($env:branch)-bcagent-k8s","azdevops-build-agent:dev$($env:branch)-bcagent", "azdevops-build-agent:dev$($env:branch)-coreagent", "azdevops-build-agent:dev$($env:branch)-vsceagent") | |
$targets = @("ltsc2019", "2004", "ltsc2022") | |
$dockerfiles = @("Dockerfile.bcagent","Dockerfile.bcagent-k8s", "Dockerfile.coreagent", "Dockerfile.vsceagent") | |
$buildCmds = New-Object System.Collections.Generic.List[System.String] | |
$imgPushCmds = New-Object System.Collections.Generic.List[System.String] | |
$manifestCmds = New-Object System.Collections.Generic.List[System.String] | |
$manifestPushCmds = New-Object System.Collections.Generic.List[System.String] | |
for ($i=0; $i -lt $images.length; $i++){ | |
$currBaseImage = "ghcr.io/cosmoconsult/$($images[$i])" | |
$manifestCmd = "docker manifest create $($currBaseImage)" | |
$manifestPushCmd = "docker manifest push $($currBaseImage)" | |
for ($j=0; $j -lt $targets.length; $j++){ | |
$currImage = "$($currBaseImage)-$($targets[$j])" | |
$buildCmd = "docker build -t $($currImage) -f $($dockerfiles[$i]) --build-arg BASE=$($targets[$j]) --build-arg AZP_TOKEN=$env:AZP_TOKEN --build-arg AZP_URL=$env:AZP_URL --isolation hyperv ." | |
$buildCmds.Add($buildCmd) | |
$imgPushCmd = "docker push $($currImage)" | |
$imgPushCmds.Add($imgPushCmd) | |
$manifestCmd = "$manifestCmd $currImage" | |
} | |
$manifestCmds.Add($manifestCmd) | |
$manifestPushCmds.Add($manifestPushCmd) | |
} | |
echo "buildCmdsString=$($buildCmds -join "###")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo "imgPushCmdsString=$($imgPushCmds -join "###")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo "manifestCmdsString=$($manifestCmds -join "###")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo "manifestPushCmdsString=$($manifestPushCmds -join "###")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo $(jq -c '. + { "experimental": \"enabled\" }' "$env:DOCKER_CONFIG\config.json") | Out-File -Encoding ASCII "$env:DOCKER_CONFIG\config.json" | |
env: | |
AZP_TOKEN: ${{ secrets.AZP_TOKEN }} | |
AZP_URL: ${{ secrets.AZP_URL }} | |
- name: Build Docker images | |
run: | | |
$buildCmds = $env:buildCmdsString.Split("###", [StringSplitOptions]::RemoveEmptyEntries) | |
foreach ($buildCmd in $buildCmds) { | |
Write-Host $buildCmd | |
Invoke-Expression $buildCmd | |
} | |
- name: Push Docker images | |
run: | | |
$imgPushCmds = $env:imgPushCmdsString.Split("###", [StringSplitOptions]::RemoveEmptyEntries) | |
foreach ($imgPushCmd in $imgPushCmds) { | |
Write-Host $imgPushCmd | |
Invoke-Expression $imgPushCmd | |
} | |
- name: Create Docker manifests | |
run: | | |
$manifestCmds = $env:manifestCmdsString.Split("###", [StringSplitOptions]::RemoveEmptyEntries) | |
foreach ($manifestCmd in $manifestCmds) { | |
Write-Host $manifestCmd | |
Invoke-Expression $manifestCmd | |
} | |
- name: Push Docker manifests | |
run: | | |
$manifestPushCmds = $env:manifestPushCmdsString.Split("###", [StringSplitOptions]::RemoveEmptyEntries) | |
foreach ($manifestPushCmd in $manifestPushCmds) { | |
Write-Host $manifestPushCmd | |
Invoke-Expression $manifestPushCmd | |
} |