Skip to content

Commit

Permalink
Add Dockerfile for arm64 compilation
Browse files Browse the repository at this point in the history
Add a Dockerfile to compile for arm64 AoT on GitHub Actions (until they have a native arm64 runner).
  • Loading branch information
martincostello committed Nov 27, 2023
1 parent 09568ce commit 2ac90c1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
**/.DS_Store
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/artifacts
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!.git/HEAD
!.git/config
!.git/refs/heads/
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ jobs:
file: ./artifacts/coverage/coverage.cobertura.xml
flags: ${{ matrix.os_name }}

- name: Build for arm64 with Docker
if: runner.os == 'Linux'
run: |
docker build --platform linux/arm64 --output . .
- name: Publish artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
Expand All @@ -77,7 +82,7 @@ jobs:
- name: Create Lambda ZIP file
if: runner.os == 'Linux'
run: |
cd "./artifacts/publish/LondonTravel.Skill/release_linux-x64" || exit
cd "./artifacts/publish/LondonTravel.Skill/release_linux-arm64" || exit
if [ -f "./bootstrap" ]
then
chmod +x ./bootstrap
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0@sha256:bb65e39b662be0265f780afae9cdbfcaa315ef63edb245ad9fb2aa1aabca0b6b AS build
ARG TARGETARCH

RUN dpkg --add-architecture arm64
RUN apt update && apt install --yes clang gcc-aarch64-linux-gnu llvm zlib1g-dev zlib1g-dev:arm64

WORKDIR /source

COPY . .
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet publish ./src/LondonTravel.Skill --runtime linux-arm64 --self-contained true /p:AssemblyName=bootstrap /p:PublishAot=true /p:PublishReadyToRun=true

FROM scratch AS export
ARG TARGETARCH
COPY --from=build /source/artifacts/publish/LondonTravel.Skill/release_*/ ./artifacts/publish/LondonTravel.Skill/release_arm64
2 changes: 1 addition & 1 deletion src/LondonTravel.Skill/aws-lambda-tools-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"region": "eu-west-1",
"configuration": "Release",
"framework": "net8.0",
"function-architecture": "x86_64",
"function-architecture": "arm64",
"function-handler": "LondonTravel.Skill",
"function-memory-size": 192,
"function-runtime": "provided.al2023",
Expand Down

0 comments on commit 2ac90c1

Please sign in to comment.