From 098fa4eb5c58214a1801d2af03e0c95300d1c8d4 Mon Sep 17 00:00:00 2001 From: zouxiaochuan Date: Tue, 26 Dec 2023 11:13:14 +0800 Subject: [PATCH] fix(backend): add monitor and admin in docker compose --- deploy/docker-compose/Dockerfile_admin | 19 +++++++ deploy/docker-compose/Dockerfile_backend | 4 +- deploy/docker-compose/Dockerfile_frontend | 14 +++--- deploy/docker-compose/config.json | 6 +++ deploy/docker-compose/docker-compose.yaml | 60 ++++++++++++++--------- deploy/docker-compose/nginx_admin.conf | 53 ++++++++++++++++++++ deploy/docker-compose/pip.conf | 3 ++ 7 files changed, 127 insertions(+), 32 deletions(-) create mode 100644 deploy/docker-compose/Dockerfile_admin create mode 100644 deploy/docker-compose/config.json create mode 100644 deploy/docker-compose/nginx_admin.conf create mode 100644 deploy/docker-compose/pip.conf diff --git a/deploy/docker-compose/Dockerfile_admin b/deploy/docker-compose/Dockerfile_admin new file mode 100644 index 0000000..9bef8ef --- /dev/null +++ b/deploy/docker-compose/Dockerfile_admin @@ -0,0 +1,19 @@ +FROM node:18-alpine as build + +COPY Beiming-System/frontend /learnware-frontend/ +WORKDIR /learnware-frontend + +RUN npm install -g pnpm +RUN pnpm config set registry https://registry.npmmirror.com/ +RUN pnpm install +RUN pnpm run build:admin + +FROM nginx:latest + +COPY --from=build /learnware-frontend/ /learnware-frontend/ + +EXPOSE 5173 + +COPY ./nginx_admin.conf /etc/nginx/nginx.conf + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/deploy/docker-compose/Dockerfile_backend b/deploy/docker-compose/Dockerfile_backend index 6009043..b061833 100644 --- a/deploy/docker-compose/Dockerfile_backend +++ b/deploy/docker-compose/Dockerfile_backend @@ -19,7 +19,7 @@ RUN apt-get update && apt-get install -y libffi-dev libssl-dev \ ca-certificates sqlite3 xz-utils zlib1g-dev lsb-release wget gnupg COPY ./pip.conf* /etc/ -ADD ./BM-System/requirements.txt / +ADD ./Beiming-System/backend/requirements.txt / RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' RUN wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | tee /etc/apt/trusted.gpg.d/postgres.asc @@ -31,7 +31,7 @@ COPY ./Beiming-System/backend /learnware-backend/ COPY ./Learnware /learnware/ WORKDIR /learnware-backend -COPY ./config.json* /learnware-backend/config.json +COPY ./config.json* /learnware-backend/ COPY ./swords.txt* /learnware-backend/swords.txt RUN python3 -m pip install -e /learnware/ diff --git a/deploy/docker-compose/Dockerfile_frontend b/deploy/docker-compose/Dockerfile_frontend index 8243097..0d14970 100644 --- a/deploy/docker-compose/Dockerfile_frontend +++ b/deploy/docker-compose/Dockerfile_frontend @@ -1,23 +1,23 @@ +FROM node:18-alpine as build + # suppose current folder contains these files: # Beiming-System (required): Beiming-System source code folder # nginx.conf (optional): config file for a specific deployment -FROM node:18-alpine as build -COPY ./BM-System/frontend /learnware-frontend/ -COPY env /learnware-frontend/packages/main/.env -COPY install.sh /learnware-frontend/install.sh +COPY ./Beiming-System/frontend /learnware-frontend/ +COPY env* /learnware-frontend/packages/main/.env WORKDIR /learnware-frontend RUN npm install -g pnpm RUN pnpm config set registry https://registry.npmmirror.com/ -RUN sh install.sh +RUN pnpm install RUN pnpm run build:main RUN echo "https://mirrors.aliyun.com/alpine/v3.14/main" > /etc/apk/repositories RUN apk --no-cache add zip -COPY ./BM-System/deploy/static /learnware-frontend/static -COPY ./static/* /learnware-frontend/static/ +COPY ./Beiming-System/deploy/static /learnware-frontend/static +# COPY ./static/* /learnware-frontend/static/ RUN zip -j /learnware-frontend/static/learnware-template.zip /learnware-frontend/static/learnware-template/* FROM nginx:latest diff --git a/deploy/docker-compose/config.json b/deploy/docker-compose/config.json new file mode 100644 index 0000000..89b7e93 --- /dev/null +++ b/deploy/docker-compose/config.json @@ -0,0 +1,6 @@ +{ + "redis": { + "host": "redis", + "port": 6379 + } +} diff --git a/deploy/docker-compose/docker-compose.yaml b/deploy/docker-compose/docker-compose.yaml index 9ebe7c8..904011b 100644 --- a/deploy/docker-compose/docker-compose.yaml +++ b/deploy/docker-compose/docker-compose.yaml @@ -1,26 +1,12 @@ version: '3' services: - postgres: - container_name: learnware-postgres - image: postgres:13.3 - environment: - - POSTGRES_PASSWORD=my-secret-pw - networks: - - learnware - ports: - - '5432:5432' - stdin_open: true - tty: true - restart: always - volumes: - - postgres_data:/var/lib/postgresql/data redis: container_name: learnware-redis image: redis networks: - learnware - ports: - - '6379:6379' + expose: + - '6379' stdin_open: true tty: true restart: always @@ -29,32 +15,60 @@ services: - redis_data:/data backend: image: lamda/bm-system-backend:0.0.1 - dockerfile: Dockerfile_backend + build: + context: . + dockerfile: Dockerfile_backend container_name: learnware-backend restart: always networks: - learnware - ports: - - '8088:8088' + expose: + - '8088' volumes: - backend_data:/backend_data - learnware_storage:/root/.learnware frontend: + build: + context: . + dockerfile: Dockerfile_frontend container_name: learnware-frontend image: lamda/bm-system-frontend:0.0.1 - dockerfile: Dockerfile_frontend stdin_open: true tty: true restart: always networks: - learnware - expose: - - '5173' + ports: + - '5173:5173' + monitor: + image: lamda/bm-system-backend:0.0.1 + build: + context: . + dockerfile: Dockerfile_backend + container_name: learnware-monitor + restart: always + networks: + - learnware + volumes: + - backend_data:/backend_data + - learnware_storage:/root/.learnware + admin-frontend: + build: + context: . + dockerfile: Dockerfile_admin + container_name: learnware-admin-frontend + image: lamda/bm-system-admin-frontend:0.0.1 + stdin_open: true + tty: true + restart: always + networks: + - learnware + ports: + - '5174:5173' networks: learnware: driver: 'bridge' volumes: learnware_storage: backend_data: - postgres_data: redis_data: \ No newline at end of file diff --git a/deploy/docker-compose/nginx_admin.conf b/deploy/docker-compose/nginx_admin.conf new file mode 100644 index 0000000..9657fdc --- /dev/null +++ b/deploy/docker-compose/nginx_admin.conf @@ -0,0 +1,53 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + gzip on; + + include /etc/nginx/conf.d/*.conf; + + client_max_body_size 50G; + + server { + listen 5173; + + location / { + root /learnware-frontend/packages/admin/dist; + index index.html; + try_files $uri $uri/ /index.html =404; + + if ($request_filename ~* ^.*?.(html|htm)$) { + add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate"; + } + } + + location /assets { + root /learnware-frontend/packages/admin/dist; + } + + location /api { + proxy_pass http://backend:8088/; + } + } +} \ No newline at end of file diff --git a/deploy/docker-compose/pip.conf b/deploy/docker-compose/pip.conf new file mode 100644 index 0000000..617ef07 --- /dev/null +++ b/deploy/docker-compose/pip.conf @@ -0,0 +1,3 @@ +[global] +index-url = https://pypi.tuna.tsinghua.edu.cn/simple +# index-url = https://mirrors.aliyun.com/pypi/simple/ \ No newline at end of file