Last active
September 7, 2022 10:22
-
-
Save kmelve/30e5e3d9a22fb60836c5668600bd5fd0 to your computer and use it in GitHub Desktop.
Bulk update your Netlify build images to Ubuntu Focal. https://docs.netlify.com/configure-builds/overview/#build-image-selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Assumes that you have the Netlify and jq CLI tools installed and that you are logged in. | |
# Only been tested on macOS and zsh | |
# Will change the build image for all sites in a Netlify account to the specified image | |
# | |
# Usage: sh ./netlify-build-image-bulk.sh | |
# This assumes that you have logged in with the CLI fairly recently and that you're on macOS | |
# For other systems: https://github.com/sindresorhus/env-paths#pathsconfig | |
NETLIFY_AUTH=$(cat ~/Library/Preferences/netlify/config.json|jq -r ".users[].auth.token") | |
# GET THE SITE IDS | |
echo "Fetching sites. Please wait." | |
SITE_IDS=$(netlify sites:list --json|jq -r '.[].id') | |
echo "Done fetching your sites. Moving on to updating their build images." | |
for SITE_ID in $SITE_IDS | |
do | |
echo "Updating build image for ${SITE_ID}" | |
SITE_NAME=$(curl -s "https://app.netlify.com/access-control/bb-api/api/v1/sites/${SITE_ID}" \ | |
-X 'PUT' \ | |
-H 'content-type: application/json' \ | |
-H "cookie: _nf-auth=${NETLIFY_AUTH}; _nf-auth-hint=user-is-likely-authed;" \ | |
-d '{"build_image":"focal"}'|jq -r '.name') | |
echo "Done updating build image for ${SITE_NAME}\n" | |
# Be nice with the Netlify API and don't hit rate limits | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment