Skip to content

Commit c01ec30

Browse files
committed
feat: add optioal CLI option for setting a temporary file path
1 parent d4dae15 commit c01ec30

File tree

9 files changed

+45
-1
lines changed

9 files changed

+45
-1
lines changed

apps/appcontainer-node/packages/generic/src/__tests__/lib/setupEnv.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export async function setupAppContainer(partialAppContainerConfig: Partial<AppCo
4646
networkIds: [],
4747
resourceId: '',
4848
windowsDriveLetters: [],
49+
temporaryFolderPath: '',
4950
},
5051
workforceURL: null,
5152
},

apps/appcontainer-node/packages/generic/src/appContainer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ export class AppContainer {
300300
this.config.appContainer.worker.windowsDriveLetters
301301
? `--windowsDriveLetters=${this.config.appContainer.worker.windowsDriveLetters?.join(';')}`
302302
: '',
303+
this.config.appContainer.worker.temporaryFolderPath
304+
? `--temporaryFolderPath=${this.config.appContainer.worker.temporaryFolderPath}`
305+
: '',
303306
this.config.appContainer.worker.costMultiplier
304307
? `--costMultiplier=${this.config.appContainer.worker.costMultiplier}`
305308
: '',

shared/packages/api/src/appContainer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface AppContainerConfig {
2222
resourceId: string
2323
networkIds: string[]
2424
windowsDriveLetters: WorkerAgentConfig['windowsDriveLetters']
25+
temporaryFolderPath: WorkerAgentConfig['temporaryFolderPath']
2526
costMultiplier: number
2627
considerCPULoad: number | null
2728
failurePeriodLimit: number

shared/packages/api/src/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ const workerArguments = defineArguments({
143143
default: process.env.WORKER_WINDOWS_DRIVE_LETTERS || 'X;Y;Z',
144144
describe: 'Which Windows Drive letters can be used to map shares. ("X;Y;Z") ',
145145
},
146+
temporaryFolderPath: {
147+
type: 'string',
148+
default: process.env.WORKER_TEMPORARY_FOLDER_PATH || '',
149+
describe: 'A temporary, local file path where the worker can store temporary artifacts',
150+
},
146151
resourceId: {
147152
type: 'string',
148153
default: process.env.WORKER_NETWORK_ID || 'default',
@@ -240,6 +245,11 @@ const appContainerArguments = defineArguments({
240245
default: process.env.WORKER_WINDOWS_DRIVE_LETTERS || 'X;Y;Z',
241246
describe: 'Which Windows Drive letters can be used to map shares. ("X;Y;Z") ',
242247
},
248+
temporaryFolderPath: {
249+
type: 'string',
250+
default: process.env.WORKER_TEMPORARY_FOLDER_PATH || '',
251+
describe: 'A temporary, local file path where the worker can store temporary artifacts',
252+
},
243253
costMultiplier: {
244254
type: 'number',
245255
default: process.env.WORKER_COST_MULTIPLIER || 1,
@@ -470,6 +480,7 @@ export async function getWorkerConfig(): Promise<WorkerConfig> {
470480
resourceId: argv.resourceId,
471481
networkIds: argv.networkIds ? argv.networkIds.split(';') : [],
472482
windowsDriveLetters: argv.windowsDriveLetters ? argv.windowsDriveLetters.split(';') : [],
483+
temporaryFolderPath: argv.temporaryFolderPath ? argv.temporaryFolderPath : undefined,
473484
costMultiplier:
474485
(typeof argv.costMultiplier === 'string' ? parseFloat(argv.costMultiplier) : argv.costMultiplier) || 1,
475486
considerCPULoad:
@@ -514,6 +525,7 @@ export async function getAppContainerConfig(): Promise<AppContainerProcessConfig
514525
resourceId: argv.resourceId,
515526
networkIds: argv.networkIds ? argv.networkIds.split(';') : [],
516527
windowsDriveLetters: argv.windowsDriveLetters ? argv.windowsDriveLetters.split(';') : [],
528+
temporaryFolderPath: argv.temporaryFolderPath ? argv.temporaryFolderPath : undefined,
517529
costMultiplier:
518530
(typeof argv.costMultiplier === 'string' ? parseFloat(argv.costMultiplier) : argv.costMultiplier) ||
519531
1,

shared/packages/api/src/worker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export interface WorkerAgentConfig {
7070
* Example: ['X', 'Y', 'Z']
7171
*/
7272
windowsDriveLetters?: string[]
73+
74+
/** A temporary, local file path where the worker can store temporary artifacts */
75+
temporaryFolderPath?: string
7376
}
7477
export type ReturnTypeDoYouSupportPackageContainer =
7578
| {

shared/packages/worker/src/worker/accessorHandlers/__tests__/lib.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class PassiveTestWorker extends BaseWorker {
1010
workerId: protectString('test'),
1111
sourcePackageStabilityThreshold: 0,
1212
windowsDriveLetters: ['X', 'Y', 'Z'],
13+
temporaryFolderPath: undefined,
1314
},
1415
location: {
1516
// localComputerId?: string
@@ -62,4 +63,7 @@ export class PassiveTestWorker extends BaseWorker {
6263
async setupPackageContainerMonitors(): Promise<any> {
6364
throw new Error('Method not implemented.')
6465
}
66+
getTemporaryFolderPath(): string {
67+
throw new Error('Method not implemented.')
68+
}
6569
}

shared/packages/worker/src/worker/worker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ export abstract class BaseWorker {
146146
}
147147
}
148148

149+
/** Returns a local file path to a temporary folder */
150+
abstract getTemporaryFolderPath(localPath?: string): string
151+
149152
private _accessorTemporaryCache: {
150153
[accessorType: string]: {
151154
[key: string]: {

shared/packages/worker/src/worker/workers/genericWorker/genericWorker.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,18 @@ export class GenericWorker extends BaseWorker {
151151
): Promise<SetupPackageContainerMonitorsResult> {
152152
return PackageContainerExpHandler.setupPackageContainerMonitors(packageContainer, this)
153153
}
154+
155+
private hasEnsuredTemporaryFolderPath = new Set<string>()
156+
getTemporaryFolderPath(localPath = ''): string {
157+
const tempBasePath =
158+
this.agentAPI.config.temporaryFolderPath ||
159+
(process.platform === 'win32' ? 'C:\\temp\\package-manager' : '/tmp/package-manager')
160+
161+
const tempPath = path.join(tempBasePath, localPath)
162+
if (!this.hasEnsuredTemporaryFolderPath.has(tempPath)) {
163+
this.hasEnsuredTemporaryFolderPath.add(tempPath)
164+
fs.mkdirSync(tempPath, { recursive: true })
165+
}
166+
return tempPath
167+
}
154168
}

tests/internal-tests/src/__tests__/lib/setupEnv.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const defaultTestConfig: SingleAppConfig = {
8080
resourceId: '',
8181
networkIds: [],
8282
windowsDriveLetters: ['X', 'Y', 'Z'],
83+
temporaryFolderPath: undefined,
8384
sourcePackageStabilityThreshold: 0, // Disabling this to speed up the tests
8485
costMultiplier: 1,
8586
considerCPULoad: null,
@@ -104,6 +105,7 @@ export const defaultTestConfig: SingleAppConfig = {
104105
resourceId: '',
105106
networkIds: [],
106107
windowsDriveLetters: ['X', 'Y', 'Z'],
108+
temporaryFolderPath: undefined,
107109
costMultiplier: 1,
108110
considerCPULoad: null,
109111
failurePeriod: 0,
@@ -274,7 +276,8 @@ export async function prepareTestEnvironment(debugLogging: boolean): Promise<Tes
274276
packageId: ExpectedPackageId,
275277
packageStatus: Omit<ExpectedPackageStatusAPI.PackageContainerPackageStatus, 'statusChanged'> | null
276278
) => {
277-
if (debugLogging) console.log('reportPackageContainerPackageStatus', containerId, packageId, packageStatus)
279+
if (debugLogging)
280+
console.log('reportPackageContainerPackageStatus', containerId, packageId, packageStatus)
278281

279282
let container = containerStatuses[containerId]
280283
if (!container) {

0 commit comments

Comments
 (0)