Skip to content

Commit

Permalink
Add multi-platform docker image for arm64 architecture support (#279)
Browse files Browse the repository at this point in the history
* feat: Add BUILDPLATFORM and TARGETARCH args in docker for supporting multi-platform images
* feat: github action use buildx
* feat: add QEMU step for docker github action
  • Loading branch information
JeyDim committed Feb 3, 2024
1 parent acf3b48 commit 8d5a947
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@ on:
push:
branches:
- 'master'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_LOGIN }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: impworks/bonsai:latest
build-args: |
BUILD_COMMIT=${{ github.sha }}
BUILD_COMMIT=${{ github.sha }}
38 changes: 30 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM node:14-alpine as node
FROM --platform=$BUILDPLATFORM node:14-alpine as node
ARG TARGETARCH
ARG TARGETVARIANT

WORKDIR /build/Bonsai

ADD src/Bonsai/package.json .
Expand All @@ -7,21 +10,39 @@ RUN npm ci
ADD src/Bonsai .
RUN node_modules/.bin/gulp build

FROM mcr.microsoft.com/dotnet/sdk:8.0 as net-builder
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine as net-builder
ARG TARGETARCH
ARG TARGETVARIANT

WORKDIR /build
ADD src/Bonsai.sln .
ADD src/Bonsai/Bonsai.csproj Bonsai/
ADD src/Bonsai.Tests.Search/Bonsai.Tests.Search.csproj Bonsai.Tests.Search/

RUN dotnet restore
RUN --mount=type=cache,id=nuget-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.nuget/packages \
dotnet restore -a ${TARGETARCH/amd64/x64}
COPY --from=node /build .

RUN dotnet publish --output ../out/ --configuration Release --runtime linux-musl-x64 --self-contained true Bonsai/Bonsai.csproj
RUN --mount=type=cache,id=nuget-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.nuget/packages \
dotnet publish Bonsai/Bonsai.csproj \
--output ../out/ \
--configuration Release \
-a ${TARGETARCH/amd64/x64} \
--self-contained true

FROM alpine:latest
FROM --platform=$TARGETPLATFORM alpine:latest
ARG TARGETARCH
ARG TARGETVARIANT
ARG BUILD_COMMIT

RUN apk add --no-cache nodejs ffmpeg libintl icu icu-data-full && \
apk add --no-cache libgdiplus --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/
RUN --mount=type=cache,id=apk-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apk \
apk --update add \
nodejs \
ffmpeg \
libintl \
icu \
icu-data-full \
&& apk add libgdiplus --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing/

WORKDIR /app
COPY --from=net-builder /out .
Expand All @@ -32,8 +53,9 @@ RUN ln -s /usr/bin/ffmpeg /app/External/ffmpeg/ffmpeg && \
ln -s /usr/bin/ffprobe /app/External/ffmpeg/ffprobe && \
chmod +x /app/Bonsai

ARG BUILD_COMMIT
ENV ASPNETCORE_ENVIRONMENT=Production
ENV BuildCommit=$BUILD_COMMIT

EXPOSE 80

ENTRYPOINT ["/app/Bonsai"]

0 comments on commit 8d5a947

Please sign in to comment.