From b1a3124fccf39b253b8dffbe91180846be3489cb Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Thu, 4 Apr 2024 22:58:00 +0200 Subject: [PATCH 1/8] Add requirements for multi-platform docker build to the CI --- .github/workflows/docker-image.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index f1dc1b40f..0c076bddf 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -40,6 +40,12 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) # to extract tags and labels that will be applied to the specified image. From 74bff84226a5ee26543bd83f00d385cc53417b55 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Thu, 4 Apr 2024 21:35:22 +0000 Subject: [PATCH 2/8] Remove unpopular archs For now, we need to stick to the most used archs for resources and build time reasons. --- .github/workflows/docker-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 0c076bddf..14f2850f5 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -79,7 +79,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v5 with: - platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6,linux/ppc64le,linux/s390x + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 context: . push: true tags: ${{ steps.meta.outputs.tags }} From 95b6dbd1404ae26dd13b77ff5b9acc312b0e7b1b Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Thu, 4 Apr 2024 21:47:29 +0000 Subject: [PATCH 3/8] Add python3 to use `node-gyp` to allow native cross platform build python3 would be required by node-gyp to natively build node add-on. This is required if we build for multi-platform --- Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ccd879b1..066c24d66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,11 @@ LABEL license="AGPL-3.0,https://github.com/HeyPuter/puter/blob/master/LICENSE.tx LABEL version="1.2.46-beta-1" # Install git (required by Puter to check version) -RUN apk add --no-cache git - +# python3 would be required by node-gyp to natively build node addon +# This is required if we build for multi-platform +RUN apk add --no-cache git python3 make g++ \ + && ln -s /usr/bin/python3 /usr/bin/python + # Setup working directory RUN mkdir -p /opt/puter/app WORKDIR /opt/puter/app From accdec3af465239fdebbcef937351f18c88f3f50 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Thu, 4 Apr 2024 21:51:39 +0000 Subject: [PATCH 4/8] handle linking to python binary gracefully --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 066c24d66..5a5241cf3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ LABEL version="1.2.46-beta-1" # python3 would be required by node-gyp to natively build node addon # This is required if we build for multi-platform RUN apk add --no-cache git python3 make g++ \ - && ln -s /usr/bin/python3 /usr/bin/python + && ln -sf /usr/bin/python3 /usr/bin/python # Setup working directory RUN mkdir -p /opt/puter/app From 1a13ef6921ab02b9a4eaeb53eca925b482730b85 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 5 Apr 2024 00:55:44 +0000 Subject: [PATCH 5/8] remove linux/arm/v7,linux/arm/v6 emporarily --- .github/workflows/docker-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 14f2850f5..9887918fb 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -79,7 +79,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v5 with: - platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 + platforms: linux/amd64,linux/arm6 context: . push: true tags: ${{ steps.meta.outputs.tags }} From 06a31fd67b6966006e38527316ecdd75432a22a2 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 5 Apr 2024 00:59:05 +0000 Subject: [PATCH 6/8] Fix typo in arm64 namespace --- .github/workflows/docker-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 9887918fb..b7aad361c 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -79,7 +79,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v5 with: - platforms: linux/amd64,linux/arm6 + platforms: linux/amd64,linux/arm64 context: . push: true tags: ${{ steps.meta.outputs.tags }} From 17ae6668b43aa46a6fc6530db6e766c57f610ffe Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 5 Apr 2024 01:10:47 +0000 Subject: [PATCH 7/8] Add `linux/arm/v7` again We need to test if this is what causes the problem of the GitHub action getting stuck or `linux/arm/v6` --- .github/workflows/docker-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index b7aad361c..987499e4f 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -79,7 +79,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v5 with: - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64, linux/arm/v7 context: . push: true tags: ${{ steps.meta.outputs.tags }} From a0f46c326a6d8b35aaaa3ef8af7e28cd3976dcd2 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Mon, 8 Apr 2024 17:12:26 +0200 Subject: [PATCH 8/8] Add build stage and remove `linux/arm/v7` --- .github/workflows/docker-image.yaml | 2 +- Dockerfile | 50 ++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 987499e4f..b7aad361c 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -79,7 +79,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v5 with: - platforms: linux/amd64,linux/arm64, linux/arm/v7 + platforms: linux/amd64,linux/arm64 context: . push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 5a5241cf3..6bbb5dc93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,27 @@ +# Build stage +FROM node:21-alpine AS build + +# Install build dependencies +RUN apk add --no-cache git python3 make g++ \ + && ln -sf /usr/bin/python3 /usr/bin/python + +# Set up working directory +WORKDIR /app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install node modules +RUN npm cache clean --force \ + && npm ci + +# Copy the rest of the source files +COPY . . + +# Run the build command if necessary +RUN npm run build + +# Production stage FROM node:21-alpine # Set labels @@ -6,30 +30,24 @@ LABEL license="AGPL-3.0,https://github.com/HeyPuter/puter/blob/master/LICENSE.tx LABEL version="1.2.46-beta-1" # Install git (required by Puter to check version) -# python3 would be required by node-gyp to natively build node addon -# This is required if we build for multi-platform -RUN apk add --no-cache git python3 make g++ \ - && ln -sf /usr/bin/python3 /usr/bin/python - -# Setup working directory +RUN apk add --no-cache git + +# Set up working directory RUN mkdir -p /opt/puter/app WORKDIR /opt/puter/app -# Add source files -# NOTE: This might change (https://github.com/HeyPuter/puter/discussions/32) -COPY . . +# Copy built artifacts and necessary files from the build stage +COPY --from=build /app/dist ./dist +COPY --from=build /app/node_modules ./node_modules +COPY package*.json ./ # Set permissions RUN chown -R node:node /opt/puter/app USER node -# Install node modules -RUN npm cache clean --force \ - && npm install - EXPOSE 4100 -HEALTHCHECK --interval=30s --timeout=3s \ - CMD wget --no-verbose --tries=1 --spider http://puter.localhost:4100/test || exit 1 +HEALTHCHECK --interval=30s --timeout=3s \ + CMD wget --no-verbose --tries=1 --spider http://puter.localhost:4100/test || exit 1 -CMD [ "npm", "start" ] +CMD ["npm", "start"] \ No newline at end of file