Skip to content

Commit

Permalink
Instead of fs copying, just change key on AWS upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Dec 11, 2023
1 parent 30616d7 commit ead035d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
18 changes: 9 additions & 9 deletions src/bin/vip-deploy-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
WithId,
UploadArguments,
} from '../lib/client-file-uploader';
import { gates, renameFile } from '../lib/manual-deploy/manual-deploy';
import { gates } from '../lib/manual-deploy/manual-deploy';
import { trackEventWithEnv } from '../lib/tracker';

const appQuery = `
Expand Down Expand Up @@ -121,6 +121,14 @@ export async function deployAppCmd( arg: string[] = [], opts: Record< string, un

await track( 'deploy_app_command_execute' );

// Upload file as different name to avoid overwriting existing same named files
const datePrefix = new Date()
.toISOString()
// eslint-disable-next-line no-useless-escape
.replace( /[\-T:\.Z]/g, '' )
.slice( 0, 14 );
fileMeta.basename = `${ datePrefix }-${ fileMeta.basename }`;

const deployMessage = ( opts.message as string ) ?? '';
const forceDeploy = opts.force;

Expand Down Expand Up @@ -179,14 +187,6 @@ Processing the file for deployment to your environment...
progressTracker.setUploadPercentage( percentage );
};

try {
fileMeta = await renameFile( fileMeta );
} catch ( err ) {
throw new Error(
`Unable to copy file to temporary working directory: ${ ( err as Error ).message }`
);
}

const appInput = { id: appId } as WithId;
const envInput = { id: envId } as WithId;
const uploadParams: UploadArguments = {
Expand Down
23 changes: 0 additions & 23 deletions src/lib/manual-deploy/manual-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,3 @@ export async function gates( app: App, env: AppEnvironment, fileMeta: FileMeta )
);
}
}

/**
* Rename file so it doesn't get overwritten.
* @param {FileMeta} fileMeta - The metadata of the file to be renamed.
* @returns {FileMeta} The updated file metadata after renaming.
*/
export async function renameFile( fileMeta: FileMeta ) {
const tmpDir = await mkdtemp( path.join( os.tmpdir(), 'vip-manual-deploys' ) );

const datePrefix = new Date()
.toISOString()
// eslint-disable-next-line no-useless-escape
.replace( /[\-T:\.Z]/g, '' )
.slice( 0, 14 );
const newFileBasename = `${ datePrefix }-${ fileMeta.basename }`;
const newFileName = `${ tmpDir }/${ newFileBasename }`;

fs.copyFileSync( fileMeta.fileName, newFileName );
fileMeta.fileName = newFileName;
fileMeta.basename = newFileBasename;

return fileMeta;
}

0 comments on commit ead035d

Please sign in to comment.