docker / docker/buildx

Github Actions - Multiplatform Amd64 and Arm64

Open
#2,880 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/qemu
Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the workflow's docker/build-push-action@v6 configuration and the Dockerfile's RUN dotnet publish at line 34. Reproduce the linux/arm64 build, compare it with linux/amd64, and investigate the reported /dev/.buildkit_qemu_emulator exit 139; done when the arm64 build completes or the limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, github-actions
Domain
build-system, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.