Guides
Upgrading Cube
Migrating from Express to Docker

Migrating from Express to Docker

Since v0.23 (opens in a new tab), Cube CLI uses the docker template instead of express as a default for project creation, and it is the recommended route for production. To migrate you should move all Cube dependencies in package.json to devDependencies and leave dependencies that you use to configure Cube in dependencies.

For example, your existing package.json might look something like:

{
  "name": "cubejs-app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "node index.js"
  },
  "dependencies": {
    "@cubejs-backend/postgres-driver": "^0.20.0",
    "@cubejs-backend/server": "^0.20.0"
  }
}

It should become:

{
  "name": "cubejs-app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "./node_modules/.bin/cubejs-server server"
  },
  "dependencies": {},
  "devDependencies": {
    "@cubejs-backend/postgres-driver": "^0.23.6",
    "@cubejs-backend/server": "^0.23.7"
  }
}

You should also rename your index.js file to cube.js and replace the CubejsServer.create() call with export of configuration using module.exports.

For an index.js like the following:

const CubejsServer = require("@cubejs-backend/server");
 
const server = new CubejsServer({
  logger: (msg, params) => {
    console.log(`${msg}: ${JSON.stringify(params)}`);
  },
});
 
server
  .listen()
  .then(({ version, port }) => {
    console.log(`🚀 Cube API server (${version}) is listening on ${port}`);
  })
  .catch((e) => {
    console.error("Fatal error during server start: ");
    console.error(e.stack || e);
  });

It should be renamed to cube.js and its' contents should look like:

module.exports = {
  logger: (msg, params) => {
    console.log(`${msg}: ${JSON.stringify(params)}`);
  },
};

Finally, add a docker-compose.yml file alongside the cube.js configuration file:

version: "2.2"
 
services:
  cube:
    image: cubejs/cube:latest
    ports:
      - 4000:4000
    env_file: .env
    volumes:
      - .:/cube/conf