mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
refactor: use bun in Dockerfile and CI workflow
This commit is contained in:
1 parent
77577d9b8d
commit
634dc8f987
16 files changed
+99
-71
No files matched your search
@@ -3,3 +3,4 @@
|
|||||||
**/dist
|
**/dist
|
||||||
**/tsconfig.tsbuildinfo
|
**/tsconfig.tsbuildinfo
|
||||||
data
|
data
|
||||||
|
postgres-data
|
||||||
@@ -11,18 +11,26 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
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
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: yarn install
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Type check
|
||||||
|
run: bun run type-check
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: yarn build
|
run: bun run build
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: yarn lint
|
run: bun run lint
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: yarn test
|
run: bun run test
|
||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
run: docker-compose -f docker-compose.testing.yml build base backend app-test cypress
|
run: docker-compose -f docker-compose.testing.yml build base backend app-test cypress
|
||||||
|
|
||||||
- name: Build Test Quests
|
- 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
|
- name: Run Cypress Tests
|
||||||
env:
|
env:
|
||||||
|
|||||||
Vendored
+4
-4
@@ -4,10 +4,10 @@
|
|||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "File Graph Yarn Jest",
|
"name": "File Graph Jest",
|
||||||
"runtimeExecutable": "yarn",
|
"runtimeExecutable": "bun",
|
||||||
"args": ["test", "--runInBand"],
|
"args": ["run", "test", "packages/file-graph", "--runInBand"],
|
||||||
"cwd": "${workspaceFolder}/packages/file-graph",
|
"cwd": "${workspaceFolder}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"internalConsoleOptions": "neverOpen"
|
"internalConsoleOptions": "neverOpen"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,15 @@
|
|||||||
|
|
||||||
## TLDR
|
## TLDR
|
||||||
|
|
||||||
yarn install
|
bun install
|
||||||
cp .env.sample .env
|
cp .env.sample .env
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
yarn dev
|
bun run dev
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- NodeJS v20+
|
- Bun: v1.3+
|
||||||
- Docker
|
- Docker
|
||||||
- Yarn: v1.22
|
|
||||||
|
|
||||||
## Known Issues
|
## 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
|
git clone https://github.com/lancatlin/linux-odyssey.git
|
||||||
cd linux-odyssey
|
cd linux-odyssey
|
||||||
yarn install
|
bun install
|
||||||
|
|
||||||
## Project Structures
|
## Project Structures
|
||||||
|
|
||||||
@@ -104,7 +103,7 @@ Customized `entrypoint.sh` for each quest is not yet supported.
|
|||||||
|
|
||||||
To build all quests:
|
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.
|
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):
|
Run dev server (frontend, backend):
|
||||||
|
|
||||||
yarn dev
|
bun run dev
|
||||||
|
|
||||||
To develop analytics dashboard:
|
To develop analytics dashboard:
|
||||||
|
|
||||||
yarn analytics
|
bun run analytics
|
||||||
|
|
||||||
The default username and password is `alex` and `Alex1234`.
|
The default username and password is `alex` and `Alex1234`.
|
||||||
|
|
||||||
@@ -146,12 +145,12 @@ The default username and password is `alex` and `Alex1234`.
|
|||||||
|
|
||||||
Unit tests:
|
Unit tests:
|
||||||
|
|
||||||
yarn test:unit
|
bun run test
|
||||||
|
|
||||||
Run Cypress locally, using the current development containers:
|
Run Cypress locally, using the current development containers:
|
||||||
|
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
yarn test:e2e
|
bun run test:e2e
|
||||||
|
|
||||||
Run Cypress in container, create brand-new containers along with it:
|
Run Cypress in container, create brand-new containers along with it:
|
||||||
|
|
||||||
@@ -183,7 +182,7 @@ Start the service
|
|||||||
|
|
||||||
# Server side
|
# Server side
|
||||||
docker compose -f docker-compose.prod.yml pull
|
docker compose -f docker-compose.prod.yml pull
|
||||||
yarn build:quests
|
bun run build:quests
|
||||||
docker compose -f docker-compose.prod.yml up -d
|
docker compose -f docker-compose.prod.yml up -d
|
||||||
|
|
||||||
### Necessary Configuration
|
### Necessary Configuration
|
||||||
@@ -197,4 +196,4 @@ You can copy from `.env.sample`
|
|||||||
|
|
||||||
You can generate a random key by running
|
You can generate a random key by running
|
||||||
|
|
||||||
yarn setup
|
bun run setup
|
||||||
+11
-4
@@ -1,17 +1,24 @@
|
|||||||
# Base stage
|
# Base stage
|
||||||
FROM node:20-alpine AS build
|
FROM oven/bun:1.3.14-alpine AS build
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json yarn.lock ./
|
COPY package.json bun.lock ./
|
||||||
COPY app/package.json ./app/package.json
|
COPY app/package.json ./app/package.json
|
||||||
COPY server/package.json ./server/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 tsconfig.json ./tsconfig.json
|
||||||
COPY server ./server
|
COPY server ./server
|
||||||
COPY packages ./packages
|
COPY packages ./packages
|
||||||
COPY app ./app
|
COPY app ./app
|
||||||
RUN yarn workspace app build
|
RUN bun run --filter app build
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
FROM nginx:stable-alpine AS prod
|
FROM nginx:stable-alpine AS prod
|
||||||
|
|||||||
@@ -102,6 +102,7 @@
|
|||||||
"name": "@odyssey/models",
|
"name": "@odyssey/models",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@odyssey/constants": "workspace:*",
|
||||||
"mongoose": "^8.24.1",
|
"mongoose": "^8.24.1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+10
-9
@@ -81,22 +81,23 @@ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|||||||
sudo apt install -y nodejs
|
sudo apt install -y nodejs
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install Yarn 1.22
|
### Install Bun
|
||||||
|
|
||||||
```bash
|
```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:
|
Verify the installations:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git --version
|
git --version
|
||||||
node --version
|
node --version
|
||||||
npm --version
|
bun --version
|
||||||
yarn --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
|
## 4. Clone the Project
|
||||||
|
|
||||||
@@ -130,10 +131,10 @@ code .
|
|||||||
From the project root, run:
|
From the project root, run:
|
||||||
|
|
||||||
```bash
|
```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.
|
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:
|
Start the frontend and backend development servers:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn dev
|
bun run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Keep the terminal running and open the following address in your browser:
|
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:
|
You can verify that the project builds successfully by running:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn build
|
bun run build
|
||||||
```
|
```
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FileGraph, IFileNode } from '../file-graph'
|
import { FileGraph, IFileNode } from '@odyssey/file-graph'
|
||||||
import { Quest } from './Quest'
|
import { Quest } from './Quest'
|
||||||
import {
|
import {
|
||||||
IQuest,
|
IQuest,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
".": "./index.ts"
|
".": "./index.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@odyssey/constants": "workspace:*",
|
||||||
"mongoose": "^8.24.1"
|
"mongoose": "^8.24.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { model, Schema, Types } from 'mongoose'
|
import { model, Schema, Types } from 'mongoose'
|
||||||
import type { QuestLocale } from '../constants'
|
import type { QuestLocale } from '@odyssey/constants'
|
||||||
import { SUPPORTED_LOCALES } from '../constants'
|
import { SUPPORTED_LOCALES } from '@odyssey/constants'
|
||||||
|
|
||||||
export interface INode {
|
export interface INode {
|
||||||
path: string
|
path: string
|
||||||
|
|||||||
+16
-15
@@ -1,27 +1,28 @@
|
|||||||
FROM node:20-alpine AS build
|
FROM oven/bun:1.3.14-alpine AS prod
|
||||||
|
|
||||||
WORKDIR /app
|
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 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
|
# 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=docker:dind /usr/local/bin/docker /usr/local/bin/
|
||||||
COPY --from=build /app/node_modules ./node_modules
|
COPY tsconfig.json ./tsconfig.json
|
||||||
COPY --from=build /app/server ./server
|
COPY packages ./packages
|
||||||
|
COPY server ./server
|
||||||
COPY ./quests ./quests
|
COPY ./quests ./quests
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
WORKDIR /app/server
|
WORKDIR /app/server
|
||||||
CMD [ "yarn", "start" ]
|
CMD [ "bun", "src/index.ts" ]
|
||||||
|
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ import { createContext } from './trpc.js'
|
|||||||
async function main() {
|
async function main() {
|
||||||
if (!config.secret) {
|
if (!config.secret) {
|
||||||
logger.error(
|
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)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
FROM node:20-alpine AS build
|
FROM oven/bun:1.3.14-alpine AS prod
|
||||||
|
|
||||||
WORKDIR /app
|
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
|
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 tsconfig.json ./tsconfig.json
|
||||||
COPY packages ./packages
|
COPY packages ./packages
|
||||||
COPY services/analytics ./services/analytics
|
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 NODE_ENV=production
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
ENV PORT=3001
|
ENV PORT=3001
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
|
||||||
WORKDIR /app/services/analytics
|
WORKDIR /app/services/analytics
|
||||||
CMD [ "yarn", "start" ]
|
CMD [ "bun", "src/index.ts" ]
|
||||||
+13
-3
@@ -1,12 +1,22 @@
|
|||||||
FROM cypress/browsers
|
FROM cypress/browsers
|
||||||
|
|
||||||
|
COPY --from=oven/bun:1.3.14 /usr/local/bin/bun /usr/local/bin/bun
|
||||||
|
|
||||||
WORKDIR /e2e
|
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
|
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 quests ./quests
|
||||||
COPY tests ./tests
|
COPY tests ./tests
|
||||||
WORKDIR /e2e/tests
|
WORKDIR /e2e/tests
|
||||||
|
|
||||||
CMD [ "yarn", "test" ]
|
CMD [ "bun", "run", "test" ]
|
||||||
+2
-2
@@ -6,8 +6,8 @@
|
|||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "yarn cypress run",
|
"test": "cypress run",
|
||||||
"test:open": "yarn cypress open"
|
"test:open": "cypress open"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@testing-library/cypress": "^10.0.1",
|
"@testing-library/cypress": "^10.0.1",
|
||||||
|
|||||||
Reference in new issue
Block a user