Przeglądaj źródła

feat: add mulitplatform Docker image support (#9594)

Spawn 1 miesiąc temu
rodzic
commit
3f194918e6
2 zmienionych plików z 11 dodań i 5 usunięć
  1. 6 1
      .github/workflows/publish-docker.yml
  2. 5 4
      Dockerfile

+ 6 - 1
.github/workflows/publish-docker.yml

@@ -17,9 +17,14 @@ jobs:
         with:
           username: ${{ secrets.DOCKER_USERNAME }}
           password: ${{ secrets.DOCKER_PASSWORD }}
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v3
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
       - name: Build and push
-        uses: docker/build-push-action@v3
+        uses: docker/build-push-action@v5
         with:
           context: .
           push: true
           tags: excalidraw/excalidraw:latest
+          platforms: linux/amd64, linux/arm64, linux/arm/v7

+ 5 - 4
Dockerfile

@@ -1,4 +1,4 @@
-FROM node:18 AS build
+FROM --platform=${BUILDPLATFORM} node:18 AS build
 
 WORKDIR /opt/node_app
 
@@ -6,13 +6,14 @@ COPY . .
 
 # do not ignore optional dependencies:
 # Error: Cannot find module @rollup/rollup-linux-x64-gnu
-RUN yarn --network-timeout 600000
+RUN --mount=type=cache,target=/root/.cache/yarn \
+    npm_config_target_arch=${TARGETARCH} yarn --network-timeout 600000
 
 ARG NODE_ENV=production
 
-RUN yarn build:app:docker
+RUN npm_config_target_arch=${TARGETARCH} yarn build:app:docker
 
-FROM nginx:1.27-alpine
+FROM --platform=${TARGETPLATFORM} nginx:1.27-alpine
 
 COPY --from=build /opt/node_app/excalidraw-app/build /usr/share/nginx/html