Skip to content

Commit

Permalink
fix(backend): add monitor and admin in docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxiaochuan committed Dec 26, 2023
1 parent 2544e3f commit 098fa4e
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 32 deletions.
19 changes: 19 additions & 0 deletions deploy/docker-compose/Dockerfile_admin
Original file line number Diff line number Diff line change
@@ -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;"]
4 changes: 2 additions & 2 deletions deploy/docker-compose/Dockerfile_backend
Original file line number Diff line number Diff line change
Expand Up @@ -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:https://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
Expand All @@ -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/
Expand Down
14 changes: 7 additions & 7 deletions deploy/docker-compose/Dockerfile_frontend
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions deploy/docker-compose/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"redis": {
"host": "redis",
"port": 6379
}
}
60 changes: 37 additions & 23 deletions deploy/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
53 changes: 53 additions & 0 deletions deploy/docker-compose/nginx_admin.conf
Original file line number Diff line number Diff line change
@@ -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:https://backend:8088/;
}
}
}
3 changes: 3 additions & 0 deletions deploy/docker-compose/pip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
# index-url = https://mirrors.aliyun.com/pypi/simple/

0 comments on commit 098fa4e

Please sign in to comment.