From d5a2ac01cb21f11196f3bf27388a8ef95821e432 Mon Sep 17 00:00:00 2001 From: daanh432 <8281824+daanh432@users.noreply.github.com> Date: Wed, 6 Sep 2023 19:21:24 +0200 Subject: [PATCH] Multi arch builds --- .dockerignore | 9 ++++++ .github/workflows/release.yml | 58 +++++++++++++++++++++++++++++++++-- Dockerfile | 17 +++++++--- Dockerfile.alpine | 37 ++++++++++++++++++++++ scripts/docker.sh | 25 --------------- 5 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile.alpine delete mode 100755 scripts/docker.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..6a5d3a092 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +**/.git/ +**/.github/ +**/node_modules/ + +**/Dockerfile +**/Dockerfile.* + +**/.env.*.local +**/.env.local \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 590c8b649..2ad75e41e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -112,8 +112,60 @@ jobs: docker: runs-on: ubuntu-latest steps: + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - name: Log in to Docker Hub + uses: docker/login-action@v2 with: - node-version: '18.x' - - run: DOCKER_PASSWORD=${{ secrets.DOCKERHUB_TOKEN }} DOCKER_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} bash scripts/docker.sh + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: deepstreamio/deepstream.io + flavor: | + latest=true + tags: | + type=semver,pattern={{version}} + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + docker-alpine: + runs-on: ubuntu-latest + steps: + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 + - uses: actions/checkout@v3 + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: deepstreamio/deepstream.io + flavor: | + latest=true + suffix=-alpine,onlatest=true + tags: | + type=semver,pattern={{version}} + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile.alpine + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index facc66a6d..e169ad32e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ -FROM node:10 - +FROM node:18 as builder +WORKDIR /app # RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" # RUN unzip awscliv2.zip # RUN ./aws/install COPY package*.json ./ +RUN npm ci RUN npm install --production \ @deepstream/cache-redis \ # @deepstream/cache-memcached \ @@ -18,11 +19,17 @@ RUN npm install --production \ @deepstream/logger-winston \ @deepstream/plugin-aws -COPY . ./ +COPY . . + +RUN npm run tsc + +FROM node:18 +WORKDIR /usr/local/deepstream +COPY --from=builder /app/node_modules/ ./node_modules +COPY --from=builder /app/dist/ . EXPOSE 6020 EXPOSE 8080 EXPOSE 9229 -CMD ["node", "./bin/deepstream.js", "start", "--inspect=0.0.0.0:9229"] - +CMD ["node", "./bin/deepstream.js", "start", "--inspect=0.0.0.0:9229"] \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 000000000..fdf66e170 --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,37 @@ +FROM node:18-alpine as builder +WORKDIR /app +# RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" +# RUN unzip awscliv2.zip +# RUN ./aws/install + +COPY package*.json ./ + +RUN npm ci +RUN npm install --production \ + @deepstream/cache-redis \ + # @deepstream/cache-memcached \ + # @deepstream/cache-hazelcast \ + @deepstream/clusternode-redis \ + @deepstream/storage-mongodb \ + @deepstream/storage-rethinkdb \ + @deepstream/storage-elasticsearch \ + @deepstream/storage-postgres \ + @deepstream/logger-winston \ + @deepstream/plugin-aws + +RUN npm uninstall --save uWebSockets.js + +COPY . . + +RUN npm run tsc + +FROM node:18-alpine +WORKDIR /usr/local/deepstream +COPY --from=builder /app/node_modules/ ./node_modules +COPY --from=builder /app/dist/ . + +EXPOSE 6020 +EXPOSE 8080 +EXPOSE 9229 + +CMD ["node", "./bin/deepstream.js", "start", "--inspect=0.0.0.0:9229"] \ No newline at end of file diff --git a/scripts/docker.sh b/scripts/docker.sh deleted file mode 100755 index d709373a9..000000000 --- a/scripts/docker.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -e - -PACKAGE_VERSION=$( node scripts/details.js VERSION ) - -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - -npm i -npm run tsc -cd dist - -docker build . -t deepstreamio/deepstream.io:${PACKAGE_VERSION} -t deepstreamio/deepstream.io:latest -docker push deepstreamio/deepstream.io:${PACKAGE_VERSION} -docker push deepstreamio/deepstream.io:latest - -npm uninstall --save uWebSockets.js -echo 'Replacing node with node-alpine' -sed -i 's@node:18@node:18-alpine@' Dockerfile -echo 'Building node alpine' -docker build . -t deepstreamio/deepstream.io:${PACKAGE_VERSION}-alpine -t deepstreamio/deepstream.io:latest-alpine -echo 'Pushing node alpine' -docker push deepstreamio/deepstream.io:${PACKAGE_VERSION}-alpine -docker push deepstreamio/deepstream.io:latest-alpine - -cd ../