Skip to content

Instantly share code, notes, and snippets.

@sergix44
Last active May 15, 2024 00:45
Show Gist options
  • Save sergix44/b700613889045d36a72a649761e485b7 to your computer and use it in GitHub Desktop.
Save sergix44/b700613889045d36a72a649761e485b7 to your computer and use it in GitHub Desktop.
Laravel deployment script
#!/usr/bin/env sh
# default: deploy from master branch
_BRANCH=${1:-master}
# php binary
_PHP=${2:-php8.2}
# path to composer
_COMPOSER=${3:-~/.composer/composer}
# remote name
_REMOTE=${4:-origin}
# sha1 of the current script
_SHA1=$(sha1sum "$0" | awk '{print $1}')
# check if a command exists
commandExists() {
if ! [ -x "$(command -v "$1")" ]; then
echo "Error: command $1 not found. Aborting..." >&2
exit 1
fi
}
# Check if the required commands exist
commandExists git
commandExists "$_PHP"
commandExists "$_COMPOSER"
# commandExists npm
set -x
$_PHP artisan down
git reset --hard
git fetch "$_REMOTE"
git checkout -f "$_REMOTE"/"$_BRANCH"
# check if the script has been changed, if so, restart it to run the new version
if [ "$_SHA1" != "$(sha1sum "$0" | awk '{print $1}')" ]; then
echo "Updater has been changed. Restarting..."
cd "$(dirname "$0")" && sh "$0" "$@"
exit 0
fi
$_PHP "$_COMPOSER" install --no-dev --no-interaction --optimize-autoloader --classmap-authoritative
$_PHP artisan optimize
$_PHP artisan view:cache
$_PHP artisan storage:link
$_PHP artisan migrate --force --step
$_PHP artisan queue:restart
# asset bundling
# npm ci
# npm run build
$_PHP artisan up
# for nutgram/nutgram framework
# $_PHP artisan nutgram:register-commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment