Skip to content

Commit 392ba1e

Browse files
committed
feat: Serverless Google Cloud Platform in CLI support
1 parent 73db73f commit 392ba1e

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

packages/cubejs-cli/cubejsCli.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ const displayError = async (text, options) => {
7777

7878
const requireFromPackage = (module) => require(path.join(process.cwd(), 'node_modules', module));
7979

80-
const npmInstall = (dependencies) => executeCommand('npm', ['install', '--save'].concat(dependencies));
80+
const npmInstall = (dependencies, isDev) => executeCommand(
81+
'npm', ['install', isDev ? '--save-dev' : '--save'].concat(dependencies)
82+
);
8183

8284
const logStage = (stage) => {
8385
console.log(`- ${stage}`);
@@ -173,6 +175,11 @@ const createApp = async (projectName, options) => {
173175
await npmInstall(templateConfig.dependencies);
174176
}
175177

178+
if (templateConfig.devDependencies) {
179+
logStage('Installing template dev dependencies');
180+
await npmInstall(templateConfig.devDependencies);
181+
}
182+
176183
await event('Create App Success', { projectName, dbType: options.dbType });
177184
logStage(`${chalk.green(projectName)} app has been created 🎉`);
178185

packages/cubejs-cli/templates.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,57 @@ plugins:
107107
- serverless-express
108108
`;
109109

110+
const serverlessGoogleYml = env => `service: ${env.projectName} # NOTE: Don't put the word "google" in here
111+
112+
provider:
113+
name: google
114+
stage: dev
115+
runtime: nodejs8
116+
region: us-central1
117+
project: <YOUR_GOOGLE_PROJECT_ID_HERE>
118+
# The GCF credentials can be a little tricky to set up. Luckily we've documented this for you here:
119+
# https://serverless.com/framework/docs/providers/google/guide/credentials/
120+
#
121+
# the path to the credentials file needs to be absolute
122+
credentials: </path/to/service/account/keyfile.json>
123+
environment:
124+
CUBEJS_DB_TYPE: ${env.dbType}
125+
CUBEJS_DB_HOST: <YOUR_DB_HOST_HERE>
126+
CUBEJS_DB_NAME: <YOUR_DB_NAME_HERE>
127+
CUBEJS_DB_USER: <YOUR_DB_USER_HERE>
128+
CUBEJS_DB_PASS: <YOUR_DB_PASS_HERE>
129+
CUBEJS_DB_PORT: <YOUR_DB_PORT_HERE>
130+
CUBEJS_DB_BQ_PROJECT_ID: "\${self:provider.project}"
131+
REDIS_URL: <YOUR_REDIS_URL_HERE>
132+
CUBEJS_API_SECRET: ${env.apiSecret}
133+
CUBEJS_APP: "\${self:service.name}-\${self:provider.stage}"
134+
CUBEJS_SERVERLESS_PLATFORM: "\${self:provider.name}"
135+
136+
plugins:
137+
- serverless-google-cloudfunctions
138+
- serverless-express
139+
140+
# needs more granular excluding in production as only the serverless provider npm
141+
# package should be excluded (and not the whole node_modules directory)
142+
package:
143+
exclude:
144+
- node_modules/**
145+
- .gitignore
146+
- .git/**
147+
148+
functions:
149+
cubejs:
150+
handler: api
151+
events:
152+
- http: ANY
153+
cubejsProcess:
154+
handler: process
155+
events:
156+
- event:
157+
eventType: providers/cloud.pubsub/eventTypes/topic.publish
158+
resource: "projects/\${self:provider.project}/topics/\${self:service.name}-\${self:provider.stage}-process"
159+
`;
160+
110161
const ordersJs = `cube(\`Orders\`, {
111162
sql: \`
112163
select 1 as id, 100 as amount, 'new' status
@@ -157,3 +208,15 @@ exports.serverless = {
157208
},
158209
dependencies: ['@cubejs-backend/serverless', '@cubejs-backend/serverless-aws']
159210
};
211+
212+
213+
exports['serverless-google'] = {
214+
files: {
215+
'index.js': () => handlerJs,
216+
'serverless.yml': serverlessGoogleYml,
217+
'.env': dotEnv,
218+
'schema/Orders.js': () => ordersJs
219+
},
220+
dependencies: ['@cubejs-backend/serverless', '@cubejs-backend/serverless-google'],
221+
devDependencies: ['serverless-google-cloudfunctions']
222+
};

packages/cubejs-serverless-google/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,32 @@ Create Cube.js Serverless app:
88

99
```
1010
$ npm install -g serverless
11-
$ cubejs create -d bigquery -t serverless
11+
$ cubejs create -d bigquery -t serverless-google
1212
```
1313

14+
Update all placeholders in just created `serverless.yml`.
15+
1416
## Setup Redis
1517

16-
TBD
18+
1. [Create Redis](https://cloud.google.com/memorystore/docs/redis/quickstart-console).
19+
2. [Setup Serverless VPC Access Connector](https://cloud.google.com/functions/docs/connecting-vpc).
1720

1821
## Deploy
1922

2023
```
2124
$ serverless deploy -v
2225
```
2326

27+
As serverless-google-cloudfunctions plugin doesn't support vpc-connector you need to [set it manually](https://cloud.google.com/functions/docs/connecting-vpc#configuring) each time after deploy.
28+
2429
## Logs
2530

2631
```
2732
$ serverless logs -t -f cubejs
2833
$ serverless logs -t -f cubejsProcess
2934
```
3035

31-
[Learn more](https://github.com/statsbotco/cube.js#getting-started)
36+
[Learn more](https://cube.dev/docs)
3237

3338
### License
3439

0 commit comments

Comments
 (0)