From 7ecfa268baa1661139184a35c1ff4870ba36b3c1 Mon Sep 17 00:00:00 2001 From: jtakalai Date: Mon, 27 May 2024 13:42:42 +0300 Subject: [PATCH] feat: add multi-platform docker image support (#19) This commit adds support for multi-platform docker images. It includes changes to the CI workflow file to setup QEMU and Docker Buildx, login to Docker Hub, and build and push the docker image for both amd64 and arm64 platforms. Future improvements Use node:18-bullseye-slim instead of node:18-bullseye, the image is half the size (compressed). Potential problem: "npm ci" (on arm64 at least) requires node-gyp requires python, so it must be installed first ("half the size" is only without python...). --- .github/workflows/ci.yml | 3 ++- Dockerfile | 2 +- package.json | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c718d2c..a7d7568 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,5 +42,6 @@ jobs: - name: Build and push uses: docker/build-push-action@v3 with: - push: true + push: ${{ github.ref == 'refs/heads/main' }} tags: streamr/stream-metrics-index:latest + platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index 59c6c70..1216d1f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN npm run build RUN chmod +x dist/bin/*.js RUN rm -rf node_modules -FROM node:18-bullseye-slim +FROM node:18-bullseye USER node WORKDIR /usr/src/app COPY --chown=node:node --from=build /usr/src/app/ . diff --git a/package.json b/package.json index a461af6..b95da33 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "private": true, "scripts": { "build": "tsc -b tsconfig.build.json", + "docker:build": "docker build --tag streamr/stream-metrics-index:latest .", + "docker:push": "docker buildx build --platform linux/amd64,linux/arm64 --tag streamr/stream-metrics-index:latest --push .", "test": "jest --runInBand", "eslint": "eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '*/**/*.{js,ts}'" },