Skip to content

Commit

Permalink
feat(baremetal): Check available disk space (#11469)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored and Josh-Walker-GM committed Oct 8, 2024
1 parent 44a28fc commit 1b99c38
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 66 deletions.
11 changes: 11 additions & 0 deletions .changesets/11469.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- feat(baremetal): Check available disk space (#11469) by @Tobbe

Adds an early step to the `yarn rw deploy baremetal` command that checks to
make sure there is enough free disk space on the server before continuing.

By default it will make sure there is at least 2048 MB (2 GB) of free disk space
but this can be changed by setting the new `deploy.toml` option
`freeSpaceRequired` to however many MB you want.

You can skip this step by passing `--no-df` to the `deploy baremetal` command or
setting `freeSpaceRequired` to `0`.
41 changes: 22 additions & 19 deletions docs/docs/deploy/baremetal.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ If you're new to connecting to remote servers, check out the [Intro to Servers](

The Baremetal deploy runs several commands in sequence. These can be customized, to an extent, and some of them skipped completely:

1. `git clone --depth=1` to retrieve the latest code
2. Symlink the latest deploy `.env` to the shared `.env` in the app dir
3. `yarn install` - installs dependencies
4. Runs prisma DB migrations
5. Generate Prisma client libs
6. Runs [data migrations](/docs/data-migrations)
7. Builds the web and/or api sides
8. Symlink the latest deploy dir to `current` in the app dir
9. Restart the serving process(es)
10. Remove older deploy directories
1. `df` to make sure there is enough free disk space on the server
2. `git clone --depth=1` to retrieve the latest code
3. Symlink the latest deploy `.env` to the shared `.env` in the app dir
4. `yarn install` - installs dependencies
5. Runs prisma DB migrations
6. Generate Prisma client libs
7. Runs [data migrations](/docs/data-migrations)
8. Builds the web and/or api sides
9. Symlink the latest deploy dir to `current` in the app dir
10. Restart the serving process(es)
11. Remove older deploy directories

### First Run Lifecycle

If the `--first-run` flag is specified then step 6 above will execute the following commands instead:
If the `--first-run` flag is specified then step 7 above will execute the following commands instead:

- `pm2 start [service]` - starts the serving process(es)
- `pm2 save` - saves the running services to the deploy users config file for future startup. See [Starting on Reboot](#starting-on-reboot) for further information
Expand Down Expand Up @@ -173,6 +174,7 @@ This lists a single server, in the `production` environment, providing the hostn
- `repo` - The path to the git repo to clone
- `branch` - [optional] The branch to deploy (defaults to `main`)
- `keepReleases` - [optional] The number of previous releases to keep on the server, including the one currently being served (defaults to 5)
- `freeSpaceRequired` - [optional] The amount of free space required on the server in MB (defaults to 2048 MB). You can set this to `0` to skip checking.

The easiest connection method is generally to include your own public key in the server's `~/.ssh/authorized_keys` mannually or by running `ssh-copy-id user@server.com` from your local machine, [enable agent forwarding](https://docs.github.com/en/developers/overview/using-ssh-agent-forwarding), and then set `agentForward = true` in `deploy.toml`. This will allow you to use your own credentials when pulling code from GitHub (required for private repos). Otherwise you can create a [deploy key](https://docs.github.com/en/developers/overview/managing-deploy-keys) and keep it on the server.

Expand Down Expand Up @@ -453,14 +455,15 @@ Run `yarn rw deploy baremetal --help` for the full list of flags. You can set th

Baremetal supports running your own custom commands before or after the regular deploy commands. You can run commands **before** and/or **after** the built-in commands. Your custom commands are defined in the `deploy.toml` config file. The existing commands that you can hook into are:

1. `update` - cloning the codebase
2. `symlinkEnv` - symlink the new deploy's `.env` to shared one in the app dir
3. `install` - `yarn install`
4. `migrate` - database migrations
5. `build` - `yarn build` (your custom before/after command is run for each side being built)
6. `symlinkCurrent` - symlink the new deploy dir to `current` in the app dir
7. `restart` - (re)starting any pm2 processes (your custom command will run before/after each process is restarted)
8. `cleanup` - cleaning up any old releases
1. `df` - Checking for free disk space
2. `update` - cloning the codebase
3. `symlinkEnv` - symlink the new deploy's `.env` to shared one in the app dir
4. `install` - `yarn install`
5. `migrate` - database migrations
6. `build` - `yarn build` (your custom before/after command is run for each side being built)
7. `symlinkCurrent` - symlink the new deploy dir to `current` in the app dir
8. `restart` - (re)starting any pm2 processes (your custom command will run before/after each process is restarted)
9. `cleanup` - cleaning up any old releases

You can define your before/after commands in three different places:

Expand Down
Loading

0 comments on commit 1b99c38

Please sign in to comment.