Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
RusovDmitriy committed Jan 13, 2025
1 parent f17fdac commit eb67c77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
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: replaceEnv ? 'true' : 'false' });
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
17 changes: 13 additions & 4 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 @@ -58,6 +66,7 @@ export function configureDeployCommand(program: CommanderStatic) {
.command('deploy')
.description('Deploy project to Cube Cloud')
.option('--upload-env', 'Upload .env file to CubeCloud')
.option('--replace-env', 'Upload .env file to CubeCloud, allowing to replace existing variables')
.option('--token <token>', 'Add auth token to CubeCloud')
.option('--directory [path]', 'Specify path to conf directory', './')
.action(
Expand Down

0 comments on commit eb67c77

Please sign in to comment.