Skip to content

Github Actions - Multiplatform Amd64 and Arm64 #2880

Open
@PointSoftware

Description

My github action workflow file is as follows;

name: Build and publish

on:
  workflow_dispatch:
  push:
    branches: [ "main" ]

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    env:
        continue: 'false'

    strategy:
      matrix:
        service:
          - name: 'pointsoftware/gateway-svc'
            path: 'src/GatewayMicroservice/GatewayMicroservice'
          - name: 'pointsoftware/identity-svc'
            path: 'src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice'
          - name: 'pointsoftware/productlifecycle-svc'
            path: 'src/ProductLifeCycleMicroservice/ProductLifeCycle.WebAPI'
          - name: 'pointsoftware/businessPartner-svc'
            path: 'src/BusinessPartnerMicroservice/BusinessPartners.WebAPI'
          - name: 'pointsoftware/barcode-svc'
            path: 'src/BarcodeMicroservice/Barcode.WebAPI'
          - name: 'pointsoftware/system-svc'
            path: 'src/SystemMicroservice/System.WebAPI'
          - name: 'pointsoftware/stockmanagement-svc'
            path: 'src/StockManagementMicroservice/StockManagement.WebAPI'
          - name: 'pointsoftware/web-app'
            path: 'frontend/pointclient'

    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      with:
        fetch-depth: 2

    - name: Check for changes in service path
      run: |
        if git diff --quiet HEAD^ HEAD -- ${{matrix.service.path}}; then
          echo "No changes in ${{matrix.service.path}}. Skipping build"
          echo "continue=false" >> $GITHUB_ENV
        else
          echo "Changes detected in ${{matrix.service.path}}. Proceeding with build"
          echo "continue=true" >> $GITHUB_ENV
        fi

    - name: Set up Docker buildx
      if: env.continue == 'true'
      uses: docker/setup-buildx-action@v2
    
    - name: Login to Docker
      if: env.continue == 'true'
      uses: docker/login-action@v3
      with:
        username: ${{secrets.DOCKER_USERNAME}}
        password: ${{secrets.DOCKER_TOKEN}}
    
    - name: Build and push docker image
      if: env.continue == 'true'
      uses: docker/build-push-action@v6
      with:
        context: .
        file: ${{matrix.service.path}}/Dockerfile
        push: true
        tags: ${{matrix.service.name}}:latest
        platforms: linux/amd64,linux/arm64

Same Dockerfile;

# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 as build
WORKDIR /app
EXPOSE 80

# Copy NuGet configuration
COPY NuGet.config /root/.nuget/NuGet/NuGet.Config

COPY src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice.csproj src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice.csproj
COPY src/IdentityMicroservice/IdentityMicroservice/Application/Application.csproj src/IdentityMicroservice/IdentityMicroservice/Application/Application.csproj
COPY src/IdentityMicroservice/IdentityMicroservice/Domain/Domain.csproj src/IdentityMicroservice/IdentityMicroservice/Domain/Domain.csproj
COPY src/IdentityMicroservice/IdentityMicroservice/Infrastructure/Infrastructure.csproj src/IdentityMicroservice/IdentityMicroservice/Infrastructure/Infrastructure.csproj
COPY src/IdentityMicroservice/IdentityMicroservice/Persistence/Persistence.csproj src/IdentityMicroservice/IdentityMicroservice/Persistence/Persistence.csproj

COPY src/ProductLifeCycleMicroservice/ProductLifeCycle.Application/ProductLifeCycle.Application.csproj src/ProductLifeCycleMicroservice/ProductLifeCycle.Application/ProductLifeCycle.Application.csproj
COPY src/ProductLifeCycleMicroservice/ProductLifeCycle.Domain/ProductLifeCycle.Domain.csproj src/ProductLifeCycleMicroservice/ProductLifeCycle.Domain/ProductLifeCycle.Domain.csproj
COPY src/ProductLifeCycleMicroservice/ProductLifeCycle.Infrastructure/ProductLifeCycle.Infrastructure.csproj src/ProductLifeCycleMicroservice/ProductLifeCycle.Infrastructure/ProductLifeCycle.Infrastructure.csproj
COPY src/ProductLifeCycleMicroservice/ProductLifeCycle.Persistance/ProductLifeCycle.Persistence.csproj src/ProductLifeCycleMicroservice/ProductLifeCycle.Persistance/ProductLifeCycle.Persistence.csproj
COPY src/ProductLifeCycleMicroservice/ProductLifeCycle.UnitTests/ProductLifeCycle.UnitTests.csproj src/ProductLifeCycleMicroservice/ProductLifeCycle.UnitTests/ProductLifeCycle.UnitTests.csproj
COPY src/ProductLifeCycleMicroservice/ProductLifeCycle.WebAPI/ProductLifeCycle.WebAPI.csproj src/ProductLifeCycleMicroservice/ProductLifeCycle.WebAPI/ProductLifeCycle.WebAPI.csproj
COPY src/ProductLifeCycleMicroservice/ProductLifeCylce.GrpcService/ProductLifeCylce.GrpcService.csproj src/ProductLifeCycleMicroservice/ProductLifeCylce.GrpcService/ProductLifeCylce.GrpcService.csproj

COPY src/GatewayMicroservice/GatewayMicroservice/GatewayMicroservice/GatewayMicroservice.csproj src/GatewayMicroservice/GatewayMicroservice/GatewayMicroservice/GatewayMicroservice.csproj

COPY src/BarcodeMicroservice/Barcode.WebAPI/Barcode.WebAPI.csproj src/BarcodeMicroservice/Barcode.WebAPI/Barcode.WebAPI.csproj

# Copy the main application project and publish
COPY src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice
COPY src/IdentityMicroservice/IdentityMicroservice/Application src/IdentityMicroservice/IdentityMicroservice/Application
COPY src/IdentityMicroservice/IdentityMicroservice/Domain src/IdentityMicroservice/IdentityMicroservice/Domain
COPY src/IdentityMicroservice/IdentityMicroservice/Infrastructure src/IdentityMicroservice/IdentityMicroservice/Infrastructure
COPY src/IdentityMicroservice/IdentityMicroservice/Persistence src/IdentityMicroservice/IdentityMicroservice/Persistence
WORKDIR /app/src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice
RUN dotnet publish -c Release -o /app/src/out

# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /apps

# Copy published artifacts from build stage
COPY --from=build /app/src/out .

# Set the entry point
ENTRYPOINT [ "dotnet", "IdentityMicroservice.dll" ]

I encounter an error like the one below, although AMD does it, I get an error in Arm.

#59 [linux/arm64 build 24/24] RUN dotnet publish -c Release -o /app/src/out
#59 81.36 Segmentation fault (core dumped)
#59 ERROR: process "/dev/.buildkit_qemu_emulator /bin/sh -c dotnet publish -c Release -o /app/src/out" did not complete successfully: exit code: 139
#58 [linux/amd64 build 24/24] RUN dotnet publish -c Release -o /app/src/out
#58 CANCELED
------
 > [linux/arm64 build 24/24] RUN dotnet publish -c Release -o /app/src/out:
22.85   Determining projects to restore...
81.36 Segmentation fault (core dumped)
------
 1 warning found (use docker --debug to expand):
 - FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 2)
Dockerfile:34
--------------------
  32 |     COPY src/IdentityMicroservice/IdentityMicroservice/Persistence src/IdentityMicroservice/IdentityMicroservice/Persistence
  33 |     WORKDIR /app/src/IdentityMicroservice/IdentityMicroservice/IdentityMicroservice
  34 | >>> RUN dotnet publish -c Release -o /app/src/out
  35 |     
  36 |     # Runtime stage
--------------------
ERROR: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c dotnet publish -c Release -o /app/src/out" did not complete successfully: exit code: 139
Reference
Check build summary support
Error: buildx failed with: ERROR: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c dotnet publish -c Release -o /app/src/out" did not complete successfully: exit code: 139

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions