Skip to content

Commit

Permalink
Bundle plan (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarqvi authored May 5, 2024
1 parent 10e8938 commit d319040
Showing 1 changed file with 47 additions and 27 deletions.
74 changes: 47 additions & 27 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class Deploy extends Command {
config.buildCache = !(config['no-cache'] || config.build?.cache === false);

this.debug(
`Using Build Cache: ${config.buildCache ? 'Enabled' : 'Disabled'}`
`Using Build Cache: ${config.buildCache ? 'Enabled' : 'Disabled'}`,
);

config.dockerfile = config.dockerfile || config.build?.dockerfile;
Expand Down Expand Up @@ -205,7 +205,7 @@ export default class Deploy extends Command {
this.log();

const { project } = await this.got(
`v1/projects/${config.app}`
`v1/projects/${config.app}`,
).json<IProjectDetailsResponse>();

const defaultSubdomain: string =
Expand All @@ -218,7 +218,7 @@ export default class Deploy extends Command {
: ` ${`https://${config.app}${defaultSubdomain}`}`;

const { domains } = await this.got(
`v1/domains?project=${config.app}`
`v1/domains?project=${config.app}`,
).json<IGetDomainsResponse>();

if (!domains.length || project.defaultSubdomain)
Expand Down Expand Up @@ -298,6 +298,26 @@ Please open up https://console.liara.ir/apps and unfreeze the app.`;
return this.error(message);
}

if (
error.response &&
error.response.statusCode === 428 &&
error.data.code === 'max_deployment_count_in_day'
) {
return this.error(
`You have reached the maximum number of deployments for today. Please try again tomorrow.`,
);
}

if (
error.response &&
error.response.statusCode === 428 &&
error.data.code === 'germany_builder_not_allowed'
) {
return this.error(
`You are not allowed to deploy in Germany builder region. Please try another region.`,
);
}

if (
error.response &&
error.response.statusCode >= 400 &&
Expand All @@ -316,8 +336,8 @@ Please login via 'liara login' command.
If you are using API token for authentication, please consider updating your API token.
You may also want to switch to another region. Your current region is: ${chalk.cyan(
config.region!
)}`).render()
config.region!,
)}`).render(),
);
process.exit(2);
}
Expand All @@ -326,10 +346,11 @@ You may also want to switch to another region. Your current region is: ${chalk.c
return this.error(error.message);
}

if (error instanceof ReachedMaxSourceSizeError) {
this.error(
`Source is too large. ${chalk.yellowBright('(max: 256MB)')}`
);
if (
error instanceof ReachedMaxSourceSizeError ||
error.response.statusCode === 413
) {
this.error(error.message);
}

this.log(chalk.gray(this.config.userAgent));
Expand Down Expand Up @@ -391,8 +412,8 @@ Additionally, you can also retry the build with the debug flag:
this.logKeyValue(
'Compressed size',
`${bytes(sourceSize)} ${chalk.cyanBright(
'(use .gitignore to reduce the size)'
)}`
'(use .gitignore to reduce the size)',
)}`,
);

if (sourceSize > MAX_SOURCE_SIZE) {
Expand All @@ -409,7 +430,7 @@ Additionally, you can also retry the build with the debug flag:
const sourceID = await this.upload(
config.app as string,
sourcePath,
sourceSize
sourceSize,
);

this.debug(`sourceID: ${sourceID}`);
Expand All @@ -436,7 +457,7 @@ Additionally, you can also retry the build with the debug flag:
}

this.spinner.start(
`Waiting for the build, ${release.queue} people(s) ahead...`
`Waiting for the build, ${release.queue} people(s) ahead...`,
);

await new Promise((resolve) => setTimeout(resolve, 3000));
Expand Down Expand Up @@ -537,7 +558,7 @@ Additionally, you can also retry the build with the debug flag:
// node, netcore, php
this.logKeyValue(
`${config.platform} version`,
body.platformConfig.version
body.platformConfig.version,
);
return body;
}
Expand All @@ -556,7 +577,7 @@ Additionally, you can also retry the build with the debug flag:
platformVersion = await getPlatformVersion(
config.platform,
config.path,
this.debug
this.debug,
);
if (platformVersion) {
this.logKeyValue('Auto-detected Python version', platformVersion);
Expand All @@ -568,7 +589,7 @@ Additionally, you can also retry the build with the debug flag:
platformVersion = await getPlatformVersion(
config.platform,
config.path,
this.debug
this.debug,
);
if (platformVersion) {
this.logKeyValue('Auto-detected php version', platformVersion);
Expand All @@ -584,20 +605,20 @@ Additionally, you can also retry the build with the debug flag:
platformVersion = await getPlatformVersion(
config.platform,
config.path,
this.debug
this.debug,
);
if (platformVersion) {
this.logKeyValue(
`Auto-detected ${config.platform} version`,
platformVersion
platformVersion,
);
body.platformConfig.version = platformVersion;
}
break;

default:
this.debug(
`Can not auto-detect version for ${config.platform} platform`
`Can not auto-detect version for ${config.platform} platform`,
);
break;
}
Expand Down Expand Up @@ -625,7 +646,7 @@ Additionally, you can also retry the build with the debug flag:
this.spinner.fail();
if (release.failReason) {
return reject(
new DeployException(this.parseFailReason(release.failReason))
new DeployException(this.parseFailReason(release.failReason)),
);
}

Expand Down Expand Up @@ -679,7 +700,7 @@ Additionally, you can also retry the build with the debug flag:
!Array.isArray(config.healthCheck.command)
) {
this.error(
'`command` field in healthCheck must be either an array or a string.'
'`command` field in healthCheck must be either an array or a string.',
);
}

Expand All @@ -692,14 +713,13 @@ Additionally, you can also retry the build with the debug flag:
this.spinner.start('Loading...\n');

try {
const { projects } = await this.got(
'v1/projects'
).json<IGetProjectsResponse>();
const { projects } =
await this.got('v1/projects').json<IGetProjectsResponse>();
this.spinner.stop();

if (!projects.length) {
this.warn(
'Please go to https://console.liara.ir/apps and create an app, first.'
'Please go to https://console.liara.ir/apps and create an app, first.',
);
this.exit(1);
}
Expand Down Expand Up @@ -778,7 +798,7 @@ Additionally, you can also retry the build with the debug flag:
validatePlatform(platform: string, projectPath: string): void {
if (platform === 'node') {
const packageJSON = fs.readJSONSync(
path.join(projectPath, 'package.json')
path.join(projectPath, 'package.json'),
);

if (!packageJSON.scripts || !packageJSON.scripts.start) {
Expand All @@ -791,7 +811,7 @@ You must add a 'start' command to your package.json scripts.`);
async upload(
project: string,
sourcePath: string,
sourceSize: number
sourceSize: number,
): Promise<string> {
const bar = new ProgressBar('Uploading [:bar] :percent :etas', {
total: sourceSize,
Expand Down

0 comments on commit d319040

Please sign in to comment.