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": "cube-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": "cube-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 CubeServer = require("@cubejs-backend/server");
const server = new CubeServer({
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:
services:
cube:
image: cubejs/cube:latest
ports:
- 4000:4000
env_file: .env
volumes:
- .:/cube/conf