diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml new file mode 100644 index 0000000..df9d08f --- /dev/null +++ b/.github/workflows/docker-build.yaml @@ -0,0 +1,26 @@ +name: Docker Build and Push + +on: + push: + branches: ['main'] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + run: ls -la + + - name: 登录 Docker + uses: docker/login-action@v3 + with: + registry: registry.cn-guangzhou.aliyuncs.com + username: ${{ secrets.ALIYUN_DOCKER_NAME}} + password: ${{ secrets.ALIYUN_PASSWORD }} + + - name: 构建 Docker 镜像 + uses: docker/build-push-action@v5 + with: + push: true + tags: registry.cn-guangzhou.aliyuncs.com/lyouc/test_github_action:v2.0 diff --git a/.gitignore b/.gitignore index 8ee54e8..33c2c45 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ coverage *.sw? *.tsbuildinfo +*/__pycache__/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..37b1905 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# 使用Node.js官方镜像作为构建环境 +FROM node:18-alpine as build-stage +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +RUN npm install -g pnpm && pnpm install +COPY . . +RUN pnpm run build + +# 使用Nginx作为生产环境 +FROM python:3.10-slim as production-stage +WORKDIR /app +COPY --from=build-stage /app/dist /app +RUN pip install fastapi uvicorn + +EXPOSE 3307 +CMD ["uvicorn", "script.main:app", "--host", "0.0.0.0", "--port", "3307"] diff --git a/script/main.py b/script/main.py new file mode 100644 index 0000000..6805144 --- /dev/null +++ b/script/main.py @@ -0,0 +1,10 @@ +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +import uvicorn + +app = FastAPI() + +app.mount("/", StaticFiles(directory="./dist"), name="static") + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0", port=3307) \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index 1cb6acc..2e28e86 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,7 +1,7 @@ -import { createRouter, createWebHistory } from 'vue-router' +import { createRouter, createWebHashHistory } from 'vue-router' const router = createRouter({ - history: createWebHistory(import.meta.env.BASE_URL), + history: createWebHashHistory(import.meta.env.BASE_URL), routes: [ { path: '/', diff --git a/vite.config.ts b/vite.config.ts index 4217010..508dbdd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,13 +6,11 @@ import vueDevTools from 'vite-plugin-vue-devtools' // https://vite.dev/config/ export default defineConfig({ - plugins: [ - vue(), - vueDevTools(), - ], + base: './', + plugins: [vue(), vueDevTools()], resolve: { alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) + '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, })