Hub
进阶
从源码构建

从源码构建

系统要求

  • Git
  • Docker
  • Docker Compose

构建 Docker 镜像

克隆仓库

git clone https://github.com/ZingerLittleBee/server_bee-backend.git

修改配置文件

切换到工作目录

cd server_bee-backend/docker/

解开如下注释

# build:
    #   context: ../
    #   dockerfile: docker/Dockerfile.hub

修改之后完整 docker-compose 如下:

docker-compose.yml
version: '3'
 
services:
  caddy:
    image: caddy:2-alpine
    container_name: serverbee-caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
  mongo:
    image: mongo
    container_name: serverbee-mongo
    restart: always
    environment:
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
  hub:
    build:
      context: ../
      dockerfile: docker/Dockerfile.hub
    image: zingerbee/serverhub:latest
    container_name: serverhub
    restart: unless-stopped
    # volumes:
    #   - ../packages/db/prisma/serverhub.db:/app/serverhub.db
    environment:
      - DATABASE_URL=${DATABASE_URL}
      - MONGODB_URI=${MONGODB_URI}
      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
      - NEXTAUTH_URL=${NEXTAUTH_URL}
      - SERVER_JWT_SECRET=${SERVER_JWT_SECRET}
    depends_on:
      - mongo
  interactor:
    build:
      context: ../
      dockerfile: docker/Dockerfile.interactor
    image: zingerbee/serverbee-interactor:latest
    container_name: serverbee-interactor
    restart: unless-stopped
    environment:
      - RUST_LOG=${RUST_LOG}
      - MONGODB_URI=${MONGODB_URI}
    depends_on:
      - mongo
  recorder:
    build:
      context: ../
      dockerfile: docker/Dockerfile.recorder
    image: zingerbee/serverbee-recorder:latest
    container_name: serverbee-recorder
    restart: unless-stopped
    environment:
      - RUST_LOG=${RUST_LOG}
      - SERVER_JWT_SECRET=${SERVER_JWT_SECRET}
      - MONGODB_URI=${MONGODB_URI}
    depends_on:
      - mongo
  web:
    build:
      context: ../
      dockerfile: docker/Dockerfile.web
    image: zingerbee/serverbee-web:latest
    container_name: serverbee-web
    restart: unless-stopped
    command: [ "-r", "-u", "$SERVER_URL", "-s", "$SERVER_TOKEN" ]
    ports:
      - "9527:9527"
    environment:
      - SERVER_URL=${SERVER_URL}
      - SERVER_TOKEN=${SERVER_TOKEN}
    depends_on:
      - recorder

构建镜像

docker-compose up -d