From dc29ff1635640ee518c5354a691e92e98ce75037 Mon Sep 17 00:00:00 2001 From: Hazi <83254065@qq.com> Date: Mon, 21 Oct 2024 20:39:34 +0800 Subject: [PATCH] =?UTF-8?q?chore=EF=BC=9A=E9=85=8D=E7=BD=AE=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/main.yml | 3 --- .github/workflows/deploy.yml | 41 ++++++++++++++++++++++++++++++++++++ Dockerfile | 37 ++++++++++++++++++++++++++++++++ nginx.conf | 24 +++++++++++++++++++++ package.json | 1 + src/App.vue | 2 +- src/main.ts | 6 +++--- tsconfig.tsbuildinfo | 1 + vite.config.ts | 11 ++++++++-- 9 files changed, 117 insertions(+), 9 deletions(-) delete mode 100644 .github/main.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile create mode 100644 nginx.conf create mode 100644 tsconfig.tsbuildinfo diff --git a/.github/main.yml b/.github/main.yml deleted file mode 100644 index 6817f34..0000000 --- a/.github/main.yml +++ /dev/null @@ -1,3 +0,0 @@ -name: 部署到 weilai.team - -on: [merge] \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..211c287 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,41 @@ +name: Deploy to Server + +on: + push: + branches: + - main + +env: + DOCKER_IMAGE: + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build the Docker image + run: docker build -t weilai.team:${{ github.sha }} . + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7e356e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# 构建阶段 + +# 使用 bun 镜像作为构建基础镜像 +FROM oven/bun:alpine AS build + +# 设置目录为 /app +WORKDIR /app + +# 将 package 文件复制到镜像中 +COPY package*.json ./ + +# 安装依赖 +RUN bun install + +# 复制所有源代码到镜像中 +COPY . . + +# 构建 Vue 项目 +RUN bun run build + +# 运行阶段 + +# 使用 nginx 镜像作为运行时基础镜像 +FROM nginx:alpine + +# 从构建阶段的镜像中复制构建好的静态文件到 nginx 的默认静态文件目录中 +COPY --from=build /app/dist /usr/share/nginx/html + +# 复制自定义的 Nginx 配置文件到 Nginx 的配置目录 +COPY ./nginx.conf /etc/nginx/nginx.conf + +# 暴露 80 端口 +EXPOSE 80 + +# 启动 Nginx 并保持在前台运行 +CMD [ "nginx", "-g", "daemon off;" ] + diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..bfd61d9 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name your-domain.com; # 你的域名 + + root /usr/share/nginx/html; # Vue 应用打包后的文件存放目录 + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /api/ { + proxy_pass http://backend-service; # 后端 API 的地址 + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/package.json b/package.json index 23a5805..3fd8c61 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "devDependencies": { "@biomejs/biome": "1.9.4", + "@types/node": "^22.7.7", "@vitejs/plugin-vue": "^5.1.4", "typescript": "^5.5.3", "vite": "^5.4.8", diff --git a/src/App.vue b/src/App.vue index fab9727..9125263 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 01433bc..b670de8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { createApp } from 'vue' -import App from './App.vue' +import { createApp } from "vue"; +import App from "./App.vue"; -createApp(App).mount('#app') +createApp(App).mount("#app"); diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo new file mode 100644 index 0000000..a6b7c8c --- /dev/null +++ b/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./src/main.ts","./src/vite-env.d.ts","./src/api/index.ts","./src/modules/console/main.ts","./src/modules/recruitment/main.ts","./src/app.vue","./src/modules/console/app.vue","./src/modules/recruitment/app.vue"],"version":"5.6.3"} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 89c983a..a3e3532 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,12 +1,19 @@ import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; +import path, { resolve } from "node:path"; -// https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], build: { rollupOptions: { - input: {} + input: { + main: path.resolve(__dirname, "./index.html"), + console: path.resolve(__dirname, "./src/modules/console/index.html"), + recruitment: path.resolve( + __dirname, + "./src/modules/recruitment/index.html", + ), + }, }, }, });