Skip to content

Commit

Permalink
chore:配置 Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazi7 committed Oct 21, 2024
1 parent d302978 commit dc29ff1
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .github/main.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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;" ]

24 changes: 24 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
</script>

<template>
ds

</template>

<style lang="scss" scoped></style>
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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");
1 change: 1 addition & 0 deletions tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -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"}
11 changes: 9 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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",
),
},
},
},
});

0 comments on commit dc29ff1

Please sign in to comment.