Skip to content

Commit

Permalink
feat(deploy): 统一web部分到server
Browse files Browse the repository at this point in the history
feat(deploy): 统一web部分到server
  • Loading branch information
aide-cloud committed Mar 27, 2024
1 parent 1beae1c commit 6986f7e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 72 deletions.
20 changes: 2 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ GO_BUILD_ARG:=CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(BUILD_GOARCH)
GIT_TAG=$(shell git describe --tags --always)
GIT_MOD=$(shell if ! git diff-index --quiet HEAD;then echo "-dirty";fi)
VERSION:=$(GIT_TAG)$(GIT_MOD)
PROM-WEB-VERSION:=$(VERSION)
PROM-SERVER-VERSION:=$(VERSION)
PROM-AGENT-VERSION:=$(VERSION)

# image
PROM-WEB-IMAGE:=${REPO}/moon-web:${PROM-WEB-VERSION}
PROM-SERVER-IMAGE:=${REPO}/moon-server:${PROM-SERVER-VERSION}
PROM-AGENT-IMAGE:=${REPO}/moon-agent:${PROM-AGENT-VERSION}

Expand Down Expand Up @@ -68,19 +66,9 @@ dev:
@cd $(APP_NAME) && make dev

# ------------------ DOCKER ------------------
all-docker-build: prom-web-docker-build prom-server-docker-build prom-agent-docker-build
all-docker-build: prom-server-docker-build prom-agent-docker-build

all-docker-push: prom-web-docker-push prom-server-docker-push prom-agent-docker-push

prom-web-docker-build:
@echo "Building docker image with the manager-web..."
docker build --no-cache -t $(PROM-WEB-IMAGE) -f ./deploy/docker/prom-web/Dockerfile .
@echo "Successfully build docker image with the web."

prom-web-docker-push:
@echo "start push image [$(PROM-WEB-IMAGE)]"
docker push $(PROM-WEB-IMAGE)
@echo "Successfully push image [$(PROM-WEB-IMAGE)] to target repo."
all-docker-push: prom-server-docker-push prom-agent-docker-push

prom-server-docker-build:
@echo "Building docker image with the prom-server..."
Expand Down Expand Up @@ -113,10 +101,6 @@ prom-server-compose-up: clean-server-cache prom-server-docker-build
docker tag $(PROM-SERVER-IMAGE) docker-prometheus_manager_server:latest
docker-compose -f ./deploy/docker/docker-compose.yaml up prometheus_manager_server -d --no-build

prom-web-compose-up: prom-web-docker-build
docker tag $(PROM-WEB-IMAGE) docker-prometheus_manager_web:latest
docker-compose -f ./deploy/docker/docker-compose.yaml up prometheus_manager_web -d --no-build

prom-agent-compose-up: prom-agent-docker-build
docker tag $(PROM-AGENT-IMAGE) docker-prometheus_manager_agent:latest
docker-compose -f ./deploy/docker/docker-compose.yaml up prometheus_manager_agent -d --no-build
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@
* 拉取镜像

```shell
# web
docker pull aidemoonio/moon-web:latest
# agent
docker pull aidemoonio/moon-agent:latest
# server
Expand All @@ -86,10 +84,8 @@
* 启动服务

```shell
# web
docker run -d --name moon-web -p 8000:80 aidemoonio/moon-web:latest
# server
docker run -d --name moon-server -p 8001:8000 -p 8888:8888 aidemoonio/moon-server:latest
docker run -d --name moon-server -p 8001:8000 -p 8888:8888 - p 8000:80 aidemoonio/moon-server:latest
# agent
docker run -d --name moon-agent -p 8002:8000 aidemoonio/moon-agent:latest
```
Expand Down
14 changes: 1 addition & 13 deletions deploy/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- "8001:8000"
- "8888:8888"
- "9001:9000"
- "8000:80"
volumes:
- "../../app/prom_server/configs/:/data/conf"
- "../../app/prom_server/cache:/app/cache"
Expand All @@ -41,18 +42,5 @@ services:
depends_on:
- prometheus_manager_server
- prometheus_manager_web
networks:
prometheus_manager_net:

prometheus_manager_web:
container_name: prometheus_manager_web
build:
context: ../..
dockerfile: ./deploy/docker/prom-web/Dockerfile
# image: docker.hub/prometheus-manager/web:v0.0.0
ports:
- "8000:80"
depends_on:
- prometheus_manager_server
networks:
prometheus_manager_net:
37 changes: 33 additions & 4 deletions deploy/docker/prom-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.0 AS builder
FROM golang:1.21.0 AS serverBuilder
ARG VERSION=v0.0.0

WORKDIR /src
Expand All @@ -7,26 +7,55 @@ RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
COPY ../../../.. /src
RUN mkdir -p bin/ && go build -ldflags "-X main.Version=$VERSION" -o ./bin/ ./app/prom_server/...

# 使用官方Node.js镜像作为基础镜像
FROM node:latest as webBuilder

# 设置工作目录
WORKDIR /usr/src/app

# 将前端应用程序代码复制到容器中
COPY ../../../web .

RUN rm -rf node_modules

# 设置npm源
RUN npm config set registry https://mirrors.cloud.tencent.com/npm/

# 安装依赖
RUN npm install

# 编译前端应用程序
RUN npm run build-docker

FROM debian:stable-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
netbase \
nginx \
&& rm -rf /var/lib/apt/lists/ \
&& apt-get autoremove -y && apt-get autoclean -y

COPY --from=builder /src/bin /app
COPY --from=builder /src/app/prom_server/configs /data/conf
# /usr/share/nginx/html
COPY --from=webBuilder /usr/src/app/dist /usr/share/nginx/html
COPY --from=webBuilder /usr/src/app/default.conf /etc/nginx/conf.d/default.conf
COPY --from=webBuilder /usr/src/app/nginx.conf /etc/nginx/nginx.conf
COPY --from=serverBuilder /src/bin /app
COPY --from=serverBuilder /src/app/prom_server/configs /data/conf

WORKDIR /app

EXPOSE 8000
EXPOSE 8888
EXPOSE 9000
EXPOSE 80
VOLUME /data/conf
VOLUME /app/cache
VOLUME /etc/nginx/conf.d

# TZ=Asia/Shanghai
ENV TZ=Asia/Shanghai

CMD ["./prom_server", "-conf", "/data/conf"]
#CMD ["nginx", "", "./prom_server", "-conf", "/data/conf"]
# 同时执行nginx 和 prom_server
CMD ["bash", "-c", "nginx && ./prom_server -conf /data/conf"]
28 changes: 0 additions & 28 deletions deploy/docker/prom-web/Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions web/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ server {
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_pass http://host.docker.internal:8001;
proxy_pass http://localhost:8000;
}

location /ws {
proxy_pass http://host.docker.internal:8888;
proxy_pass http://localhost:8888;
proxy_read_timeout 500;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
Expand Down
31 changes: 31 additions & 0 deletions web/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
user root;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}
2 changes: 0 additions & 2 deletions web/src/apis/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ const host =
const hostMap: { [key: string]: string } = {
[localhost]: 'http://localhost:8000',
[local127]: 'http://localhost:8000',
[localhostDocker]: 'http://localhost:8001'
}

const wsHostMap: { [key: string]: string } = {
[localhost]: 'ws://localhost:8888/',
[local127]: 'ws://localhost:8888/',
[localhostDocker]: 'ws://localhost:8888/'
}

export const getWsURL = () => {
Expand Down

0 comments on commit 6986f7e

Please sign in to comment.