From e5714bad78790aa852f3d3652ff2c57fa5245239 Mon Sep 17 00:00:00 2001 From: mu88 <4560672+mu88@users.noreply.github.com> Date: Mon, 20 May 2024 16:15:59 +0200 Subject: [PATCH] build: build and push multi-arch Docker images See https://github.com/dotnet/sdk-container-builds/issues/87 --- .github/workflows/CI_CD.yml | 9 ++- ShopAndEat/ShopAndEat.csproj | 105 +++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI_CD.yml b/.github/workflows/CI_CD.yml index d836e6b..d9bbebb 100644 --- a/.github/workflows/CI_CD.yml +++ b/.github/workflows/CI_CD.yml @@ -38,7 +38,6 @@ jobs: run: dotnet sonarscanner end /d:sonar.token=${{ secrets.SONAR_TOKEN }} - name: Login to DockerHub uses: docker/login-action@v3 - if: ${{ env.IS_RELEASE == 'true' }} with: registry: registry.hub.docker.com username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -52,10 +51,10 @@ jobs: - name: Build Docker if: ${{ env.IS_RELEASE != 'true' }} run: | - dotnet publish ShopAndEat/ShopAndEat.csproj --os linux --arch arm64 /t:PublishContainer '-p:ContainerImageTags="dev"' - dotnet publish ShopAndEat/ShopAndEat.csproj --os linux --arch arm64 /t:PublishContainer '-p:ContainerImageTags="dev-chiseled"' -p:ContainerFamily=jammy-chiseled + dotnet publish ShopAndEat/ShopAndEat.csproj /t:MultiArchPublish '-p:ContainerImageTags="dev"' -p:ContainerRegistry=registry.hub.docker.com + dotnet publish ShopAndEat/ShopAndEat.csproj /t:MultiArchPublish '-p:ContainerImageTags="dev-chiseled"' -p:ContainerFamily=jammy-chiseled -p:ContainerRegistry=registry.hub.docker.com - name: Push Docker if: ${{ env.IS_RELEASE == 'true' }} run: | - dotnet publish ShopAndEat/ShopAndEat.csproj --os linux --arch arm64 /t:PublishContainer '-p:ContainerImageTags="${{ env.VERSION }};latest"' -p:ContainerRegistry=registry.hub.docker.com - dotnet publish ShopAndEat/ShopAndEat.csproj --os linux --arch arm64 /t:PublishContainer '-p:ContainerImageTags="${{ env.VERSION }}-chiseled;latest-chiseled"' -p:ContainerRegistry=registry.hub.docker.com -p:ContainerFamily=jammy-chiseled \ No newline at end of file + dotnet publish ShopAndEat/ShopAndEat.csproj /t:MultiArchPublish '-p:ContainerImageTags="${{ env.VERSION }};latest"' -p:ContainerRegistry=registry.hub.docker.com + dotnet publish ShopAndEat/ShopAndEat.csproj /t:MultiArchPublish '-p:ContainerImageTags="${{ env.VERSION }}-chiseled;latest-chiseled"' -p:ContainerRegistry=registry.hub.docker.com -p:ContainerFamily=jammy-chiseled \ No newline at end of file diff --git a/ShopAndEat/ShopAndEat.csproj b/ShopAndEat/ShopAndEat.csproj index 2a694d1..db51f77 100644 --- a/ShopAndEat/ShopAndEat.csproj +++ b/ShopAndEat/ShopAndEat.csproj @@ -22,4 +22,109 @@ + + + + linux-x64;linux-arm64 + + + + + + + + + <_rids Include="$(RuntimeIdentifiers)"/> + <_InnerBuild Include="$(MSBuildProjectFullPath)" + AdditionalProperties="RuntimeIdentifier=%(_rids.Identity)" + PropertiesToUnset="RuntimeIdentifiers"/> + + + + + + + + + + + + + + <_TagsToPublish Include="$(ContainerImageTags)"/> + + + <_RIDItems Include="linux-x64" GolangArch="amd64"/> + <_RIDItems Include="linux-arm64" GolangArch="arm64"/> + + + + + + + + + <_RIDSForTag Include="@(_TagsToPublish)" RID="%(_RIDItems.Identity)" GolangArch="%(_RIDItems.GolangArch)"/> + <_TagsForRID Include="%(_RIDSForTag.RID)" ContainerTags="@(_RIDSForTag->'%(Identity)-%(GolangArch)', ';')"/> + + + <_ContainerPublish + Include="$(MSBuildProjectFullPath)" + AdditionalProperties="RuntimeIdentifier=%(_TagsForRID.Identity);ContainerImageTags=%(_TagsForRID.ContainerTags)"/> + + + + + + + + + + + + + + + <_RIDSForTag> + $(ContainerRegistry)/$(ContainerRepository):%(Identity)-%(GolangArch) + $(ContainerRegistry)/$(ContainerRepository):%(Identity) + + + + + + + + \ No newline at end of file