From 68151b43646c2ba7a0cb70b55919bdc66a2c92ba Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Fri, 19 Jan 2024 21:55:40 +0100 Subject: [PATCH 1/9] feat: add official gpu image --- .github/workflows/deploy.yaml | 36 +++++++++++ Dockerfile.gpu | 79 ++++++++++++++++++++++++ apps/docs/docs/install/docker-compose.md | 26 ++++++++ apps/docs/docs/install/docker.md | 15 +++++ 4 files changed, 156 insertions(+) create mode 100644 Dockerfile.gpu diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index cc631e61a..df796888d 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -50,6 +50,7 @@ jobs: sudo rm -f /swapfile sudo apt clean df -h + # DEPLOY normal image - uses: docker/metadata-action@v4 id: meta with: @@ -81,6 +82,41 @@ jobs: tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max + # DEPLOY GPU supported image + - uses: docker/metadata-action@v4 + id: meta_gpu + with: + flavor: | + latest=false + images: | + ghcr.io/mauricenino/dashdot + mauricenino/dashdot + labels: | + org.opencontainers.image.title="dash." + org.opencontainers.image.description="dash. - a modern server dashboard" + org.opencontainers.image.authors="MauriceNino " + org.opencontainers.image.url=https://github.com/MauriceNino/dashdot + org.opencontainers.image.source=https://github.com/MauriceNino/dashdot + org.opencontainers.image.licenses=MIT + tags: | + type=semver,pattern={{version}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=gpu- + type=semver,pattern={{major}}.{{minor}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=gpu- + type=semver,pattern={{major}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=gpu- + type=ref,event=branch,enable=${{ github.ref_name != 'main' }},prefix=gpu- + type=raw,value=gpu,enable=${{ github.ref_name == 'main' }} + - uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64 + target: prod + push: true + build-args: | + VERSION=${{ github.ref_name == 'main' && env.package_version || format('0.0.0-{0}', github.ref_name) }} + BUILDHASH=${{ github.sha }} + labels: ${{ steps.meta_gpu.outputs.labels }} + tags: ${{ steps.meta_gpu.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max - if: ${{ github.ref_name == 'main' }} env: GIT_USER: github-actions diff --git a/Dockerfile.gpu b/Dockerfile.gpu new file mode 100644 index 000000000..1aab8b193 --- /dev/null +++ b/Dockerfile.gpu @@ -0,0 +1,79 @@ +# BASE # +FROM nvidia/cuda:12.2.0-base-ubuntu20.04 AS base + +WORKDIR /app +ARG TARGETPLATFORM +ENV DASHDOT_RUNNING_IN_DOCKER=true +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" + +RUN \ + /bin/echo ">> installing dependencies" &&\ + apt-get update &&\ + apt-get install -y \ + curl \ + wget \ + mdadm \ + dmidecode \ + util-linux \ + pciutils \ + lm-sensors \ + speedtest-cli &&\ + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ + apt-get install -y nodejs &&\ + npm i -g yarn &&\ + wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-x86_64.tgz \ + | tar xmoz -C /usr/bin speedtest; + +RUN \ + /bin/echo -e ">> clean-up" &&\ + apt-get clean && \ + rm -rf /tmp/* /var/tmp/* + +# DEV # +FROM base AS dev + +EXPOSE 3001 +EXPOSE 3000 + +RUN \ + /bin/echo -e ">> installing dependencies (dev)" &&\ + apt-get install -y \ + git &&\ + git config --global --add safe.directory /app + +# BUILD # +FROM base as build + +ARG BUILDHASH +ARG VERSION + +RUN \ + /bin/echo -e ">> installing dependencies (build)" &&\ + apt-get install -y \ + git \ + make \ + clang \ + build-essential &&\ + git config --global --add safe.directory /app &&\ + /bin/echo -e "{\"version\":\"$VERSION\",\"buildhash\":\"$BUILDHASH\"}" > /app/version.json + +COPY . ./ + +RUN \ + yarn --immutable --immutable-cache &&\ + yarn build:prod + +# PROD # +FROM base as prod + +EXPOSE 3001 + +COPY --from=build /app/package.json . +COPY --from=build /app/version.json . +COPY --from=build /app/.yarn/releases/ .yarn/releases/ +COPY --from=build /app/dist/apps/server dist/apps/server +COPY --from=build /app/dist/apps/cli dist/apps/cli +COPY --from=build /app/dist/apps/view dist/apps/view + +CMD ["yarn", "start"] \ No newline at end of file diff --git a/apps/docs/docs/install/docker-compose.md b/apps/docs/docs/install/docker-compose.md index c93f49d81..d24dbdd9f 100644 --- a/apps/docs/docs/install/docker-compose.md +++ b/apps/docs/docs/install/docker-compose.md @@ -35,3 +35,29 @@ services: DASHDOT_ENABLE_CPU_TEMPS: 'true' # ... ``` + +## GPU Support + +GPU support is available with another image tag and a slightly different config. + +> **Note:** GPU support is not available on ARM devices. + +```yml +version: '3.5' + +services: + dash: + image: mauricenino/dashdot:gpu + restart: unless-stopped + privileged: true + deploy: + resources: + reservations: + devices: + - capabilities: + - gpu + ports: + - '80:3001' + volumes: + - /:/mnt/host:ro +``` diff --git a/apps/docs/docs/install/docker.md b/apps/docs/docs/install/docker.md index 174c837d0..b45af4c15 100644 --- a/apps/docs/docs/install/docker.md +++ b/apps/docs/docs/install/docker.md @@ -28,3 +28,18 @@ docker container run -it \ --env DASHDOT_ENABLE_CPU_TEMPS="true" \ # ... ``` + +## GPU Support + +GPU support is available with another image tag and a slightly different command. + +> **Note:** GPU support is not available on ARM devices. + +```bash +docker container run -it \ + -p 80:3001 \ + --privileged \ + --gpus all \ + -v /:/mnt/host:ro \ + mauricenino/dashdot:gpu +``` From eadeca9d8abf877bad9707a2aeb5a9b47a3e4431 Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Fri, 19 Jan 2024 22:28:19 +0100 Subject: [PATCH 2/9] docs: add environment variable to enable gpu widget --- apps/docs/docs/install/docker-compose.md | 2 ++ apps/docs/docs/install/docker.md | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/docs/docs/install/docker-compose.md b/apps/docs/docs/install/docker-compose.md index d24dbdd9f..5e1c0e9ab 100644 --- a/apps/docs/docs/install/docker-compose.md +++ b/apps/docs/docs/install/docker-compose.md @@ -60,4 +60,6 @@ services: - '80:3001' volumes: - /:/mnt/host:ro + environment: + DASHDOT_WIDGET_LIST: 'os,cpu,storage,ram,network,gpu' ``` diff --git a/apps/docs/docs/install/docker.md b/apps/docs/docs/install/docker.md index b45af4c15..176875710 100644 --- a/apps/docs/docs/install/docker.md +++ b/apps/docs/docs/install/docker.md @@ -12,8 +12,8 @@ tags: ```bash docker container run -it \ -p 80:3001 \ - --privileged \ -v /:/mnt/host:ro \ + --privileged \ mauricenino/dashdot ``` @@ -38,8 +38,9 @@ GPU support is available with another image tag and a slightly different command ```bash docker container run -it \ -p 80:3001 \ + -v /:/mnt/host:ro \ --privileged \ --gpus all \ - -v /:/mnt/host:ro \ + --env DASHDOT_WIDGET_LIST="os,cpu,storage,ram,network,gpu" mauricenino/dashdot:gpu ``` From f3f438a8d7d830501c584af6eedf51060ee5792a Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Fri, 19 Jan 2024 22:32:58 +0100 Subject: [PATCH 3/9] chore: change tag prefix to nvidia --- .github/workflows/deploy.yaml | 16 ++++++++-------- .../docs/docs/config/widget-specific/graphics.md | 16 +++------------- apps/docs/docs/install/docker-compose.md | 2 +- apps/docs/docs/install/docker.md | 2 +- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index df796888d..38f3d58d2 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -84,7 +84,7 @@ jobs: cache-to: type=gha,mode=max # DEPLOY GPU supported image - uses: docker/metadata-action@v4 - id: meta_gpu + id: meta_nvidia with: flavor: | latest=false @@ -99,11 +99,11 @@ jobs: org.opencontainers.image.source=https://github.com/MauriceNino/dashdot org.opencontainers.image.licenses=MIT tags: | - type=semver,pattern={{version}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=gpu- - type=semver,pattern={{major}}.{{minor}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=gpu- - type=semver,pattern={{major}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=gpu- - type=ref,event=branch,enable=${{ github.ref_name != 'main' }},prefix=gpu- - type=raw,value=gpu,enable=${{ github.ref_name == 'main' }} + type=semver,pattern={{version}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=nvidia- + type=semver,pattern={{major}}.{{minor}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=nvidia- + type=semver,pattern={{major}},value=${{ format('v{0}', env.package_version) }},enable=${{ github.ref_name == 'main' }},prefix=nvidia- + type=ref,event=branch,enable=${{ github.ref_name != 'main' }},prefix=nvidia- + type=raw,value=nvidia,enable=${{ github.ref_name == 'main' }} - uses: docker/build-push-action@v4 with: context: . @@ -113,8 +113,8 @@ jobs: build-args: | VERSION=${{ github.ref_name == 'main' && env.package_version || format('0.0.0-{0}', github.ref_name) }} BUILDHASH=${{ github.sha }} - labels: ${{ steps.meta_gpu.outputs.labels }} - tags: ${{ steps.meta_gpu.outputs.tags }} + labels: ${{ steps.meta_nvidia.outputs.labels }} + tags: ${{ steps.meta_nvidia.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max - if: ${{ github.ref_name == 'main' }} diff --git a/apps/docs/docs/config/widget-specific/graphics.md b/apps/docs/docs/config/widget-specific/graphics.md index b52a56f00..7f960c3e2 100644 --- a/apps/docs/docs/config/widget-specific/graphics.md +++ b/apps/docs/docs/config/widget-specific/graphics.md @@ -12,19 +12,9 @@ title: Graphics -To use the GPU widget, make sure to include it in the `DASHDOT_WIDGET_LIST`. One -limitation with the GPU widget is that it will **only run out of the box with from -source installations**. Docker images do not include the necessary tools (mainly, -because I don't want to bloat the image for everyone). If you absolutely need the -GPU widget running inside a docker container, you will need to create your own image. - -These links might help you with that: - -- -- -- -- -- +To use the GPU widget, make sure to include it in the `DASHDOT_WIDGET_LIST`. +Also, if you are running the docker image, make sure to use the `nvidia` tag +(see [Installation with Docker](/docs/install/docker#gpu-support)). ## `DASHDOT_GPU_WIDGET_GROW` diff --git a/apps/docs/docs/install/docker-compose.md b/apps/docs/docs/install/docker-compose.md index 5e1c0e9ab..9a584e6a7 100644 --- a/apps/docs/docs/install/docker-compose.md +++ b/apps/docs/docs/install/docker-compose.md @@ -47,7 +47,7 @@ version: '3.5' services: dash: - image: mauricenino/dashdot:gpu + image: mauricenino/dashdot:nvidia restart: unless-stopped privileged: true deploy: diff --git a/apps/docs/docs/install/docker.md b/apps/docs/docs/install/docker.md index 176875710..6e262daa0 100644 --- a/apps/docs/docs/install/docker.md +++ b/apps/docs/docs/install/docker.md @@ -42,5 +42,5 @@ docker container run -it \ --privileged \ --gpus all \ --env DASHDOT_WIDGET_LIST="os,cpu,storage,ram,network,gpu" - mauricenino/dashdot:gpu + mauricenino/dashdot:nvidia ``` From 051c3863b52228ac5ba9915bcf848ca332e838ff Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Sat, 20 Jan 2024 10:51:07 +0100 Subject: [PATCH 4/9] fix: select correct dockerfile in nvidia build --- .github/workflows/deploy.yaml | 3 ++- Dockerfile.gpu => Dockerfile.nvidia | 21 ++++++++++++++++++--- apps/docs/docs/install/docker-compose.md | 2 -- apps/docs/docs/install/docker.md | 2 -- 4 files changed, 20 insertions(+), 8 deletions(-) rename Dockerfile.gpu => Dockerfile.nvidia (64%) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 38f3d58d2..1907f0ca1 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -107,7 +107,8 @@ jobs: - uses: docker/build-push-action@v4 with: context: . - platforms: linux/amd64 + file: Dockerfile.nvidia + platforms: linux/amd64,linux/arm64/v8 target: prod push: true build-args: | diff --git a/Dockerfile.gpu b/Dockerfile.nvidia similarity index 64% rename from Dockerfile.gpu rename to Dockerfile.nvidia index 1aab8b193..1d8ed4587 100644 --- a/Dockerfile.gpu +++ b/Dockerfile.nvidia @@ -23,9 +23,24 @@ RUN \ apt-get install -y nodejs &&\ npm i -g yarn &&\ wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-x86_64.tgz \ - | tar xmoz -C /usr/bin speedtest; - -RUN \ + | tar xmoz -C /usr/bin speedtest; &&\ + if [ "$TARGETPLATFORM" = "linux/amd64" ] || [ "$(uname -m)" = "x86_64" ]; \ + then \ + /bin/echo ">> installing dependencies (amd64)" &&\ + wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-x86_64.tgz \ + | tar xmoz -C /usr/bin speedtest; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ] || [ "$(uname -m)" = "aarch64" ]; \ + then \ + /bin/echo ">> installing dependencies (arm64)" &&\ + wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-aarch64.tgz \ + | tar xmoz -C /usr/bin speedtest \ + elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; \ + then \ + /bin/echo ">> installing dependencies (arm/v7)" &&\ + wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-armhf.tgz \ + | tar xmoz -C /usr/bin speedtest \ + else /bin/echo "Unsupported platform"; exit 1; \ + fi &&\ /bin/echo -e ">> clean-up" &&\ apt-get clean && \ rm -rf /tmp/* /var/tmp/* diff --git a/apps/docs/docs/install/docker-compose.md b/apps/docs/docs/install/docker-compose.md index 9a584e6a7..72124b333 100644 --- a/apps/docs/docs/install/docker-compose.md +++ b/apps/docs/docs/install/docker-compose.md @@ -40,8 +40,6 @@ services: GPU support is available with another image tag and a slightly different config. -> **Note:** GPU support is not available on ARM devices. - ```yml version: '3.5' diff --git a/apps/docs/docs/install/docker.md b/apps/docs/docs/install/docker.md index 6e262daa0..9dfce656e 100644 --- a/apps/docs/docs/install/docker.md +++ b/apps/docs/docs/install/docker.md @@ -33,8 +33,6 @@ docker container run -it \ GPU support is available with another image tag and a slightly different command. -> **Note:** GPU support is not available on ARM devices. - ```bash docker container run -it \ -p 80:3001 \ From 80fa4723171b008f1c698f737406d38d135d0e11 Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Sat, 20 Jan 2024 11:06:10 +0100 Subject: [PATCH 5/9] fix: dockerfile syntax error --- Dockerfile.nvidia | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile.nvidia b/Dockerfile.nvidia index 1d8ed4587..da5de9ebc 100644 --- a/Dockerfile.nvidia +++ b/Dockerfile.nvidia @@ -22,8 +22,6 @@ RUN \ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ apt-get install -y nodejs &&\ npm i -g yarn &&\ - wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-x86_64.tgz \ - | tar xmoz -C /usr/bin speedtest; &&\ if [ "$TARGETPLATFORM" = "linux/amd64" ] || [ "$(uname -m)" = "x86_64" ]; \ then \ /bin/echo ">> installing dependencies (amd64)" &&\ @@ -33,12 +31,12 @@ RUN \ then \ /bin/echo ">> installing dependencies (arm64)" &&\ wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-aarch64.tgz \ - | tar xmoz -C /usr/bin speedtest \ + | tar xmoz -C /usr/bin speedtest; \ elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; \ then \ /bin/echo ">> installing dependencies (arm/v7)" &&\ wget -qO- https://install.speedtest.net/app/cli/ookla-speedtest-1.1.1-linux-armhf.tgz \ - | tar xmoz -C /usr/bin speedtest \ + | tar xmoz -C /usr/bin speedtest; \ else /bin/echo "Unsupported platform"; exit 1; \ fi &&\ /bin/echo -e ">> clean-up" &&\ From 0633c48414b31cd6ccb9215a6308a23143d86cbb Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Sat, 20 Jan 2024 11:39:58 +0100 Subject: [PATCH 6/9] fix: enable corepack --- Dockerfile.nvidia | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile.nvidia b/Dockerfile.nvidia index da5de9ebc..66b9e03f2 100644 --- a/Dockerfile.nvidia +++ b/Dockerfile.nvidia @@ -10,6 +10,7 @@ ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" RUN \ /bin/echo ">> installing dependencies" &&\ apt-get update &&\ + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ apt-get install -y \ curl \ wget \ @@ -18,10 +19,10 @@ RUN \ util-linux \ pciutils \ lm-sensors \ - speedtest-cli &&\ - curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ - apt-get install -y nodejs &&\ + speedtest-cli \ + nodejs &&\ npm i -g yarn &&\ + corepack enable &&\ if [ "$TARGETPLATFORM" = "linux/amd64" ] || [ "$(uname -m)" = "x86_64" ]; \ then \ /bin/echo ">> installing dependencies (amd64)" &&\ From bde51d27afea6560c6c31e994d2f9ab3f6f90346 Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Sat, 20 Jan 2024 11:41:40 +0100 Subject: [PATCH 7/9] fix: remove yarn --- Dockerfile.nvidia | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile.nvidia b/Dockerfile.nvidia index 66b9e03f2..babf63f12 100644 --- a/Dockerfile.nvidia +++ b/Dockerfile.nvidia @@ -21,7 +21,6 @@ RUN \ lm-sensors \ speedtest-cli \ nodejs &&\ - npm i -g yarn &&\ corepack enable &&\ if [ "$TARGETPLATFORM" = "linux/amd64" ] || [ "$(uname -m)" = "x86_64" ]; \ then \ From 916cf9684939b159c0a98f470d69abcfd637e564 Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Sat, 20 Jan 2024 13:26:57 +0100 Subject: [PATCH 8/9] fix: yarn config in container --- Dockerfile | 13 +++++++++---- Dockerfile.nvidia | 19 ++++++++++++------- apps/cli/src/main.ts | 8 ++++++-- scripts/strip_package_json.js | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 scripts/strip_package_json.js diff --git a/Dockerfile b/Dockerfile index 62e013557..02f688fbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM node:20-alpine AS base WORKDIR /app ARG TARGETPLATFORM +ENV DASHDOT_IMAGE=base ENV DASHDOT_RUNNING_IN_DOCKER=true RUN \ @@ -69,18 +70,22 @@ COPY . ./ RUN \ yarn --immutable --immutable-cache &&\ - yarn build:prod + yarn build:prod &&\ + node scripts/strip_package_json.js # PROD # FROM base as prod EXPOSE 3001 -COPY --from=build /app/package.json . COPY --from=build /app/version.json . -COPY --from=build /app/.yarn/releases/ .yarn/releases/ +COPY --from=build /app/.yarn/releases .yarn/releases +COPY --from=build /app/.yarnrc.yml .yarnrc.yml COPY --from=build /app/dist/apps/server dist/apps/server COPY --from=build /app/dist/apps/cli dist/apps/cli COPY --from=build /app/dist/apps/view dist/apps/view +COPY --from=build /app/dist/package.json package.json -CMD ["yarn", "start"] \ No newline at end of file +RUN yarn + +CMD ["node", "."] \ No newline at end of file diff --git a/Dockerfile.nvidia b/Dockerfile.nvidia index babf63f12..c972380c5 100644 --- a/Dockerfile.nvidia +++ b/Dockerfile.nvidia @@ -3,6 +3,7 @@ FROM nvidia/cuda:12.2.0-base-ubuntu20.04 AS base WORKDIR /app ARG TARGETPLATFORM +ENV DASHDOT_IMAGE=nvidia ENV DASHDOT_RUNNING_IN_DOCKER=true ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" @@ -10,7 +11,6 @@ ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" RUN \ /bin/echo ">> installing dependencies" &&\ apt-get update &&\ - curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ apt-get install -y \ curl \ wget \ @@ -19,8 +19,9 @@ RUN \ util-linux \ pciutils \ lm-sensors \ - speedtest-cli \ - nodejs &&\ + speedtest-cli &&\ + curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\ + apt-get install -y nodejs &&\ corepack enable &&\ if [ "$TARGETPLATFORM" = "linux/amd64" ] || [ "$(uname -m)" = "x86_64" ]; \ then \ @@ -75,18 +76,22 @@ COPY . ./ RUN \ yarn --immutable --immutable-cache &&\ - yarn build:prod + yarn build:prod &&\ + node scripts/strip_package_json.js # PROD # FROM base as prod EXPOSE 3001 -COPY --from=build /app/package.json . COPY --from=build /app/version.json . -COPY --from=build /app/.yarn/releases/ .yarn/releases/ +COPY --from=build /app/.yarn/releases .yarn/releases +COPY --from=build /app/.yarnrc.yml .yarnrc.yml COPY --from=build /app/dist/apps/server dist/apps/server COPY --from=build /app/dist/apps/cli dist/apps/cli COPY --from=build /app/dist/apps/view dist/apps/view +COPY --from=build /app/dist/package.json package.json + +RUN yarn -CMD ["yarn", "start"] \ No newline at end of file +CMD ["node", "."] \ No newline at end of file diff --git a/apps/cli/src/main.ts b/apps/cli/src/main.ts index af3bd475d..f3575a4e3 100644 --- a/apps/cli/src/main.ts +++ b/apps/cli/src/main.ts @@ -35,10 +35,12 @@ yargs(hideBin(process.argv)) const nodeVersion = await execpnoerr('node --version'); const buildInfoJson = await execpnoerr('cat version.json'); const gitHash = await execpnoerr('git log -1 --format="%H"'); + const platform = await execpnoerr('uname -a'); const runningInDocker = await execpnoerr( 'echo $DASHDOT_RUNNING_IN_DOCKER' ); + const image = await execpnoerr('echo $DASHDOT_IMAGE'); const buildInfo = JSON.parse(buildInfoJson ?? '{}'); const version = buildInfo.version ?? 'unknown'; const buildhash = buildInfo.buildhash ?? gitHash; @@ -53,9 +55,11 @@ yargs(hideBin(process.argv)) Cwd: ${process.cwd()} Hash: ${buildhash} + Platform: ${platform} + Docker image: ${image} In Docker: ${isDocker} - In Podman: ${isPodman} - In Docker (env): ${runningInDocker}` + In Docker (env): ${runningInDocker} + In Podman: ${isPodman}` ); } ) diff --git a/scripts/strip_package_json.js b/scripts/strip_package_json.js new file mode 100644 index 000000000..492e1430a --- /dev/null +++ b/scripts/strip_package_json.js @@ -0,0 +1,15 @@ +const packageJson = require('../package.json') +const fs = require('fs') + +const newPackageJson = { + name: packageJson.name, + version: packageJson.version, + description: packageJson.description, + packageManager: packageJson.packageManager, + main: packageJson.main, + scripts: { + cli: 'node dist/apps/cli/main.js', + } +} + +fs.writeFileSync('dist/package.json', JSON.stringify(newPackageJson, null, 2)) \ No newline at end of file From 045bab1190fb92801421edb43b617bf4316e4d85 Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Sat, 20 Jan 2024 13:51:52 +0100 Subject: [PATCH 9/9] fix: minor style changes --- .dockerignore | 1 + apps/cli/src/main.ts | 10 +++++----- apps/server/src/index.ts | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 720f7b529..dde862a68 100644 --- a/.dockerignore +++ b/.dockerignore @@ -22,4 +22,5 @@ .dockerignore Dockerfile Dockerfile.dev +Dockerfile.nvidia docker-compose.yml \ No newline at end of file diff --git a/apps/cli/src/main.ts b/apps/cli/src/main.ts index f3575a4e3..3ffdd3e4e 100644 --- a/apps/cli/src/main.ts +++ b/apps/cli/src/main.ts @@ -7,10 +7,10 @@ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; const execp = promisify(exec); -const execpnoerr = async (cmd: string): Promise => { +const execpnoerr = async (cmd: string) => { return execp(cmd) - .then(({ stdout }) => stdout) - .catch(() => undefined); + .then(({ stdout }) => stdout.trim()) + .catch(() => ''); }; const inspectObj = (obj: unknown): string => { @@ -49,8 +49,8 @@ yargs(hideBin(process.argv)) removePad` INFO ========= - Yarn: ${yarnVersion.trim()} - Node: ${nodeVersion.trim()} + Yarn: ${yarnVersion} + Node: ${nodeVersion} Dash: ${version} Cwd: ${process.cwd()} diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index d51cef4f4..d0cefc793 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -222,3 +222,8 @@ process.on('unhandledRejection', e => { tearDownHostSpecific(); process.exit(1); }); + +process.on('SIGINT', () => { + console.info('SIGINT signal received.'); + process.exit(0); +});