Skip to content

Commit

Permalink
Language-aware Registration (#566)
Browse files Browse the repository at this point in the history
Python is coming!
  • Loading branch information
kraftp authored Aug 2, 2024
1 parent 887a48a commit a4975f2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
29 changes: 23 additions & 6 deletions packages/dbos-cloud/applications/deploy-app-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
dbosEnvPath,
CloudAPIErrorResponse,
CLILogger,
retrieveApplicationLanguage,
AppLanguages,
} from "../cloudutils.js";
import path from "path";
import { Application } from "./types.js";
Expand Down Expand Up @@ -91,13 +93,28 @@ export async function deployAppCode(
}
logger.debug(` ... app name is ${appName}.`);

// Verify lock file exists
logger.debug("Checking for package-lock.json...");
const packageLockJsonExists = existsSync(path.join(process.cwd(), "package-lock.json"));
logger.debug(` ... package-lock.json found: ${packageLockJsonExists}`);
const appLanguage = retrieveApplicationLanguage();

if (!packageLockJsonExists) {
logger.error("No package-lock.json found. Please run 'npm install' before deploying.");
if (appLanguage === AppLanguages.Node as string) {
logger.debug("Checking for package-lock.json...");
const packageLockJsonExists = existsSync(path.join(process.cwd(), "package-lock.json"));
logger.debug(` ... package-lock.json found: ${packageLockJsonExists}`);

if (!packageLockJsonExists) {
logger.error("No package-lock.json found. Please run 'npm install' before deploying.");
return 1;
}
} else if (appLanguage === AppLanguages.Python as string) {
logger.debug("Checking for requirements.txt...");
const requirementsTxtExists = existsSync(path.join(process.cwd(), "requirements.txt"));
logger.debug(` ... requirements.txt found: ${requirementsTxtExists}`);

if (!requirementsTxtExists) {
logger.error("No requirements.txt found. Please create one before deploying.");
return 1;
}
} else {
logger.error(`dbos-config.yaml contains invalid language ${appLanguage}`)
return 1;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/dbos-cloud/applications/register-app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosError } from "axios";
import { handleAPIErrors, getCloudCredentials, getLogger, isCloudAPIErrorResponse, retrieveApplicationName, CloudAPIErrorResponse } from "../cloudutils.js";
import { handleAPIErrors, getCloudCredentials, getLogger, isCloudAPIErrorResponse, retrieveApplicationName, CloudAPIErrorResponse, retrieveApplicationLanguage } from "../cloudutils.js";
import chalk from "chalk";

export async function registerApp(dbname: string, host: string, appName?: string): Promise<number> {
Expand All @@ -11,14 +11,16 @@ export async function registerApp(dbname: string, host: string, appName?: string
if (!appName) {
return 1;
}
logger.info(`Registering application: ${appName}`);
const appLanguage = retrieveApplicationLanguage();

try {
logger.info(`Registering application: ${appName}`);
const register = await axios.put(
`https://${host}/v1alpha1/${userCredentials.organization}/applications`,
{
name: appName,
database: dbname,
language: appLanguage,
},
{
headers: {
Expand Down
10 changes: 10 additions & 0 deletions packages/dbos-cloud/cloudutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface UserProfile {
SubscriptionPlan: string;
}

export enum AppLanguages {
Node = "node",
Python = "python",
}

export const dbosConfigFilePath = "dbos-config.yaml";
export const DBOSCloudHost = process.env.DBOS_DOMAIN || "cloud.dbos.dev";
export const dbosEnvPath = ".dbos";
Expand All @@ -45,6 +50,11 @@ export function retrieveApplicationName(logger: Logger, silent: boolean = false)
return appName;
}

export function retrieveApplicationLanguage() {
const configFile = loadConfigFile(dbosConfigFilePath);
return configFile.language || AppLanguages.Node;
}

export type CLILogger = ReturnType<typeof createLogger>;
let curLogger: Logger | undefined = undefined;
export function getLogger(verbose?: boolean): CLILogger {
Expand Down

0 comments on commit a4975f2

Please sign in to comment.