Tips for ensuring successful build activities:
It is paramount that end users have a positive experience on headless sites with a smooth path to purchase. In this environment, it is essential to proactively prepare in case of a service outage or build error to minimize the impact on the customer experience. If necessary, there must be fallback reactive measures that can be deployed to lessen the customer impact.
To ensure that automated build processes are optimized for consistent and successful deployments, it is necessary to follow some best practices to prevent the sites from being deployed with missing content which would greatly impact the customer experience.
When fetching product and content data during static generation, ensure that exceptions are thrown in try/catch blocks.
- Pass the appropriate option to the generate command in package.json.
- NuxtJS provides a flag “fail-on-error” which causes CI/CD process to fail in the event that a page error occurs.
- NextJS builds, by default, will fail if an error is thrown from getStaticProps. To ensure a NextJS app build fails due to a downstream API issue, always throw an error as the appropriate inside of getStaticProps. As mentioned above, if fetching data inside of a try/catch, ensure that an error is thrown
If a system outage has caused problems in the current production deployment of the app AND the outage is preventing successful builds, it is possible to revert to a known successful deployment instance in Netlify or Vercel.
If your App is deployed with Vercel (https://vercel.com/docs/cli#commands/alias):
NOTE: In Vercel’s UI, there is an option to Promote to Production an earlier build. For the purposes of this document, this option is not viable since it triggers a rebuild. The method below utilizes the Vercel CLI, and does not trigger a build.
- Pause or disable any automated build processes to prevent them from overwriting the next steps.
- Locate the production domain(s) for the application’s deployments. This can be found on the Overview tab of the application or in Settings > Domains.
- Locate the known-good deployment that should be promoted to production in the Deployments tab of the application.
- In a CLI, change directory to the root of your application’s repository, and execute the following command as many times as needed to update all production domains.
vercel alias set [deployment-URL] [production-URL]
deployment-URL = domain of known good deployment
production-URL = domain of production site
Enable automation that was disabled in step 1 when the issue preventing successful builds is resolved.
If your App is deployed with Netlify (https://docs.netlify.com/configure-builds/stop-or-activate-builds/):
- Login to Netlify, click on the relevant site and navigate to the Deploys tab.
- Select the previous Deploy you’d like to publish, then click Publish deploy and confirm by clicking Publish.
- Next, you’ll see the option to Lock publishing to this deploy. By selecting this, you’ll temporarily stop auto-publishing from deploying new builds to the production branch. New builds will still trigger (if you have a cron job set up or if you trigger them manually via UI or API) but they will not deploy to production.
- Confirm by clicking Stop auto-publishing.
- Return to the Deploys tab to see that the build is published and locked to production.
- To resume normal CI/CD processes, you must click on the published/locked deployment, select Unlock publishing, and then confirm by Start auto publishing.
NOTE: Reactivating auto-publishing will not trigger a rebuild and deployment. Instead, any future deployments will be promoted and published to production. If you need a new version of the app built and deployed immediately after enabling auto-publishing, you must trigger a build manually.