Skip to content

Commit f877fd2

Browse files
committed
feat: add docker support
1 parent 0df2c3b commit f877fd2

11 files changed

+206
-4
lines changed

Dockerfile

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# 构建阶段
2+
FROM oven/bun:1 as builder
3+
4+
# 安装构建依赖
5+
RUN apt-get update && apt-get install -y \
6+
python3 \
7+
build-essential \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /app
11+
12+
# 复制 package.json 和 lock 文件
13+
COPY package*.json ./
14+
COPY bun.lockb ./
15+
16+
# 安装依赖
17+
RUN bun install
18+
19+
# 复制源代码
20+
COPY . .
21+
22+
# 构建应用
23+
RUN bun run build
24+
25+
# 运行阶段
26+
FROM oven/bun:1-slim
27+
28+
# 安装 Playwright 依赖
29+
RUN apt-get update && apt-get install -y \
30+
python3 \
31+
libnss3 \
32+
libnspr4 \
33+
libatk1.0-0 \
34+
libatk-bridge2.0-0 \
35+
libcups2 \
36+
libdrm2 \
37+
libxkbcommon0 \
38+
libxcomposite1 \
39+
libxdamage1 \
40+
libxfixes3 \
41+
libxrandr2 \
42+
libgbm1 \
43+
libasound2 \
44+
&& rm -rf /var/lib/apt/lists/*
45+
46+
# 安装 Playwright 浏览器
47+
RUN bunx playwright install
48+
49+
WORKDIR /app
50+
51+
# 从构建阶段复制构建产物和源代码
52+
COPY --from=builder /app/.output ./
53+
COPY --from=builder /app/node_modules ./node_modules
54+
COPY --from=builder /app/hono ./hono
55+
COPY start.sh ./
56+
57+
# 设置环境变量
58+
ENV NODE_ENV=production
59+
ENV NUXT_HOST=0.0.0.0
60+
ENV NUXT_PORT=3000
61+
ENV PYTHON=/usr/bin/python3
62+
63+
# 设置启动脚本权限
64+
RUN chmod +x ./start.sh
65+
66+
# 暴露端口
67+
EXPOSE 3000
68+
EXPOSE 3001
69+
70+
# 启动应用
71+
CMD ["./start.sh"]

Dockerfile.server

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# 构建阶段
2+
FROM oven/bun:1 as builder
3+
4+
# 安装构建依赖
5+
RUN apt-get update && apt-get install -y \
6+
python3 \
7+
build-essential \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /app
11+
12+
# 复制 package.json 和 lock 文件
13+
COPY package*.json ./
14+
COPY bun.lockb ./
15+
16+
# 安装依赖
17+
RUN bun install
18+
19+
# 复制源代码
20+
COPY . .
21+
22+
# 运行阶段
23+
FROM oven/bun:1-slim
24+
25+
# 安装 Playwright 依赖
26+
RUN apt-get update && apt-get install -y \
27+
python3 \
28+
libnss3 \
29+
libnspr4 \
30+
libatk1.0-0 \
31+
libatk-bridge2.0-0 \
32+
libcups2 \
33+
libdrm2 \
34+
libxkbcommon0 \
35+
libxcomposite1 \
36+
libxdamage1 \
37+
libxfixes3 \
38+
libxrandr2 \
39+
libgbm1 \
40+
libasound2 \
41+
&& rm -rf /var/lib/apt/lists/*
42+
43+
# 安装 Playwright 浏览器
44+
RUN bunx playwright install --with-deps
45+
46+
WORKDIR /app
47+
48+
# 从构建阶段复制必要文件
49+
COPY --from=builder /app/node_modules ./node_modules
50+
COPY --from=builder /app/hono ./hono
51+
52+
# 设置环境变量
53+
ENV NODE_ENV=production
54+
ENV PYTHON=/usr/bin/python3
55+
56+
# 暴露端口
57+
EXPOSE 3001
58+
59+
# 启动应用
60+
CMD ["bun", "./hono/index.ts"]

Dockerfile.web

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 构建阶段
2+
FROM oven/bun:1 as builder
3+
4+
# 安装构建依赖
5+
RUN apt-get update && apt-get install -y \
6+
python3 \
7+
build-essential \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /app
11+
12+
# 复制 package.json 和 lock 文件
13+
COPY package*.json ./
14+
COPY bun.lockb ./
15+
16+
# 安装依赖
17+
RUN bun install
18+
19+
# 复制源代码
20+
COPY . .
21+
22+
# 构建应用
23+
RUN bun run build
24+
25+
# 运行阶段
26+
FROM oven/bun:1-slim
27+
28+
WORKDIR /app
29+
30+
# 从构建阶段复制构建产物
31+
COPY --from=builder /app/.output ./
32+
COPY --from=builder /app/node_modules ./node_modules
33+
34+
# 设置环境变量
35+
ENV NODE_ENV=production
36+
ENV NUXT_HOST=0.0.0.0
37+
ENV NUXT_PORT=3000
38+
39+
# 暴露端口
40+
EXPOSE 3000
41+
42+
# 启动应用
43+
CMD ["bun", "./server/index.mjs"]

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

bun.lockb

32 Bytes
Binary file not shown.

components/ImagePreview.vue

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script setup lang="ts">
2-
import Image from 'nuxt/image'
32
import { ref } from 'vue'
43
54
interface Props {

docker-compose.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.8'
2+
3+
services:
4+
web:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.web
8+
ports:
9+
- "3000:3000"
10+
environment:
11+
- NODE_ENV=production
12+
restart: unless-stopped
13+
14+
server:
15+
build:
16+
context: .
17+
dockerfile: Dockerfile.server
18+
ports:
19+
- "3001:3001"
20+
environment:
21+
- NODE_ENV=production
22+
restart: unless-stopped

nuxt.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export default defineNuxtConfig({
88
'@nuxt/fonts',
99
'@nuxt/icon',
1010
'@nuxt/image',
11-
'@nuxtjs/tailwindcss',
12-
'dayjs-nuxt',
11+
'@nuxtjs/tailwindcss', 'dayjs-nuxt',
1312
'@pinia/colada-nuxt',
1413
'nuxt-og-image',
1514
'@nuxtjs/seo',
@@ -32,5 +31,8 @@ export default defineNuxtConfig({
3231
configPath: 'tailwind.config.js',
3332
exposeConfig: false,
3433
viewer: true,
34+
},
35+
nitro: {
36+
preset: "bun"
3537
}
3638
})

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"lucide-vue-next": "^0.484.0",
3939
"nuxt": "^3.16.1",
4040
"nuxt-og-image": "5.1.0",
41+
"ofetch": "^1.4.1",
4142
"pinia": "^3.0.1",
4243
"pinia-plugin-persistedstate": "^4.2.0",
4344
"playwright": "1.46.1",

server/middleware/proxy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export default defineEventHandler(async event => {
44
const url = event.path;
55
console.log("🚀 ~ url:", url)
66
if (url.startsWith('/api/proxy')) {
7-
return proxyRequest(event, `http://localhost:3001${url}`);
7+
return proxyRequest(event, `http://server:3001${url}`);
88
}
99
});

start.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
bun ./server/index.mjs &
3+
bun ./hono/index.ts

0 commit comments

Comments
 (0)