Skip to content

Commit

Permalink
Deploy Old Versions (#404)
Browse files Browse the repository at this point in the history
Initial support for restoring old application versions. Redeploys a
previous version with a specified version number. Directly deploys the
original code of that version, so make sure your database schema is what
that version expects!
  • Loading branch information
kraftp authored Apr 26, 2024
1 parent fe0d063 commit 792594f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 11 additions & 7 deletions packages/dbos-cloud/applications/deploy-app-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function createZipData(logger: CLILogger): Promise<string> {
return buffer.toString('base64');
}

export async function deployAppCode(host: string, rollback: boolean, verbose: boolean): Promise<number> {
export async function deployAppCode(host: string, rollback: boolean, previousVersion: string | null, verbose: boolean): Promise<number> {
const logger = getLogger(verbose);
logger.debug("Getting cloud credentials...");
const userCredentials = await getCloudCredentials();
Expand All @@ -79,9 +79,15 @@ export async function deployAppCode(host: string, rollback: boolean, verbose: bo
logger.debug(" ... package-lock.json exists.");

try {
logger.debug("Creating application zip ...");
const zipData = await createZipData(logger);
logger.debug(" ... application zipped.");
const body: {application_archive?: string, previous_version?: string} = {}
if (previousVersion === null) {
logger.debug("Creating application zip ...");
body.application_archive = await createZipData(logger);
logger.debug(" ... application zipped.");
} else {
logger.debug(`Restoring previous version ${previousVersion}`);
body.previous_version = previousVersion
}

// Submit the deploy request
let url = '';
Expand All @@ -94,9 +100,7 @@ export async function deployAppCode(host: string, rollback: boolean, verbose: bo
logger.info(`Submitting deploy request for ${appName}`)
const response = await axios.post(
url,
{
application_archive: zipData,
},
body,
{
headers: {
"Content-Type": "application/json",
Expand Down
7 changes: 4 additions & 3 deletions packages/dbos-cloud/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ applicationCommands
.command('deploy')
.description('Deploy this application to the cloud and run associated database migration commands')
.option('--verbose', 'Verbose log of deployment step')
.action(async (options: {verbose?: boolean}) => {
const exitCode = await deployAppCode(DBOSCloudHost, false, options.verbose ?? false);
.option('-p, --previous-version <string>', 'Specify a previous version to restore')
.action(async (options: {verbose?: boolean, previousVersion?: string}) => {
const exitCode = await deployAppCode(DBOSCloudHost, false, options.previousVersion ?? null, options.verbose ?? false);
process.exit(exitCode);
});

applicationCommands
.command('rollback')
.description('Deploy this application to the cloud and run associated database rollback commands')
.action(async () => {
const exitCode = await deployAppCode(DBOSCloudHost, true, false);
const exitCode = await deployAppCode(DBOSCloudHost, true, null, false);
process.exit(exitCode);
});

Expand Down

0 comments on commit 792594f

Please sign in to comment.