Skip to content

Commit

Permalink
improve dockerfile, refactor turbo tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed Apr 11, 2024
1 parent cdb7094 commit 6ea9b83
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 38 deletions.
5 changes: 1 addition & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ node_modules

*.tsbuildinfo

# Ignore dist directory in the current directory
dist

# Ignore .env files
.env
.env.test
Expand All @@ -49,4 +46,4 @@ dist
# Ignore .vscode directory in the current directory
/.vscode

/.git
/.git
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"build:ts": "tsc -b",
"build:css": "postcss ./src/styles/full.css -o ./dist/full.css && postcss ./src/styles/common.css -o ./dist/common.css",
"build:lezer": "cd ./src/components/CodeEditor/languageSupport; mkdir -p generated; lezer-generator ./squiggle.grammar --output generated/squiggle.ts",
"build": "pnpm run build:lezer && pnpm run build:ts && pnpm run build:css",
"build:storybook": "storybook build",
"build": "pnpm run build:lezer && pnpm run build:ts && pnpm run build:css && pnpm run build:storybook",
"lint": "pnpm lint:prettier && pnpm eslint",
"lint:prettier": "prettier --check .",
"eslint": "eslint --ignore-path .gitignore .",
Expand Down
1 change: 0 additions & 1 deletion packages/components/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"build": {
"outputs": [
"dist/**",
"storybook-static/**",
"src/components/CodeEditor/languageSupport/generated/**"
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/components/vercel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"buildCommand": "PLATFORM=vercel npx turbo build",
"buildCommand": "PLATFORM=vercel npx turbo build:storybook",
"outputDirectory": "storybook-static",
"ignoreCommand": "npx turbo-ignore || ../../skip-dependabot.sh"
}
62 changes: 38 additions & 24 deletions packages/hub/dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
# Use the official Node.js 20 image as the base
FROM node:20
WORKDIR /app
# Should be invoked from monorepo's root.

# Copy the entire monorepo to the working directory
# Use the official Node.js 20 image as the base
ARG DOCKER_NODE_VERSION=20-bookworm-slim

FROM node:$DOCKER_NODE_VERSION AS node-with-openssl

# Install OpenSSL - necessary for Prisma client
# Mount caches via https://stackoverflow.com/a/72851168
RUN --mount=type=cache,id=apt-lists,target=/var/lib/apt/lists,sharing=locked \
--mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get install -y \
openssl
# If we ever need canvas for components, uncomment these:
# build-essential \
# libcairo2-dev \
# libpango1.0-dev \
# libjpeg-dev \
# libgif-dev \
# librsvg2-dev

# Build
FROM node-with-openssl AS build-stage
WORKDIR /build

RUN apt-get update && apt-get install -y apt
# Install necessary dependencies for canvas
RUN apt-get update && \
apt-get install -y \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev
# Install pnpm and turbo globally
RUN npm install -g pnpm

# Copy the entire monorepo to the working directory
COPY . .
# Install pnpm and turbo globally
RUN npm install -g pnpm turbo

# Install monorepo dependencies
RUN pnpm install
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store/v3 pnpm install --frozen-lockfile

# run turbo build
WORKDIR /build/packages/hub
ENV NODE_ENV=production

# WORKDIR /app/packages/hub
# TODO - turbo cache, either as volume or remote
RUN npx turbo run bundle --concurrency=1

# RUN pnpm install
FROM node-with-openssl AS run-stage
WORKDIR /app

# Expose the port on which the application will run (adjust if necessary)
# EXPOSE 3001
COPY --from=build-stage /build/packages/hub/dist /app/dist
COPY --from=build-stage /build/node_modules/.pnpm/@prisma+client*/node_modules/.prisma/client/*.so.node /app/dist

# Set the command to run the application
# CMD ["pnpm", "run", "build-last-revision"]
CMD ["node", "dist/bundle/buildRecentModelRevision.js"]
2 changes: 2 additions & 0 deletions packages/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"gen:schema": "tsx ./src/graphql/print-schema.ts",
"gen": "pnpm gen:prisma && pnpm gen:schema && pnpm gen:relay",
"build:ts": "pnpm gen && tsc",
"bundle": "esbuild ./src/scripts/buildRecentModelRevision.ts --format=cjs --platform=node --sourcemap --minify --bundle --outdir=./dist/bundle",
"build": "pnpm gen && __NEXT_PRIVATE_PREBUNDLED_REACT=next next build",
"lint": "prettier --check . && next lint",
"format": "prettier --write .",
Expand Down Expand Up @@ -80,6 +81,7 @@
"@types/relay-runtime": "^14.1.23",
"babel-plugin-relay": "^16.2.0",
"dotenv-cli": "^7.3.0",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"eslint-config-next": "^14.1.0",
"graphql": "^16.8.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/hub/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"pipeline": {
"build": {
"env": ["DATABASE_URL", "VERCEL_ENV"]
},
"bundle": {
"dependsOn": ["^build", "build:ts"],
"outputs": ["dist/bundle*"]
}
}
}
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build:css": "postcss ./src/styles/full.css -o ./dist/full.css",
"build:storybook": "storybook build",
"clean:ts": "rm -rf ./dist ./tsconfig.tsbuildinfo",
"build": "pnpm clean:ts && pnpm build:ts && pnpm build:css && pnpm build:storybook",
"build": "pnpm clean:ts && pnpm build:ts && pnpm build:css",
"lint": "pnpm lint:prettier && pnpm eslint",
"lint:prettier": "prettier --check .",
"eslint": "eslint --ignore-path .gitignore ./src",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/vercel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"buildCommand": "PLATFORM=vercel npx turbo build",
"buildCommand": "PLATFORM=vercel npx turbo build:storybook",
"outputDirectory": "storybook-static",
"ignoreCommand": "npx turbo-ignore || ../../skip-dependabot.sh"
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"pipeline": {
// dev target for pre-push checks
"build:ts": {
"dependsOn": ["^build:ts"],
"dependsOn": ["^build"],
"outputs": ["dist/**", "*.tsbuildinfo"]
},
"build": {
Expand All @@ -19,15 +19,15 @@
"!.next/cache/**"
]
},
"build:storybook": {
"dependsOn": ["build"],
"outputs": ["storybook-static/**"]
},
"lint": {},
"eslint": {},
"test": {
"dependsOn": ["build"]
},
"bundle": {
"dependsOn": ["build"],
"outputs": ["dist/bundle*"]
},
"coverage": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
Expand Down

0 comments on commit 6ea9b83

Please sign in to comment.