Skip to content

Instantly share code, notes, and snippets.

@testfailed
Forked from Kamleshpaul/nextjs-pm2-deploy.sh
Last active June 14, 2022 07:16
Show Gist options
  • Save testfailed/8a1950a51005c1b2406daada1e4302a1 to your computer and use it in GitHub Desktop.
Save testfailed/8a1950a51005c1b2406daada1e4302a1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# set -euo pipefail
# IFS=$'\n\t'
function deploy() {
# zero downtime deployment nextjs without vercel
echo "Deploy starting..."
git pull
yarn install || exit
BUILD_DIR=temp yarn build || exit
if [ ! -d "temp" ]; then
echo '\033[31m directory "temp" does not exists!\033[0m'
exit 1;
fi
rm -rf .next
mv temp .next
pm2 reload ecosystem.config.production.js --update-env
echo "Deploy done!"
# make sure `next.config.js` it set `distDir: process.env.BUILD_DIR`
}
deploy "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment