Skip to content

Commit

Permalink
fix: yarn config in container
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Jan 20, 2024
1 parent bde51d2 commit 916cf96
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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"]
RUN yarn

CMD ["node", "."]
19 changes: 12 additions & 7 deletions Dockerfile.nvidia
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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"

RUN \
/bin/echo ">> installing dependencies" &&\
apt-get update &&\
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &&\
apt-get install -y \
curl \
wget \
Expand All @@ -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 \
Expand Down Expand Up @@ -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"]
CMD ["node", "."]
8 changes: 6 additions & 2 deletions apps/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`
);
}
)
Expand Down
15 changes: 15 additions & 0 deletions scripts/strip_package_json.js
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 916cf96

Please sign in to comment.