From 4327f6e77fc412bc05d007ae676956bb1464616b Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Fri, 7 Jun 2024 18:30:53 +0800 Subject: [PATCH] Refactor docker build and tag; temporary disable Ubuntu update to latest --- .../workflows/docker-teamcityagent-image.yml | 16 ++++++--- README.md | 14 ++++---- docker-build.ps1 | 26 +++++++++++---- teamcity-agent/Dockerfile | 33 +++++++++++++------ 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/.github/workflows/docker-teamcityagent-image.yml b/.github/workflows/docker-teamcityagent-image.yml index 7f3adba..92af415 100644 --- a/.github/workflows/docker-teamcityagent-image.yml +++ b/.github/workflows/docker-teamcityagent-image.yml @@ -18,6 +18,10 @@ jobs: env: IS_SEMVER_TAG: ${{ false }} IS_TAG: ${{ null }} + DOTNET_SDK_VERSION6_TAG: 6.0-focal + DOTNET_SDK_VERSION7_TAG: 7.0-jammy + DOTNET_SDK_VERSION8_TAG: 8.0-jammy + DOTNET_SDK_VERSION9_TAG: 9.0-preview-noble steps: - uses: actions/checkout@v4 @@ -117,7 +121,7 @@ jobs: id: dotnet6_vers shell: pwsh run: | - $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:6.0-focal sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') + $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:${{ env.DOTNET_SDK_VERSION6_TAG }} sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') Write-Output "Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2])" Write-Output "sdk=$($dotnet_vers[0])" >> $env:GITHUB_OUTPUT Write-Output "aspnet=$($dotnet_vers[1])" >> $env:GITHUB_OUTPUT @@ -127,7 +131,7 @@ jobs: id: dotnet7_vers shell: pwsh run: | - $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:7.0-jammy sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') + $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:=${{ env.DOTNET_SDK_VERSION7_TAG }} sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') Write-Output "Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2])" Write-Output "sdk=$($dotnet_vers[0])" >> $env:GITHUB_OUTPUT Write-Output "aspnet=$($dotnet_vers[1])" >> $env:GITHUB_OUTPUT @@ -137,7 +141,7 @@ jobs: id: dotnet8_vers shell: pwsh run: | - $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:8.0-jammy sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') + $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:${{ env.DOTNET_SDK_VERSION8_TAG }} sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') Write-Output "Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2])" Write-Output "sdk=$($dotnet_vers[0])" >> $env:GITHUB_OUTPUT Write-Output "aspnet=$($dotnet_vers[1])" >> $env:GITHUB_OUTPUT @@ -148,7 +152,7 @@ jobs: id: dotnet9_vers shell: pwsh run: | - $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:9.0-preview-jammy sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') + $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:${{ env.DOTNET_SDK_VERSION9_TAG }} sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') Write-Output "Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2])" Write-Output "sdk=$($dotnet_vers[0])" >> $env:GITHUB_OUTPUT Write-Output "aspnet=$($dotnet_vers[1])" >> $env:GITHUB_OUTPUT @@ -179,6 +183,10 @@ jobs: ASPNET_VERSION9=${{ steps.dotnet9_vers.outputs.aspnet }} DOTNET_VERSION9=${{ steps.dotnet9_vers.outputs.dotnet }} POWERSHELL_VERSION=${{ steps.dotnet9_vers.outputs.pwsh }} + DOTNET_SDK_VERSION6_TAG=${{ env.DOTNET_SDK_VERSION6_TAG }} + DOTNET_SDK_VERSION7_TAG=${{ env.DOTNET_SDK_VERSION7_TAG }} + DOTNET_SDK_VERSION8_TAG=${{ env.DOTNET_SDK_VERSION8_TAG }} + DOTNET_SDK_VERSION9_TAG=${{ env.DOTNET_SDK_VERSION9_TAG }} unused: | DOTNET_SDK_VERSION31=${{ steps.dotnetcore31_vers.outputs.sdk }} ASPNET_VERSION31=${{ steps.dotnetcore31_vers.outputs.aspnet }} diff --git a/README.md b/README.md index 59d0e99..3f62022 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ https://hub.docker.com/r/teslaconsulting/teamcity-agent Update per build. -- TeamCity Agent: `2022.04.5-linux` -- .NET 9 SDK: 9.0.100-preview.2.24157.14 -- .NET 8 SDK: 8.0.203 -- .NET 7 SDK: 7.0.407 -- .NET 6 SDK: 6.0.420 +- TeamCity Agent: `2022.04.7-linux` +- .NET 9 SDK: 9.0.100-preview.4.24267.66 +- .NET 8 SDK: 8.0.301 +- .NET 7 SDK: 7.0.410 +- .NET 6 SDK: 6.0.423 - .NET 5 SDK: 5.0.408 - .NETCore 3.1 SDK: 3.1.426 - Powershell Core: 7.5.0-preview.2 -- MinVer Cli: 4.3.0 -- Docker Compose v2: 2.26.0 +- MinVer Cli: 5.0.0 +- Docker Compose v2: 2.27.1 diff --git a/docker-build.ps1 b/docker-build.ps1 index 38fbcc8..7630546 100644 --- a/docker-build.ps1 +++ b/docker-build.ps1 @@ -1,10 +1,14 @@ [CmdletBinding()] param ( - [Parameter(Mandatory = $false)] [string] $Version = '2022.04.5-20240327-01', - [Parameter(Mandatory = $false)] [string] $SourceImageTag = '2022.04.5-linux', + [Parameter(Mandatory = $false)] [string] $Version, # = '2022.04.5-20240327-01', + [Parameter(Mandatory = $false)] [string] $SourceImageTag = '2022.04.7-linux', [Parameter(Mandatory = $false)] [string[]] $DockerRepository = @('teslaconsulting/teamcity-agent'), [Parameter(Mandatory = $false)] [string] $Branch, [Parameter(Mandatory = $false)] [string] $Sha, + [Parameter(Mandatory = $false)] [string] $DotnetSdkVersion6Tag = '6.0-focal', + [Parameter(Mandatory = $false)] [string] $DotnetSdkVersion7Tag = '7.0-jammy', + [Parameter(Mandatory = $false)] [string] $DotnetSdkVersion8Tag = '8.0-jammy', + [Parameter(Mandatory = $false)] [string] $DotnetSdkVersion9Tag = '9.0-preview-noble', [Parameter(Mandatory = $false)] [switch] $NoSquash, [Parameter(Mandatory = $false)] [switch] $Latest, [Parameter(Mandatory = $false)] [switch] $WhatIf @@ -43,6 +47,11 @@ $root = Split-Path $MyInvocation.MyCommand.Path -Parent -Resolve $imageTags = @() private:AddImageTag "sha-$($Sha)" private:AddImageTag $Branch +if (!$Version) { + $Version = ($SourceImageTag.EndsWith('-linux') ? $SourceImageTag.Substring(0, $SourceImageTag.Length - 5) : $SourceImageTag) + (Get-Date).ToString('yyyyMMdd-HHmmss') +} +#Write-Host "Version: $Version" + AddTag '^(\d+)\.\d+(\.\d+)?(-.+)?$' AddTag '^(\d+\.\d+)(\.\d+)?(-.+)?$' AddTag '^(\d+\.\d+(\.\d+)?)(-.+)?$' @@ -101,31 +110,36 @@ private:AddBuildArg 'DOCKER_COMPOSE_VERSION' $docker_compose_version #private:AddBuildArg 'ASPNET_VERSION5' $dotnet_vers[1] #private:AddBuildArg 'DOTNET_VERSION5' $dotnet_vers[2] -$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:6.0-focal sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') +$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:$DotnetSdkVersion6Tag sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') Write-Output ".NET 6.0: Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2])" private:AddBuildArg 'DOTNET_SDK_VERSION6' $dotnet_vers[0] private:AddBuildArg 'ASPNET_VERSION6' $dotnet_vers[1] private:AddBuildArg 'DOTNET_VERSION6' $dotnet_vers[2] -$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:7.0-jammy sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') +$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:$DotnetSdkVersion7Tag sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION') Write-Output ".NET 7.0: Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2])" private:AddBuildArg 'DOTNET_SDK_VERSION7' $dotnet_vers[0] private:AddBuildArg 'ASPNET_VERSION7' $dotnet_vers[1] private:AddBuildArg 'DOTNET_VERSION7' $dotnet_vers[2] -$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:8.0-jammy sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') +$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:$DotnetSdkVersion8Tag sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') Write-Output ".NET 8.0: Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2]) PowerShell:$($dotnet_vers[3].SubString(11))" private:AddBuildArg 'DOTNET_SDK_VERSION8' $dotnet_vers[0] private:AddBuildArg 'ASPNET_VERSION8' $dotnet_vers[1] private:AddBuildArg 'DOTNET_VERSION8' $dotnet_vers[2] -$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:9.0-preview-jammy sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') +$dotnet_vers = $(docker run --rm mcr.microsoft.com/dotnet/sdk:$DotnetSdkVersion9Tag sh -c 'echo $DOTNET_SDK_VERSION;echo $ASPNET_VERSION;echo $DOTNET_VERSION;pwsh --version') Write-Output ".NET 9.0: Version SDK:$($dotnet_vers[0]) ASP.NET:$($dotnet_vers[1]) .NETCore:$($dotnet_vers[2]) PowerShell:$($dotnet_vers[3].SubString(11))" private:AddBuildArg 'DOTNET_SDK_VERSION9' $dotnet_vers[0] private:AddBuildArg 'ASPNET_VERSION9' $dotnet_vers[1] private:AddBuildArg 'DOTNET_VERSION9' $dotnet_vers[2] private:AddBuildArg 'POWERSHELL_VERSION' $dotnet_vers[3].SubString(11) private:AddBuildArg 'POWERSHELL_DISTRIBUTION_CHANNEL' 'PSDocker-DotnetSDK-Ubuntu-20.04' + +private:AddBuildArg 'DOTNET_SDK_VERSION6_TAG' $DotnetSdkVersion6Tag +private:AddBuildArg 'DOTNET_SDK_VERSION7_TAG' $DotnetSdkVersion7Tag +private:AddBuildArg 'DOTNET_SDK_VERSION8_TAG' $DotnetSdkVersion8Tag +private:AddBuildArg 'DOTNET_SDK_VERSION9_TAG' $DotnetSdkVersion9Tag #=========================================================== Write-Verbose "Execute: docker $params" diff --git a/teamcity-agent/Dockerfile b/teamcity-agent/Dockerfile index c2006b4..abd3a70 100644 --- a/teamcity-agent/Dockerfile +++ b/teamcity-agent/Dockerfile @@ -3,12 +3,12 @@ ARG DOTNET_SDK_VERSION6_TAG=6.0-focal ARG DOTNET_SDK_VERSION7_TAG=7.0-jammy ARG DOTNET_SDK_VERSION8_TAG=8.0-jammy -ARG DOTNET_SDK_VERSION9_TAG=9.0-preview-jammy +ARG DOTNET_SDK_VERSION9_TAG=9.0-preview-noble ARG MINVER_IMAGE_TAG=latest ARG MINVER_IMAGE=teslaconsulting/minver-cli:$MINVER_IMAGE_TAG ARG DOCKER_CLI_IMAGE=docker:cli ARG TEAMCITYAGENT_IMAGE_REPOS=jetbrains/teamcity-agent -ARG TEAMCITYAGENT_IMAGE_TAG=2022.04.5-linux +ARG TEAMCITYAGENT_IMAGE_TAG=2022.04.7-linux FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_VERSION9_TAG} AS dotnetsdk9 FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_VERSION8_TAG} AS dotnetsdk8 @@ -101,11 +101,26 @@ ENV DOTNET_SDK_VERSION6=${DOTNET_SDK_VERSION6} \ COPY --from=build /usr /usr -RUN curl -s https://package.perforce.com/perforce.pubkey | gpg --dearmor | tee /usr/share/keyrings/perforce.gpg \ - && echo 'deb [signed-by=/usr/share/keyrings/perforce.gpg] https://package.perforce.com/apt/ubuntu focal release' > /etc/apt/sources.list.d/perforce.list \ - && apt-get update \ - && apt-get upgrade -y \ - && ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \ +# RUN curl -s https://package.perforce.com/perforce.pubkey | gpg --dearmor | tee /usr/share/keyrings/perforce.gpg \ +# && echo 'deb [signed-by=/usr/share/keyrings/perforce.gpg] https://package.perforce.com/apt/ubuntu focal release' > /etc/apt/sources.list.d/perforce.list \ +# && apt-get update \ +# && apt-get upgrade -y \ +# && ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \ +# && chmod 755 /usr/share/powershell/pwsh \ +# && ln -s /usr/share/minver-cli/minver /usr/bin/minver \ +# && chmod +x /usr/share/minver-cli/minver \ +# && rm /usr/local/bin/docker-compose \ +# && ln -s /usr/local/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose \ +# && chmod +x /usr/libexec/docker/cli-plugins/docker-* \ +# # Install module Pester - for root user +# && pwsh -Command "Install-Module -Name Pester -Scope AllUsers -Force" \ +# && dotnet --help \ +# && dotnet --info \ +# && dotnet nuget locals all --clear \ +# && apt-get clean \ +# && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +RUN ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \ && chmod 755 /usr/share/powershell/pwsh \ && ln -s /usr/share/minver-cli/minver /usr/bin/minver \ && chmod +x /usr/share/minver-cli/minver \ @@ -116,9 +131,7 @@ RUN curl -s https://package.perforce.com/perforce.pubkey | gpg --dearmor | tee && pwsh -Command "Install-Module -Name Pester -Scope AllUsers -Force" \ && dotnet --help \ && dotnet --info \ - && dotnet nuget locals all --clear \ - && apt-get clean \ - && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + && dotnet nuget locals all --clear USER buildagent