From 29c9fc79a8a9853711edd0ec81f8a37d166e3cf7 Mon Sep 17 00:00:00 2001 From: martincostello Date: Mon, 27 Nov 2023 10:58:02 +0000 Subject: [PATCH] Add Dockerfile for arm64 compilation Add a Dockerfile to compile for arm64 AoT on GitHub Actions (until they have a native arm64 runner). --- .dockerignore | 26 +++++++++++++++++++ .github/dependabot.yml | 8 ++++++ .github/workflows/build.yml | 7 ++++- Dockerfile | 15 +++++++++++ .../aws-lambda-tools-defaults.json | 2 +- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..cb71a42f --- /dev/null +++ b/.dockerignore @@ -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/ diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7f2f1b2f..35488cd4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,13 @@ version: 2 updates: +- package-ecosystem: docker + directory: "/" + schedule: + interval: daily + time: "05:30" + timezone: Europe/London + reviewers: + - "martincostello" - package-ecosystem: "github-actions" directory: "/" schedule: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac77ee62..2cc6104f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..984ddad1 --- /dev/null +++ b/Dockerfile @@ -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_linux-arm64 diff --git a/src/LondonTravel.Skill/aws-lambda-tools-defaults.json b/src/LondonTravel.Skill/aws-lambda-tools-defaults.json index 591770fa..1dfbe0a8 100644 --- a/src/LondonTravel.Skill/aws-lambda-tools-defaults.json +++ b/src/LondonTravel.Skill/aws-lambda-tools-defaults.json @@ -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",