Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking(baremetal): Throw an error if there is not enough available space #11638

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changesets/11638.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- breaking(baremetal): Throw an error if there is not enough available space (#11638) by @Tobbe
26 changes: 13 additions & 13 deletions packages/cli/src/commands/deploy/__tests__/baremetal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down Expand Up @@ -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
Expand All @@ -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/,
)
})

Expand Down
15 changes: 4 additions & 11 deletions packages/cli/src/commands/deploy/baremetal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const DEFAULT_SERVER_CONFIG = {
monitorCommand: 'pm2',
sides: ['api', 'web'],
keepReleases: 5,
freeSpaceRequired: 2048,
}

export const command = 'baremetal [environment]'
Expand Down Expand Up @@ -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')
}

Expand Down Expand Up @@ -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)',
)
}
},
Expand Down
Loading