Skip to content

Instantly share code, notes, and snippets.

@osbre
Last active August 6, 2024 16:32
Show Gist options
  • Save osbre/221189736e6a158a7bb52833ac0d316d to your computer and use it in GitHub Desktop.
Save osbre/221189736e6a158a7bb52833ac0d316d to your computer and use it in GitHub Desktop.
(ported from freek.dev's envoy.blade.php setup)
# Configuration
SITE_DIR="/home/forge/staging.streampot.io"
GIT_REPO="git@github.com:StreamPot/SaaS.git"
RELEASES_DIR="$SITE_DIR/releases"
PERSISTENT_DIR="$SITE_DIR/persistent"
CURRENT_DIR="$SITE_DIR/current"
RELEASE_NAME=$(date +"%Y%m%d-%H%M%S")
NEW_RELEASE_DIR="$RELEASES_DIR/$RELEASE_NAME"
# Ensure required directories exist
mkdir -p $RELEASES_DIR $PERSISTENT_DIR/storage
# Clone repository
echo "πŸŒ€ Cloning repository..."
git clone --depth 1 $GIT_REPO --branch "$FORGE_SITE_BRANCH" "$NEW_RELEASE_DIR"
# Configure sparse checkout
cd "$NEW_RELEASE_DIR" || exit
git config core.sparsecheckout true
echo "*" > .git/info/sparse-checkout
echo "!storage" >> .git/info/sparse-checkout
echo "!public/build" >> .git/info/sparse-checkout
git read-tree -mu HEAD
# Mark release
echo "$RELEASE_NAME" > "$NEW_RELEASE_DIR"/public/release-name.txt
# Set up environment and dependencies
echo "🚚 Setting up environment and running Composer..."
ln -nfs $SITE_DIR/.env "$NEW_RELEASE_DIR"/.env
#ln -nfs $SITE_DIR/auth.json "$NEW_RELEASE_DIR"/auth.json
cd "$NEW_RELEASE_DIR" || exit
$FORGE_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader
# Run PNPM
echo "πŸ“¦ Running PNPM..."
/home/forge/.local/share/pnpm/pnpm i && /home/forge/.local/share/pnpm/pnpm build
# Update symlinks
echo "πŸ”— Updating symlinks..."
ln -nfs $PERSISTENT_DIR/storage "$NEW_RELEASE_DIR"/storage
#ln -nfs $PERSISTENT_DIR/uploads "$NEW_RELEASE_DIR"/public/uploads
#ln -nfs $PERSISTENT_DIR/storage/admin-uploads "$NEW_RELEASE_DIR"/public/admin-uploads
#ln -nfs $PERSISTENT_DIR/storage/og-images "$NEW_RELEASE_DIR"/public/og-images
#ln -nfs $PERSISTENT_DIR/fonts "$NEW_RELEASE_DIR"/public/fonts
# Optimize installation
echo "✨ Optimizing installation..."
php artisan clear-compiled
# Backup database
# echo "πŸ“€ Backing up database..."
# php artisan backup:run
# Migrate database
echo "πŸ™ˆ Migrating database..."
php artisan migrate --force
# Bless new release
echo "πŸ™ Blessing new release..."
ln -nfs "$NEW_RELEASE_DIR" $CURRENT_DIR
cd $CURRENT_DIR || exit
php artisan horizon:terminate
php artisan config:clear
php artisan view:clear
php artisan cache:clear
php artisan config:cache
php artisan route:clear
php artisan route:cache
php artisan event:cache
# Filament admin commands
php artisan icons:cache
php artisan filament:cache-components
# Restart services
echo "πŸ”„ Restarting services..."
sudo service $FORGE_PHP_FPM restart
sudo supervisorctl restart all
# Additional tasks
#php artisan schedule:sync
#php artisan health:check
# Clean old releases
echo "🚾 Cleaning up old releases..."
cd $RELEASES_DIR || exit
ls -dt */ | tail -n +4 | xargs -I {} rm -rf {}
echo "πŸš€ Deployment completed successfully!"
@osbre
Copy link
Author

osbre commented Aug 6, 2024

video-of-a-problem-with-changing-deployment-script.mov

Upd: turns out this was due to emoji being present in the script. still a bug tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment