diff --git a/README.md b/README.md index 2b253f8..d244d70 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,21 @@ # PowerJob-Console + 分布式调度与计算框架——PowerJob 前端页面 -项目文档:https://www.yuque.com/powerjob/guidence +项目文档: # 命令 + npm run serve(使用 .env.dev ,请求 localhost:7700) npm run build(使用 .env.product) npm run build_spring(使用 .env.spring,请求 /,构建内置于 SpringBoot 的 vue project) + +# 使用容器启动 + +修改`docker-compose.yml`文件,将`API_HOST`和`API_PORT`两个环境变量设置为后端接口地址。 + +```bash +docker compose up -d --build +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2411548 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + console: + restart: always + container_name: powerjob-console + image: powerjob/powerjob-console:latest + build: + context: . + dockerfile: docker/Dockerfile + environment: + API_HOST: 127.0.0.1 + PORT: 7700 + ports: + - "8880:80" diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..b5b44bb --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,29 @@ +### Builder +FROM node:14.20.0 AS builder + +WORKDIR /app +# RUN npm config set registry https://registry.npmmirror.com + +COPY package.json package.json +RUN npm install + +COPY public public +COPY src src +COPY .env.product .env.product +RUN npm run build + +### Runner +FROM openresty/openresty:alpine-apk AS runner +MAINTAINER "z.t.x@foxmail.com" + +COPY --from=builder /app/dist /app/dist + +ENV TZ=Asia/Shanghai +ENV API_HOST='127.0.0.1' +ENV API_PORT='7700' + +COPY docker/default.conf /etc/nginx/conf.d/ +COPY docker/env.main /etc/nginx/conf.d/ +COPY docker/api.lua /etc/nginx/lua/ + +EXPOSE 80 diff --git a/docker/api.lua b/docker/api.lua new file mode 100644 index 0000000..ebf412d --- /dev/null +++ b/docker/api.lua @@ -0,0 +1,19 @@ +local balancer = require "ngx.balancer" + +local api_host = os.getenv("API_HOST") +local api_port = tonumber(os.getenv("API_PORT")) + +if not api_host then + ngx.log(ngx.ERR, "API_HOST is not set") + ngx.exit(500) +end +if not api_port then + ngx.log(ngx.ERR, "API_PORT is not a valid number: ", api_port) + ngx.exit(500) +end + +local ok, err = balancer.set_current_peer(api_host, api_port) +if not ok then + ngx.log(ngx.ERR, "Failed to set peer: ", err) + ngx.exit(502) +end diff --git a/docker/default.conf b/docker/default.conf new file mode 100644 index 0000000..0b5e6e4 --- /dev/null +++ b/docker/default.conf @@ -0,0 +1,19 @@ +upstream api { + server 127.0.0.1; + balancer_by_lua_file /etc/nginx/lua/api.lua; +} + +server { + listen 80; + root /app/dist; + try_files $uri $uri/ /index.html; + + location /api/ { + proxy_pass http://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; + add_header Cache-Control no-cache; + } +} diff --git a/docker/env.main b/docker/env.main new file mode 100644 index 0000000..2ff69cb --- /dev/null +++ b/docker/env.main @@ -0,0 +1,2 @@ +env API_HOST; +env API_PORT; diff --git a/src/main.js b/src/main.js index 078e84f..a4d0b50 100644 --- a/src/main.js +++ b/src/main.js @@ -15,9 +15,8 @@ import store from "./store"; import common from "./common"; Vue.use(ElementUI); -// let baseURL = "http://139.224.83.134:7700"; -let baseURL = process.env.VUE_APP_BASE_URL; -// let baseURL = '/api'; +// let baseURL = process.env.VUE_APP_BASE_URL; +let baseURL = '/api'; let timeout = 10000;