Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/cubejs-backend-cloud/src/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fetch, { RequestInit } from 'node-fetch';
import FormData from 'form-data';
import path from 'path';
import { ReadStream } from 'fs';
import { DotenvParseOutput } from '@cubejs-backend/dotenv';

export type AuthObject = {
auth: string,
Expand Down Expand Up @@ -145,9 +146,10 @@ export class CubeCloudClient {
});
}

public setEnvVars({ envVariables, auth }: { envVariables: any, auth?: AuthObject }) {
public setEnvVars({ envVariables, auth, replaceEnv }: { envVariables: DotenvParseOutput, auth?: AuthObject, replaceEnv?: boolean }) {
const params = new URLSearchParams({ replaceEnv: Boolean(replaceEnv).toString() });
return this.request({
url: (deploymentId) => `build/deploy/${deploymentId}/set-env`,
url: (deploymentId) => `build/deploy/${deploymentId}/set-env?${params.toString()}`,
method: 'POST',
body: JSON.stringify({ envVariables: JSON.stringify(envVariables) }),
headers: {
Expand Down
9 changes: 6 additions & 3 deletions packages/cubejs-backend-cloud/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface DeployResponse {
export class DeployController {
public constructor(
protected readonly cubeCloudClient: CubeCloudClient,
protected readonly envVariables: DotenvParseOutput = {},
protected readonly envs: { envVariables?: DotenvParseOutput, replaceEnv?: boolean } = {},
protected readonly hooks: DeployHooks = {}
) {
}
Expand All @@ -92,8 +92,11 @@ export class DeployController {
const upstreamHashes = await this.cubeCloudClient.getUpstreamHashes();
const { transaction, deploymentName } = await this.cubeCloudClient.startUpload();

if (Object.keys(this.envVariables).length) {
await this.cubeCloudClient.setEnvVars({ envVariables: this.envVariables });
if (this.envs.envVariables) {
const { envVariables, replaceEnv } = this.envs;
if (Object.keys(this.envs.envVariables).length) {
await this.cubeCloudClient.setEnvVars({ envVariables, replaceEnv });
}
}

const files = Object.keys(fileHashes);
Expand Down
19 changes: 14 additions & 5 deletions packages/cubejs-cli/src/command/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import fs from 'fs-extra';
import path from 'path';
import cliProgress from 'cli-progress';
import { CommanderStatic } from 'commander';
import { CubeCloudClient, DeployController } from '@cubejs-backend/cloud';
import { AuthObject, CubeCloudClient, DeployController } from '@cubejs-backend/cloud';
import { ConfigCli } from '../config';

import { logStage, displayError, event } from '../utils';

const deploy = async ({ directory, auth, uploadEnv, token }: any) => {
type DeployOptions = {
directory: string,
auth: AuthObject,
uploadEnv: boolean,
replaceEnv: boolean,
token: string
};

const deploy = async ({ directory, auth, uploadEnv, replaceEnv, token }: DeployOptions) => {
if (!(await fs.pathExists(path.join(process.cwd(), 'node_modules', '@cubejs-backend/server-core')))) {
await displayError(
'@cubejs-backend/server-core dependency not found. Please run deploy command from project root directory and ensure npm install has been run.'
Expand All @@ -28,10 +36,10 @@ const deploy = async ({ directory, auth, uploadEnv, token }: any) => {
hideCursor: true
});

const envVariables = uploadEnv ? await config.envFile(`${directory}/.env`) : {};
const envVariables = uploadEnv || replaceEnv ? await config.envFile(`${directory}/.env`) : {};

const cubeCloudClient = new CubeCloudClient(auth || (await config.deployAuthForCurrentDir()));
const deployController = new DeployController(cubeCloudClient, envVariables, {
const deployController = new DeployController(cubeCloudClient, { envVariables, replaceEnv }, {
onStart: async (deploymentName, files) => {
await logStage(`Deploying ${deploymentName}...`, 'Cube Cloud CLI Deploy');
bar.start(files.length, 0, {
Expand All @@ -57,7 +65,8 @@ export function configureDeployCommand(program: CommanderStatic) {
program
.command('deploy')
.description('Deploy project to Cube Cloud')
.option('--upload-env', 'Upload .env file to CubeCloud')
.option('--upload-env', 'Use .env file to populate environment variables in Cube Cloud. Only set them once during the very first upload for this deployment')
.option('--replace-env', 'Use .env file to populate environment variables in Cube Cloud. Replace them with new ones during every upload for this deployment')
.option('--token <token>', 'Add auth token to CubeCloud')
.option('--directory [path]', 'Specify path to conf directory', './')
.action(
Expand Down
Loading