From fc6cefd1715d1eb318831c055dce26fbc759b8ef Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Wed, 25 Sep 2024 14:33:00 +0200 Subject: [PATCH] breaking(baremetal): Throw an error if there is not enough available space --- .../deploy/__tests__/baremetal.test.js | 26 +++++++++---------- packages/cli/src/commands/deploy/baremetal.js | 15 +++-------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/cli/src/commands/deploy/__tests__/baremetal.test.js b/packages/cli/src/commands/deploy/__tests__/baremetal.test.js index deb0f957892b..5d6e3ba7ec05 100644 --- a/packages/cli/src/commands/deploy/__tests__/baremetal.test.js +++ b/packages/cli/src/commands/deploy/__tests__/baremetal.test.js @@ -267,9 +267,9 @@ describe('serverConfigWithDefaults', () => { expect(config.branch).toEqual('moon') }) - it('does not provide default freeSpaceRequired', () => { + it('provides default freeSpaceRequired', () => { const config = baremetal.serverConfigWithDefaults({}, {}) - expect(config.freeSpaceRequired).toBeUndefined() + expect(config.freeSpaceRequired).toEqual(2048) }) }) @@ -688,9 +688,9 @@ describe('deployTasks', () => { expect(tasks[0].skip()).toBeTruthy() }) - it('warns if there is not enough available space on the server and freeSpaceRequired is not configured', async () => { + it('throws an error if there is not enough available space on the server and freeSpaceRequired is not configured', () => { const ssh = { - exec: () => ({ stdout: 'df:1875' }), + exec: () => ({ stdout: 'df:1875893' }), } const { freeSpaceRequired: _, ...serverConfig } = defaultServerConfig @@ -702,29 +702,29 @@ describe('deployTasks', () => { {}, // lifecycle ) - await tasks[0].task({}, mockTask) - - expect(mockTask.skip).toHaveBeenCalledWith( - expect.stringContaining( - 'Warning: Your server is running low on disk space.', - ), + expect(() => tasks[0].task({}, {})).rejects.toThrowError( + /Not enough disk space\. You need at least 2048MB free space to continue\. \(Currently 1832MB available\)/, ) }) it('throws an error if there is less available space on the server than freeSpaceRequired', () => { const ssh = { - exec: () => ({ stdout: 'df:1875' }), + exec: () => ({ stdout: 'df:3875893' }), } const tasks = baremetal.deployTasks( defaultYargs, ssh, - { ...defaultServerConfig, sides: ['api', 'web'] }, + { + ...defaultServerConfig, + sides: ['api', 'web'], + freeSpaceRequired: 4096, + }, {}, // lifecycle ) expect(() => tasks[0].task({}, {})).rejects.toThrowError( - /Not enough disk space/, + /Not enough disk space\. You need at least 4096MB free space to continue/, ) }) diff --git a/packages/cli/src/commands/deploy/baremetal.js b/packages/cli/src/commands/deploy/baremetal.js index c26629244657..a816a923e041 100644 --- a/packages/cli/src/commands/deploy/baremetal.js +++ b/packages/cli/src/commands/deploy/baremetal.js @@ -26,6 +26,7 @@ export const DEFAULT_SERVER_CONFIG = { monitorCommand: 'pm2', sides: ['api', 'web'], keepReleases: 5, + freeSpaceRequired: 2048, } export const command = 'baremetal [environment]' @@ -172,7 +173,7 @@ export const verifyServerConfig = (config) => { throwMissingConfig('repo') } - if (config.freeSpaceRequired && !/^\d+$/.test(config.freeSpaceRequired)) { + if (!/^\d+$/.test(config.freeSpaceRequired)) { throw new Error('"freeSpaceRequired" must be an integer >= 0') } @@ -415,18 +416,10 @@ export const deployTasks = (yargs, ssh, serverConfig, serverLifecycle) => { ) if (dfMb < freeSpaceRequired) { - if (typeof serverConfig.freeSpaceRequired === 'undefined') { - return task.skip( - c.warning( - 'Warning: Your server is running low on disk space. (' + - `${Math.round(dfMb)}MB available)`, - ), - ) - } - throw new Error( `Not enough disk space. You need at least ${freeSpaceRequired}` + - 'MB free space to continue.', + `MB free space to continue. (Currently ${Math.round(dfMb)}MB ` + + 'available)', ) } },