Skip to content

Use the current .NET 3.1, 5.0 and 6.0, to reduce the image size #78

Use the current .NET 3.1, 5.0 and 6.0, to reduce the image size

Use the current .NET 3.1, 5.0 and 6.0, to reduce the image size #78

name: Build teamcity-agent image
on:
push:
branches: ["main", "dev*"]
tags: ["*.*.*", "*.*", "!minver-*.*.*", "!minver-*.*"]
pull_request:
branches: [main]
jobs:
docker:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest]
name: build-${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
env:
IS_SEMVER_TAG: ${{ false }}
IS_TAG: ${{ null }}
steps:
- uses: actions/checkout@v4
- name: Check Tag Ref
shell: pwsh
run: |
$isTag='${{ startsWith(github.ref, 'refs/tags/') }}'
Write-Output "IS_TAG=$isTag" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
if ($true -eq $isTag) {
if ($Env:GITHUB_REF_NAME -match '^(\d+\.\d+(\.\d+)?(-.+)?)$') {
Write-Output "IS_SEMVER_TAG=true" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
}
# https://github.com/orgs/community/discussions/26351
# https://github.com/jens-maus/RaspberryMatic/blob/d5044bef3307bc61166377c162569de1a61cf332/.github/workflows/ci.yml#L34-L40
- name: Free disk space
run: |
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
docker rmi $(docker image ls -aq)
df -h
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_HUB_REPOS }}
name=teslaconsulting/teamcity-agent,enable=${{ env.IS_SEMVER_TAG == 'true' }}
flavor: |
latest=false
tags: |
type=match,enable=true,priority=900,prefix=,suffix=,pattern=^(\d+\.\d+(\.\d+)?(-.+)?)$,group=1
type=match,enable=true,priority=890,prefix=,suffix=,pattern=^(\d+\.\d+(\.\d+)?)(-.+)?$,group=1
type=match,enable=true,priority=880,prefix=,suffix=,pattern=^(\d+\.\d+)(\.\d+)?(-.+)?$,group=1
type=match,enable=false,priority=870,prefix=,suffix=,pattern=^(\d+)\.\d+(\.\d+)?(-.+)?$,group=1
type=ref,enable=true,priority=600,event=branch
type=sha,enable=true,priority=500,prefix=sha-,suffix=,format=short
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Get MinVer version
id: minver_version
shell: pwsh
run: |
$minver_help=$(docker run --rm teslaconsulting/minver-cli:latest minver --help)
Write-Output "Minver help:`n$minver_help"
$minver_version=$minver_help[0] -Replace '^[^0-9]+([0-9.]+)[^0-9].*$','$1'
Write-Output "Minver version: $minver_version"
Write-Output "version=$minver_version" >> $env:GITHUB_OUTPUT
- name: Get Docker Compose version
id: docker_compose_version
run: |
DOCKER_COMPOSE_VERSION=$(docker run --rm docker:cli docker compose version)
echo "Docker compose version raw: $DOCKER_COMPOSE_VERSION"
DOCKER_COMPOSE_VERSION=${DOCKER_COMPOSE_VERSION#Docker Compose version v}
echo "Docker compose version only: '$DOCKER_COMPOSE_VERSION'"
echo "version=$DOCKER_COMPOSE_VERSION" >> $GITHUB_OUTPUT
#- name: Get .NETCore 3.1 Versions
# id: dotnetcore31_vers
# shell: pwsh
# run: |
# $dotnet_info_raw=$(docker run --rm mcr.microsoft.com/dotnet/sdk:3.1-focal dotnet --info) -join ' '
# $dotnet_sdk_version=$dotnet_info_raw -replace '^.+\.NET Core SDKs installed:[^0-9]+([0-9.]+)[^0-9].*$','$1'
# $aspnetcore_version=$dotnet_info_raw -replace '^.+Microsoft.AspNetCore.App\s+([0-9.]+)[^0-9.].*$','$1'
# $dotnet_version=$dotnet_info_raw -replace '^.+Microsoft.NETCore.App\s+([0-9.]+)[^0-9.].*$','$1'
# Write-Output "Version SDK:$dotnet_sdk_version ASP.NET:$aspnetcore_version .NETCore:$dotnet_version"
# Write-Output "sdk=$dotnet_sdk_version" >> $env:GITHUB_OUTPUT
# Write-Output "aspnet=$aspnetcore_version" >> $env:GITHUB_OUTPUT
# Write-Output "dotnet=$dotnet_version" >> $env:GITHUB_OUTPUT
#- name: Get .NET 5.0 Versions
# id: dotnet5_vers
# shell: pwsh
# run: |
# $dotnet_vers=$(docker run --rm mcr.microsoft.com/dotnet/sdk:5.0-focal 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
# Write-Output "dotnet=$($dotnet_vers[2])" >> $env:GITHUB_OUTPUT
#- name: Get .NET 6.0 Versions
# 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')
# 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
# Write-Output "dotnet=$($dotnet_vers[2])" >> $env:GITHUB_OUTPUT
- name: Get .NET 7.0 Versions
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')
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
Write-Output "dotnet=$($dotnet_vers[2])" >> $env:GITHUB_OUTPUT
- name: Get .NET 8.0 Versions
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')
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
Write-Output "dotnet=$($dotnet_vers[2])" >> $env:GITHUB_OUTPUT
Write-Output "pwsh=$($dotnet_vers[3].SubString(11))" >> $env:GITHUB_OUTPUT
- name: Get .NET 9.0 Versions
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')
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
Write-Output "dotnet=$($dotnet_vers[2])" >> $env:GITHUB_OUTPUT
Write-Output "pwsh=$($dotnet_vers[3].SubString(11))" >> $env:GITHUB_OUTPUT
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: ./teamcity-agent
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MINVER_VERSION=${{ steps.minver_version.outputs.version }}
DOCKER_COMPOSE_VERSION=${{ steps.docker_compose_version.outputs.version }}
DOTNET_SDK_VERSION7=${{ steps.dotnet7_vers.outputs.sdk }}
ASPNET_VERSION7=${{ steps.dotnet7_vers.outputs.aspnet }}
DOTNET_VERSION7=${{ steps.dotnet7_vers.outputs.dotnet }}
DOTNET_SDK_VERSION8=${{ steps.dotnet8_vers.outputs.sdk }}
ASPNET_VERSION8=${{ steps.dotnet8_vers.outputs.aspnet }}
DOTNET_VERSION8=${{ steps.dotnet8_vers.outputs.dotnet }}
DOTNET_SDK_VERSION9=${{ steps.dotnet9_vers.outputs.sdk }}
ASPNET_VERSION9=${{ steps.dotnet9_vers.outputs.aspnet }}
DOTNET_VERSION9=${{ steps.dotnet9_vers.outputs.dotnet }}
POWERSHELL_VERSION=${{ steps.dotnet9_vers.outputs.pwsh }}
unused: |
DOTNET_SDK_VERSION31=${{ steps.dotnetcore31_vers.outputs.sdk }}
ASPNET_VERSION31=${{ steps.dotnetcore31_vers.outputs.aspnet }}
DOTNET_VERSION31=${{ steps.dotnetcore31_vers.outputs.dotnet }}
DOTNET_SDK_VERSION5=${{ steps.dotnet5_vers.outputs.sdk }}
ASPNET_VERSION5=${{ steps.dotnet5_vers.outputs.aspnet }}
DOTNET_VERSION5=${{ steps.dotnet5_vers.outputs.dotnet }}
DOTNET_SDK_VERSION6=${{ steps.dotnet6_vers.outputs.sdk }}
ASPNET_VERSION6=${{ steps.dotnet6_vers.outputs.aspnet }}
DOTNET_VERSION6=${{ steps.dotnet6_vers.outputs.dotnet }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}