diff --git a/.dockerignore b/.dockerignore index a23c257..6ab80c4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,5 @@ .git **/dist **/tsconfig.tsbuildinfo -data \ No newline at end of file +data +postgres-data diff --git a/.github/workflows/ci-checks.yml b/.github/workflows/ci-checks.yml index 82f5cd8..5e9b138 100644 --- a/.github/workflows/ci-checks.yml +++ b/.github/workflows/ci-checks.yml @@ -11,18 +11,26 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.3.14 + + # Jest still runs on Node until tests move to `bun test` - uses: actions/setup-node@v3 with: node-version: 20 - name: Install dependencies - run: yarn install + run: bun install --frozen-lockfile + + - name: Type check + run: bun run type-check - name: Build - run: yarn build + run: bun run build - name: Lint - run: yarn lint + run: bun run lint - name: Test - run: yarn test + run: bun run test diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9bf278c..3c784a7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -14,7 +14,7 @@ jobs: run: docker-compose -f docker-compose.testing.yml build base backend app-test cypress - name: Build Test Quests - run: docker-compose -f docker-compose.testing.yml run --rm backend yarn build:quests + run: docker-compose -f docker-compose.testing.yml run --rm backend bun run build:quests - name: Run Cypress Tests env: diff --git a/.vscode/launch.json b/.vscode/launch.json index 91e6bfc..afab9b7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,10 +4,10 @@ { "type": "node", "request": "launch", - "name": "File Graph Yarn Jest", - "runtimeExecutable": "yarn", - "args": ["test", "--runInBand"], - "cwd": "${workspaceFolder}/packages/file-graph", + "name": "File Graph Jest", + "runtimeExecutable": "bun", + "args": ["run", "test", "packages/file-graph", "--runInBand"], + "cwd": "${workspaceFolder}", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" } diff --git a/README.md b/README.md index 7643e06..3dcaa89 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,15 @@ ## TLDR - yarn install + bun install cp .env.sample .env docker compose up -d - yarn dev + bun run dev ## Requirements -- NodeJS v20+ +- Bun: v1.3+ - Docker -- Yarn: v1.22 ## Known Issues @@ -26,7 +25,7 @@ Windows user please refer to [docs/windows-setup.md](docs/windows-setup.md) for git clone https://github.com/lancatlin/linux-odyssey.git cd linux-odyssey - yarn install + bun install ## Project Structures @@ -104,7 +103,7 @@ Customized `entrypoint.sh` for each quest is not yet supported. To build all quests: - yarn build:quests + bun run build:quests The base image is built with docker-compose, so you can use `docker compose build base` to rebuild it. Once you rebuild the base image, you have to rebuild all quests. @@ -134,11 +133,11 @@ Copy `.env.sample` to `.env` and customize it for your needs. Run dev server (frontend, backend): - yarn dev + bun run dev To develop analytics dashboard: - yarn analytics + bun run analytics The default username and password is `alex` and `Alex1234`. @@ -146,12 +145,12 @@ The default username and password is `alex` and `Alex1234`. Unit tests: - yarn test:unit + bun run test Run Cypress locally, using the current development containers: docker compose up -d - yarn test:e2e + bun run test:e2e Run Cypress in container, create brand-new containers along with it: @@ -183,7 +182,7 @@ Start the service # Server side docker compose -f docker-compose.prod.yml pull - yarn build:quests + bun run build:quests docker compose -f docker-compose.prod.yml up -d ### Necessary Configuration @@ -197,4 +196,4 @@ You can copy from `.env.sample` You can generate a random key by running - yarn setup + bun run setup diff --git a/app/Dockerfile b/app/Dockerfile index 3c3e03b..8ede7a2 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,17 +1,24 @@ # Base stage -FROM node:20-alpine AS build +FROM oven/bun:1.3.14-alpine AS build WORKDIR /app -COPY package.json yarn.lock ./ +COPY package.json bun.lock ./ COPY app/package.json ./app/package.json COPY server/package.json ./server/package.json -RUN yarn install --frozen-lockfile +COPY services/analytics/package.json ./services/analytics/package.json +COPY tests/package.json ./tests/package.json +COPY packages/constants/package.json ./packages/constants/package.json +COPY packages/file-graph/package.json ./packages/file-graph/package.json +COPY packages/game/package.json ./packages/game/package.json +COPY packages/models/package.json ./packages/models/package.json +COPY packages/utils/package.json ./packages/utils/package.json +RUN bun install --frozen-lockfile --filter app COPY tsconfig.json ./tsconfig.json COPY server ./server COPY packages ./packages COPY app ./app -RUN yarn workspace app build +RUN bun run --filter app build # Production stage FROM nginx:stable-alpine AS prod diff --git a/bun.lock b/bun.lock index 4f2c266..09383dd 100644 --- a/bun.lock +++ b/bun.lock @@ -102,6 +102,7 @@ "name": "@odyssey/models", "version": "0.0.0", "dependencies": { + "@odyssey/constants": "workspace:*", "mongoose": "^8.24.1", }, }, diff --git a/docs/windows-setup.md b/docs/windows-setup.md index 5ae49ce..a58cdd5 100644 --- a/docs/windows-setup.md +++ b/docs/windows-setup.md @@ -81,22 +81,23 @@ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs ``` -### Install Yarn 1.22 +### Install Bun ```bash -sudo npm install -g yarn@1.22.22 +curl -fsSL https://bun.sh/install | bash ``` +Restart your terminal (or run `source ~/.bashrc`) so `bun` is on your `PATH`. + Verify the installations: ```bash git --version node --version -npm --version -yarn --version +bun --version ``` -The Node.js version should be `20.x` or later, and the Yarn version should be `1.22.x`. +The Node.js version should be `20.x` or later, and the Bun version should be `1.3` or later. ## 4. Clone the Project @@ -130,10 +131,10 @@ code . From the project root, run: ```bash -yarn install +bun install ``` -Warnings during installation may be harmless. The installation succeeded if Yarn finishes with a `Done` message and does not display `error Command failed`. +Warnings during installation may be harmless. The installation succeeded if Bun finishes with an `installed` message and does not display an `error:` message. If a `gyp` error appears, confirm that it belongs to an optional dependency before ignoring it. @@ -180,7 +181,7 @@ docker compose down Start the frontend and backend development servers: ```bash -yarn dev +bun run dev ``` Keep the terminal running and open the following address in your browser: @@ -194,5 +195,5 @@ To stop the development servers, press `Ctrl+C`. You can verify that the project builds successfully by running: ```bash -yarn build +bun run build ``` diff --git a/packages/game/Session.ts b/packages/game/Session.ts index 1fde8b6..eeef16e 100644 --- a/packages/game/Session.ts +++ b/packages/game/Session.ts @@ -1,4 +1,4 @@ -import { FileGraph, IFileNode } from '../file-graph' +import { FileGraph, IFileNode } from '@odyssey/file-graph' import { Quest } from './Quest' import { IQuest, diff --git a/packages/models/package.json b/packages/models/package.json index 85bf0f5..a235df9 100644 --- a/packages/models/package.json +++ b/packages/models/package.json @@ -8,6 +8,7 @@ ".": "./index.ts" }, "dependencies": { + "@odyssey/constants": "workspace:*", "mongoose": "^8.24.1" } } diff --git a/packages/models/session.ts b/packages/models/session.ts index 9872be8..9b3c993 100644 --- a/packages/models/session.ts +++ b/packages/models/session.ts @@ -1,6 +1,6 @@ import { model, Schema, Types } from 'mongoose' -import type { QuestLocale } from '../constants' -import { SUPPORTED_LOCALES } from '../constants' +import type { QuestLocale } from '@odyssey/constants' +import { SUPPORTED_LOCALES } from '@odyssey/constants' export interface INode { path: string diff --git a/server/Dockerfile b/server/Dockerfile index f2b5e93..6905f19 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,27 +1,28 @@ -FROM node:20-alpine AS build +FROM oven/bun:1.3.14-alpine AS prod WORKDIR /app -COPY ./package.json yarn.lock ./ +COPY package.json bun.lock ./ +COPY app/package.json ./app/package.json COPY server/package.json ./server/package.json -RUN yarn install +COPY services/analytics/package.json ./services/analytics/package.json +COPY tests/package.json ./tests/package.json +COPY packages/constants/package.json ./packages/constants/package.json +COPY packages/file-graph/package.json ./packages/file-graph/package.json +COPY packages/game/package.json ./packages/game/package.json +COPY packages/models/package.json ./packages/models/package.json +COPY packages/utils/package.json ./packages/utils/package.json +RUN bun install --frozen-lockfile --production --filter server + # Install docker cli -COPY server ./server -COPY packages ./packages -COPY tsconfig.json ./tsconfig.json -RUN yarn workspace server build - -# Production -FROM node:20-alpine AS prod - -WORKDIR /app COPY --from=docker:dind /usr/local/bin/docker /usr/local/bin/ -COPY --from=build /app/node_modules ./node_modules -COPY --from=build /app/server ./server +COPY tsconfig.json ./tsconfig.json +COPY packages ./packages +COPY server ./server COPY ./quests ./quests ENV NODE_ENV=production WORKDIR /app/server -CMD [ "yarn", "start" ] +CMD [ "bun", "src/index.ts" ] ENV HOST=0.0.0.0 ENV PORT=3000 diff --git a/server/src/index.ts b/server/src/index.ts index ad48f98..68a6531 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -24,7 +24,7 @@ import { createContext } from './trpc.js' async function main() { if (!config.secret) { logger.error( - 'No SECRET_KEY found in .env! To set up a persistent key, please run `yarn setup`:' + 'No SECRET_KEY found in .env! To set up a persistent key, please run `bun run setup`:' ) process.exit(1) } diff --git a/services/analytics/Dockerfile b/services/analytics/Dockerfile index 973c62c..e89c520 100644 --- a/services/analytics/Dockerfile +++ b/services/analytics/Dockerfile @@ -1,27 +1,26 @@ -FROM node:20-alpine AS build +FROM oven/bun:1.3.14-alpine AS prod WORKDIR /app -COPY ./package.json yarn.lock ./ +COPY package.json bun.lock ./ +COPY app/package.json ./app/package.json +COPY server/package.json ./server/package.json COPY services/analytics/package.json ./services/analytics/package.json -RUN yarn install --frozen-lockfile +COPY tests/package.json ./tests/package.json +COPY packages/constants/package.json ./packages/constants/package.json +COPY packages/file-graph/package.json ./packages/file-graph/package.json +COPY packages/game/package.json ./packages/game/package.json +COPY packages/models/package.json ./packages/models/package.json +COPY packages/utils/package.json ./packages/utils/package.json +RUN bun install --frozen-lockfile --production --filter analytics COPY tsconfig.json ./tsconfig.json COPY packages ./packages COPY services/analytics ./services/analytics -RUN yarn workspace analytics build - -# Production stage -FROM node:20-alpine AS prod - -WORKDIR /app -COPY --from=build /app/node_modules ./node_modules -COPY --from=build /app/services/analytics ./services/analytics - ENV NODE_ENV=production ENV HOST=0.0.0.0 ENV PORT=3001 EXPOSE 3001 WORKDIR /app/services/analytics -CMD [ "yarn", "start" ] \ No newline at end of file +CMD [ "bun", "src/index.ts" ] diff --git a/tests/Dockerfile b/tests/Dockerfile index d5c96d2..d51f4dd 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -1,12 +1,22 @@ FROM cypress/browsers +COPY --from=oven/bun:1.3.14 /usr/local/bin/bun /usr/local/bin/bun + WORKDIR /e2e -COPY package.json yarn.lock ./ +COPY package.json bun.lock ./ +COPY app/package.json ./app/package.json +COPY server/package.json ./server/package.json +COPY services/analytics/package.json ./services/analytics/package.json COPY tests/package.json ./tests/package.json -RUN yarn install --frozen-lockfile +COPY packages/constants/package.json ./packages/constants/package.json +COPY packages/file-graph/package.json ./packages/file-graph/package.json +COPY packages/game/package.json ./packages/game/package.json +COPY packages/models/package.json ./packages/models/package.json +COPY packages/utils/package.json ./packages/utils/package.json +RUN bun install --frozen-lockfile COPY quests ./quests COPY tests ./tests WORKDIR /e2e/tests -CMD [ "yarn", "test" ] +CMD [ "bun", "run", "test" ] diff --git a/tests/package.json b/tests/package.json index 885c84b..b5f181e 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "license": "MIT", "scripts": { - "test": "yarn cypress run", - "test:open": "yarn cypress open" + "test": "cypress run", + "test:open": "cypress open" }, "dependencies": { "@testing-library/cypress": "^10.0.1",