Skip to content

Instantly share code, notes, and snippets.

@mishak87
Last active August 29, 2015 14:02
Show Gist options
  • Save mishak87/ac15e189cdf7852b8e0b to your computer and use it in GitHub Desktop.
Save mishak87/ac15e189cdf7852b8e0b to your computer and use it in GitHub Desktop.
Simple deploy script for demo/sandbox server - supports changed file
#!/bin/bash
echo "Deploy launched."
# fetch new version
git fetch origin
# check for changes
CHANGES=$(git status -s)
# store changes
if [ "$CHANGES" ]; then
echo "Saving changes"
git checkout -b changes -q
git add -A .
git commit -m "CHANGES" -q
git checkout master -q
fi
# checkout new version
echo "Checking out latest code"
git reset --hard origin/master -q
# re-apply changes
if [ -n "$CHANGES" ]; then
echo "Restoring changes"
git cherry-pick changes
git reset HEAD^ -q
git branch -D changes -q
fi
# install dependencies
echo "Installing composer dependencies"
composer install --prefer-source --dev -n -q
echo "Installing bower dependencies"
bower install -s
# database migration
MIGRATE=1
MIGRATION_STATUS_FILE="migrations/.status"
if [ -f $MIGRATION_STATUS_FILE ]; then
MIGRATION_LAST_BATCH=$(cat $MIGRATION_STATUS_FILE)
echo "Migrating database"
touch $MIGRATION_STATUS_FILE
else
MIGRATE=0
echo "Creating database"
vendor/bin/nette orm:schema-tool:create
if [ $? -ne 0 ]; then
echo "Creating database failed"
exit 1
fi
fi
for BATCH in $(ls migrations | grep "\.sql$" | sort); do
if [ $MIGRATE -eq 1 ]; then
if [[ "$BATCH" > "$MIGRATION_LAST_BATCH" ]]; then
vendor/bin/nette dbal:batch:file $BATCH -q
if [ $? -ne 0 ]; then
echo "Migration script $BATCH failed"
exit 1
fi
fi
fi
echo $BATCH > $MIGRATION_STATUS_FILE
done
# generate proxies
echo "Generating proxies"
vendor/bin/nette orm:generate:proxies -q
echo "Setting up application"
touch app/config/setup.neon
echo "Cleaning cache"
rm -f temp/cache/latte/*
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment