fix(deps): update redwood monorepo to v2 (major) #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
1.5.2
->2.0.0
1.5.2
->2.0.0
1.5.1
->2.0.0
1.5.2
->2.0.0
1.5.2
->2.0.0
1.5.2
->2.0.0
1.5.2
->2.0.0
Release Notes
redwoodjs/redwood
v2.0.0
Compare Source
Don't panic
Two point oh?! What is happening?! Reading Tom's latest blog post should ease some of your worries: Major Version Numbers are Not Sacred. Along with v1, this major version will be a part of the same Redwood epochal version, Arapaho Forest.
There are only a few breaking changes in this release, and if you don't use some of these features then this'll be practically the same as a normal ol' minor-version update for you!
Having said that, here are the three breaking changes:
Breaking Changes
Linting import order
Previously, Redwood didn't validate the order of imports. Import something from a local file before an npm package? Space between import groups? Nothing to see here:
But since we use this rule in the framework itself, and since Redwood's opinionated, we consider its exclusion from projects a miss. So as of v2.0.0, Redwood lints the order of imports and reports them as an error. So if you're seeing red squiggles on import declarations after upgrading, this's why:
Although they're annoying and make you feel like you did something wrong, in of themselves, these squiggles are harmless. The real consequences come if you're running lint in CI because now that step will fail. But luckily it's a super easy fix.
How to upgrade
TL;DR, after upgrading, run
yarn rw lint --fix
.Although it really is that simple, we recommend going the extra mile to keep your git history clean by stashing whatever changes you have, running the command, then committing the changes:
Note that running
yarn rw lint --fix
may alert you to other errors, like unused variables, that the lint command can't fix automatically. That's ok—it should've fixed the order of imports still since it's just a matter of rearranging import declarations.Congratulations, you're on v2.0.0! But if you're deploying via baremetal or using auth in serverless functions, keep reading.
Baremetal deploy
This release features some major updates to the Baremetal deploy option! Let's break them down along with any changes you'll need to make to your server and
deploy.toml
file.We've got a good news/bad news situation. The good news: you can now deploy a branch other than
main
and code updates are much more reliable usinggit clone
! The bad news is that you're going to have to do some more config and server setup to get this latest version working. But once you do, everything will be awesome!PM2
Baremetal now requires that PM2 be installed globally, rather than a development dependency of your app. This has to do with the new directory structure we're going to create and where
pm2
is executed from (short version: it's run outside of your actual codebase, soyarn pm2
won't be available).You'll want to remove your existing pm2 services. This will cause downtime, so be mindful if running in a production environment. Run the following commands on the server:
Now install PM2 globally: https://pm2.io/docs/runtime/guide/installation/
PM2 will still be running in memory as the previous
yarn pm2
version, so you can run this command to update the process:If you previously setup PM2 to run at startup, you'll need to update to the new global install instead:
Be sure to remove
pm2
in your app'spackage.json
file.Directory Structure
Next we'll need to update the directory structure inside your deploy path.
Current directory structure:
New directory structure:
The
current
symlink is updated at the end of a deploy to point to the latest release (assuming a successful clone and build). This means all build packages inweb/dist
andapi/dist
remain self-contained in their parent timestamp directory. This makes a rollback trivial: just point thecurrent
symlink to the previous directory and restart your web/api processes!yarn rw deploy baremetal --rollback
is coming soon! A shared.env
file exists in the root of your app path and each copy of the codebase will contain a symlink back out to this file.The easiest way to update to this structure is to simply remove everything inside of your currently deploy directory (like
/var/www/myapp
) and letyarn rw deploy baremetal --first-run
set everything up for you. You'll want to keep your.env
file, however:Config Updates
You'll need to add a new option to your
ecosystem.config.js
file for any processes that run within the context of your app:module.exports = { apps: [ { name: 'serve', + cwd: 'current', script: 'node_modules/.bin/rw', args: 'serve', instances: 'max', exec_mode: 'cluster', wait_ready: true, listen_timeout: 10000, } }
You'll also need to add the
repo
config setting and optionallybranch
to yourdeploy.toml
file (also note the new environment name prefixingservers
, more on that in a moment):The
branch
will default tomain
if not set.Make sure everything is saved, committed, and pushed up to your repo because we're ready for the first deploy.
First Deploy
Run the deploy command for the first time to setup the directory structure, check out your code, and build and start monitoring your processes:
And that's it! If everything started up correctly then you're good to go for future deploys. If not check out https://redwoodjs.com/docs/deployment/baremetal#troubleshooting
If you want to perform a one-time deploy of a branch other than the one listed in
deploy.toml
you can do so via a flag at deploy time:Multiple Environment Support
Baremetal deploy now supports deploying to multiple environments! If you've got production, and staging, and whatever else, this update is for you. If you're setting up a new deploy from scratch with
yarn rw setup deploy baremetal
you're good to go. If you have an existingdeploy.toml
file you may want to make an update:Instead of just
[[servers]]
prefixing your server config, make it[[environment.servers]]
whereenvironment
is the actual name of your environment. For example:You can still have multiple servers in an environment, just repeat the
[[servers.production]]
heading multiple times, one for each block of server config:This new syntax is optional: keeping your default
[[servers]]
name will act as production (and leaving off the stage name inyarn rw deploy baremetal
will default to use these server settings).Maintenance Page
You can now enable/disable a maintenance page with the Baremetal deploy! Simply create
web/src/maintenance.html
containing your maintenance message. (For now this page must just be plain HTML, but if the need is there it should be possible to add the page to the webpack/babel pipeline and make it a full React app. If this is something you'd like to work on, get in touch!)When you're ready to enable your maintenance page on the site:
And to take it back down:
This command respects the environment argument so you can put it up on just your
staging
environment, for example:That's it! This feature works by turning
web/dist/index.html
into a symlink pointing toweb/src/maintenance.html
. As long as your server is configured to check for the existence of200.html
for the web side and serve that for any URL request that isn't the API, users should see the maintenance page the time time your site loads. Note that if a user already has your site loaded, they will most likely be able to keep clicking through your pages since everything is already cached in the browser. We're thinking about adding a "ping" feature that, on each page request, would check with the server to see if the maintenance page should be displayed, and if so interrupt their browsing session to show it. If this is something you'd like to work on, let us know by opening an issue or PR!Old Deploy Cleanup
Baremetal will now cleanup old deploy codebase directories at the end of a deployment! It defaults to keep the last 5 deployments, but this can be configured in
deploy.toml
with thekeepReleases
option:Why keep around old deploys? In case something goes horribly wrong and you need to rollback!
This config setting is optional and will default to keeping the last 5 deploys if not set.
Rollback
If you deploy and find something has gone horribly wrong, you can now rollback your deploy to the previous release!
You can even rollback multiple deploys, up to the total number you still have denoted with the
keepReleases
option:Note that this will not rollback your database—if you had a release that changed the database, that updated database will still be in effect, but with the previous version of the web and api sides. Trying to undo database migrations is a very difficult proposition and isn't even possible in many cases.
Make sure to thoroughly test releases that change the database before doing it for real!
There's no Rollforward: you probably rolled back because the newer deploy is faulty! Performing a new deploy would be the equivalent action to rolling the codebase forward to a newer release.
Override Default
yarn
andpm2
commandsYou can now override the default
yarn
andpm2
exec commands with your own custom command. Why would you want to do this? Tools like doppler provide their own CLI command to inject secrets into your shell, and you then chain on the command you would normally run, like so:To set this, add the following to your
deploy.toml
file:These two settings are optional and will default to the existing
yarn
andpm2
commands if not set.Lifecycle Events
When in the course of a deploy, if it becomes necessary to run additional commands not provided for in the stock list of Baremetal steps, you can turn to lifecycle events. These events allow you to run custom commands before or after the existing commands. Here are the current steps in a deploy:
update
- the latest code is cloned from the serversymlinkEnv
- a symlink is created in the newly cloned codebase pointing to the.env
file in the main app directoryinstall
- latest dependencies are installedmigrate
- database and db migrations are runbuild
- the api and/or web sides are builtsymlinkCurrent
- a symlink is created from the main app directory to the latest deploy directoryrestart
- PM2 restarts any services listedcleanup
- old deploy directories are removedThere are three ways you can define your lifecycle events: globally (runs for all environments and all servers), environment-specific (runs for all servers in a given environment) or server-specific (runs only for a single server).
Global Lifecycle Events
Add a top level
[before]
or[after]
key to yourdeploy.toml
, listing which step you want to hook into and what command to run:You can hook into multiple steps, and execute multiple custom commands:
Environment Lifecycle Events
Server Lifecycle Events
Important Considerations
All commands are run inside the newly deployed code directory (like
/var/www/myapp/20220520120000
) exceptupdate
andcleanup
! These are run in thepath
defined indeploy.toml
since they are independent of any single release.The
build
andrestart
steps may run multiple times based on how many sides you're building or services you're restarting. Any defined before/after lifecycle events will run as many times as the original step is run, so plan accordingly: make your command idempotent so that it can be run multiple times without side effects.Previously, the behavior of
useRequireAuth
in serverless functions differed depending on whether auth-related headers were set. In this release, we rectified it so that it behaves the same whether or not headers are set.When calling a serverless function wrapped in
useRequireAuth
with no auth-related headers set, Redwood continues invoking the serverless function. But if theauth-provider
header is set and the token is invalid, the function throws and returns a 401 error. This is inconsistent behavior for otherwise similar scenarios. In v2.0.0, we've changed it so that in both scenarios it continues executing.Note that this breaking change is just behavioral. It's up to you as the developer to make sure you call
requireAuth
or use theisAuthenticated
variable inside the serverless function to enforce authentication. That is,useRequireAuth
just makes the authentication context available, but doesn't enforce authentication in of itself.Unique contributors: 35
PRs merged: 48
Breaking
Features
Fixed
Chore
Docs
Package Dependencies
View all Dependency Version Upgrades
See this forum topic for manual upgrade instructions and general upgrade help.
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about these updates again.
This PR has been generated by Mend Renovate. View repository job log here.