cube.js 学习 cube docker-compose 运行

cube.js 官方为我们也提供了backeng 部署的模型,为了测试方便以下是一个使用docker-compose 运行的demo

项目是一个集成gitbase 的demo,实际可以按照自己的项目修改,同时集成了redis cache,gitbase-web

环境准备

  • 项目结构
├── README.md
├── cube
│ ├── Dockerfile
│ ├── index.js
│ ├── package.json
│ └── schema
│ ├── Blobs.js
│ ├── CommitBlobs.js
│ ├── CommitFiles.js
│ ├── CommitPerMonth.js
│ ├── CommitTrees.js
│ ├── Commits.js
│ ├── Committer-Repos.js
│ ├── Files.js
│ ├── RefCommits.js
│ ├── Refs.js
│ ├── Remotes.js
│ ├── Repositories.js
│ ├── TopNCommitters.js
│ ├── TopNRepoCommit.js
│ └── TreeEntries.js
├── docker-compose-bblfsh.yaml
└── docker-compose.yaml
  • docker-compose.yaml

    项目中包含了两个,有一个包含了bblfsh ,主要说明不包含bblfsh的

version: "3"
services:
  gitbase-web:
    image: srcd/gitbase-web:latest
    environment: 
    - "GITBASEPG_DB_CONNECTION=root@tcp(gitbase:3306)/none"
    ports:
    - "8080:8080"
  redis_db:
    image: redis
    ports:
      - "6379:6379"
  cube:
    build: ./cube
    env_file: .env
    ports: 
    - "4000:4000"
    volumes:
      - ./cube/schema:/usr/src/app/schema
    command: node index.js
  gitbase:
    container_name: gitbase
    hostname: gitbase
    image: srcd/gitbase:v0.20.0-rc2
    volumes: 
    - "./git-demos:/opt/repos"
    ports:
    - "3306:3306"
  • cube 项目docker 配置

    cube 目录包含了需要的dockerfile

Dockerfile:
FROM node:10-alpine
LABEL AUTHOR="dalong"
LABEL EMAIL="1141591465@qq.com"
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4000
  • cube nodejs 项目

    nodejs 项目依赖的npm 包,以及启动入口

package.json:
{
  "name": "gitbase-demo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "./node_modules/.bin/cubejs-dev-server"
  },
  "dependencies": {
    "@cubejs-backend/mysql-driver": "^0.9.2",
    "@cubejs-backend/server": "^0.9.2"
  }
}
index.js:
const CubejsServer = require('@cubejs-backend/server');
const server = new CubejsServer();
server.listen().then(({ port }) => {
  console.log(`🚀 Cube.js server is listening on ${port}`);
});
  • cube 项目环境变量配置

    cube 基于dotenv 进行环境变量管理,使用.env 管理配置

REDIS_URL=redis://redis_db:6379/0
CUBEJS_DB_HOST=gitbase
CUBEJS_DB_NAME=gitbase
CUBEJS_DB_USER=root
CUBEJS_DB_TYPE=mysql
CUBEJS_API_SECRET=f175c412a9136d6bf6cb84bc59c027f39cc93ae35887774ac3fe091bb0717a8d53409a967a1d2014988ef344e75214d48e0cd65c8b6c9403f8d0850a5545afdd

运行&&测试

  • 预备
需要拷贝一些git 代码到git-demos 目录,可以直接clone 几个开源项目就可以了,同时对于gitbase 的schema 我已经准备好了
可以参考 https://github.com/rongfengliang/cube-gitbase-docker-compose/tree/master/cube/schema
  • 构建镜像
docker-compose build
  • 启动
docker-compose up -d
  • cube web
open http://localhost:4000

效果


说明

cube docker-compose 的运行还是比较简单,简答的配置就可以了,很方便,类似我也提供了一个postgresql 数据库的docker-compose 项目
cube-pg-docker-compose

参考资料

https://github.com/rongfengliang/cube-gitbase-docker-compose
https://github.com/src-d/gitbase
https://cube.dev/docs/deployment#docker-compose

posted on 2019-05-16 13:10  荣锋亮  阅读(688)  评论(0编辑  收藏  举报

导航