Introduction Link to heading
Well, “catch you next week” was a bit optimistic. My writing goal of a blog post per week might need to be updated to one per month. On the topic of updates and sustainability, today I’m going to talk about updating cdk.
But Why Update Link to heading
It’s 2020. Almost 2021. Let’s all agree that software has bugs. Keeping things patched is just a reality of life. Also, cdk is moving pretty quickly these days. It is usually less work to make multiple small upgrades than a single large one.
Getting Started Link to heading
The good news is that cdk has better release notes
than PostgreSQL, which is an awfully high bar. And this is where you want to start.
Take a look in your package.json and figure out what version of cdk is.
Next, hop over to the release notes and start scrolling down.
You will want to focus on the Breaking Changes section of each release.
Make note of anything relevant to your code.
Purge and Pull Link to heading
Arguably the most obnoxious and difficult to understand error I have seen working with cdk is the construct mismatch error. If you have even one cdk package of even a slightly different version than the rest, you will have a Bad Time. We will explicitly avoid that problem.
# I think it is reasonable to have this utility globally installed.
npm install -g npm-check-updates
cd myCdkProject
git pull
git checkout -b update
# Make sure no old versions are floating around
rm -rf node_modules/*
# Update EVERYTHING
ncu -u
npm install
git add -p
git commit -m "updated cdk"
npm run watch
Iterate Iterate Iterate Link to heading
The last command we ran was npm run watch which will build the project every time you save a change.
In an ideal world, you have no breaking changes to address.
The project builds, and in a separate terminal you confirm the update:
npm run test
You did write UTs right? cdk’s rather excellent UT support makes it pretty easy to avoid fragile UTs. Once you have tests passing, it’s time for the final test:
npx cdk diff
Should return no differences.
If you have a breaking change, you’ll need to get things re-wired appropriately.
Once your build succeeds, iterate on the diff until you can see that you
haven’t changed anything in your deploy.
Conclusion Link to heading
I have been repeatedly impressed by how easy it is to keep cdk up to date. I strongly encourage you to do the same.