Skip to content

Instantly share code, notes, and snippets.

@sergix44
Last active July 23, 2024 07:36
Show Gist options
  • Select an option

  • Save sergix44/dff3f971d621e584807e1812b1e7f1de to your computer and use it in GitHub Desktop.

Select an option

Save sergix44/dff3f971d621e584807e1812b1e7f1de to your computer and use it in GitHub Desktop.
Symfony 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"
set -x
git reset --hard
git fetch "$_REMOTE"
# Check if $_BRANCH is a tag or a branch
if git show-ref --tags "tags/$_BRANCH" --quiet; then
# $_BRANCH is a tag
git checkout -f "tags/$_BRANCH"
else
# $_BRANCH is a branch
git checkout -f "$_REMOTE/$_BRANCH"
fi
# 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 ./bin/console cache:clear --env=prod --no-debug
$_PHP ./bin/console doctrine:migrations:migrate --allow-no-migration --no-interaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment