From b28f92b99f24a46687e9aa26f63358f71244baa1 Mon Sep 17 00:00:00 2001 From: imsyy Date: Wed, 6 Dec 2023 13:41:45 +0800 Subject: [PATCH] feat: Add Docker #107 --- .dockerignore | 15 +++++++++++++++ .eslintignore | 3 +++ Dockerfile | 16 ++++++++++++++++ README.md | 11 +++++++++++ docker-compose.yml | 9 +++++++++ package.json | 3 ++- src/api/index.js | 1 + vite.config.js | 1 + 8 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .eslintignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2810f83 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +node_modules +npm-debug.log +Dockerfile* +docker-compose* +.dockerignore +.git +.github +.gitignore +README.md +LICENSE +.vscode +dist +build +images +script \ No newline at end of file diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..91f2905 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules +dist +.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4c7ee03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# 构建应用 +FROM node:18 AS builder +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +# 最小化镜像 +FROM node:18-alpine +WORKDIR /app +COPY --from=builder /app/dist ./dist +RUN npm install -g http-server + +EXPOSE 12445 +CMD ["http-server", "dist", "-p", "12445"] \ No newline at end of file diff --git a/README.md b/README.md index 0955359..63e84ca 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,17 @@ pnpm build ``` > 构建完成后,静态资源会在 **`dist` 目录** 中生成,可将 **`dist` 文件夹下的文件**上传至服务器,也可使用 `Vercel` 等托管平台一键导入并自动部署 +### Docker 部署 + +> 安装及配置 Docker 将不在此处说明,请自行解决 + +```bash +// 构建 +docker build -t home . +// 运行 +docker run -p 12445:12445 -d home +``` + ### 网站链接 在 `src/assets/siteLinks.json` 中可以自定义网站链接(以指向自己的网站): diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bb80acd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' + +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "12445:12445" diff --git a/package.json b/package.json index b6c5d58..0faaa1b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "dev": "vite --host", "build": "vite build", "preview": "vite preview", - "format": "prettier --write src/" + "format": "prettier --write src/", + "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix" }, "dependencies": { "aplayer": "^1.10.1", diff --git a/src/api/index.js b/src/api/index.js index 773b1ed..2db7bd0 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -13,6 +13,7 @@ export const getPlayerList = async (server, type, id) => { const data = await res.json(); if (data[0].url.startsWith("@")) { + // eslint-disable-next-line no-unused-vars const [handle, jsonpCallback, jsonpCallbackFunction, url] = data[0].url.split("@").slice(1); const jsonpData = await fetchJsonp(url).then((res) => res.json()); const domain = ( diff --git a/vite.config.js b/vite.config.js index 3efee52..2bd70e0 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ import { defineConfig, loadEnv } from "vite"; import { ElementPlusResolver } from "unplugin-vue-components/resolvers"; import { resolve } from "path";