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

feat(baremetal): Check available disk space #11469

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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.
Copy link
Member

@cannikin cannikin Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says [optional] but doesn't the task itself require it to exist? It only skips if the value is set to 0 but what if you don't have the config option at all? Like if a person upgrades and doesn't this config var, what happens? Can it just also skip if undefined?

Copy link
Member Author

@Tobbe Tobbe Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't the task itself require it to exist?

No, I made it part of DEFAULT_SERVER_CONFIG. So if it's not set at all it will default to 2048 MB.


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
Loading