diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a9561ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# 忽略 .git 目录 +.git +.gitignore + +pnpm-lock.yaml + +dist/ + +# 忽略应设置为容器卷的东西 +db/ + +# 忽略 node_modules 目录,因为它可以基于 package.json 重新生成 +node_modules/ \ No newline at end of file diff --git a/DOCKERFILE b/DOCKERFILE new file mode 100644 index 0000000..80f3178 --- /dev/null +++ b/DOCKERFILE @@ -0,0 +1,21 @@ +# 使用官方 Node.js 20.18.0 版本的 slim 镜像作为基础镜像 +FROM node:20.18.0 + +# 安装 Deno +RUN curl -fsSL https://x.deno.js.cn/install.sh | sh + +# 将 Deno 的可执行文件路径添加到 PATH 环境变量中 +ENV DENO_INSTALL="/root/.deno" +ENV PATH="$DENO_INSTALL/bin:$PATH" + +# 设置工作目录 +WORKDIR /app + +# 将本地文件复制到容器中 +COPY . . + +RUN npm config set registry https://registry.npmmirror.com +RUN npm install + +# 运行您的应用 +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/package.json b/package.json index 86395f7..4b24e06 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,9 @@ "test": "/root/.deno/bin/deno run -A ./src/index.js", "nodemon": "deno run -A --watch src/index.ts", "build:linux": "deno compile --no-check -o dist/test --target x86_64-unknown-linux-gnu -A src/index.ts", - "build:win": "deno compile --no-check -o dist/test --target x86_64-pc-windows-msvc -A src/index.ts" + "build:win": "deno compile --no-check -o dist/test --target x86_64-pc-windows-msvc -A src/index.ts", + "docker": "docker build -t qqbot-image .", + "docker:run": "docker run -d --rm --name qqbot-image-app -v ./db:/app/db qqbot-image" }, "author": "mine123456@foxmail.com", "license": "ISC",