-
-
Save feyyazesat/bd3dcc2ce6ccfeea31e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# include config | |
# config example below: | |
# | |
# | |
# Example deploy_config.sh | |
# | |
# dev_env() { | |
# PHPBIN="/usr/local/bin/php" | |
# SERVER_IP="192.168.1.1" | |
# SERVER_PORT="22" | |
# SERVER_USER="apache" | |
# HTTPDOCS_PATH="/var/www/vhosts/domain.com/httpdocs" | |
# ASSETIC_ENV="--env=prod" | |
# CERTIFICATE="certificate.pem" | |
# } | |
execute_rsync() { | |
if [ "$DRY_RUN" == "N" ]; then | |
RSYNC_DRYRUN= | |
else | |
RSYNC_DRYRUN=--dry-run | |
fi | |
echo rsync -vaz --delete "$RSYNC_DRYRUN" -e "$BASE_SSH" --stats --progress --exclude-from 'rsync.exclude' . "$SERVER_USER"@"$SERVER_IP":"$HTTPDOCS_PATH" | |
rsync -vaz --delete "$RSYNC_DRYRUN" -e "$BASE_SSH" --stats --progress --exclude-from 'rsync.exclude' . "$SERVER_USER"@"$SERVER_IP":"$HTTPDOCS_PATH" | |
} | |
execute_schema_update() { | |
if [ "$DRY_RUN" == "N" ]; then | |
SCHEMA_UPDATE=--force | |
else | |
SCHEMA_UPDATE=--dump-sql | |
fi | |
echo "$BASE_SSH" "$SERVER_USER@$SERVER_IP $PHPBIN $HTTPDOCS_PATH/app/console doctrine:schema:update $SCHEMA_UPDATE" | |
$BASE_SSH "$SERVER_USER"@"$SERVER_IP" "$PHPBIN $HTTPDOCS_PATH/app/console doctrine:schema:update $SCHEMA_UPDATE" | |
} | |
execute_clear_cache() { | |
if [ "$DRY_RUN" == "N" ]; then | |
echo "$BASE_SSH" "$SERVER_USER"@"$SERVER_IP" rm -rf "$HTTPDOCS_PATH"/app/cache/* | |
$BASE_SSH "$SERVER_USER"@"$SERVER_IP" rm -rf "$HTTPDOCS_PATH"/app/cache/* | |
else | |
skip_task "execute_clear_cache" | |
fi | |
} | |
execute_assets_install() { | |
if [ "$DRY_RUN" == "N" ]; then | |
echo "$BASE_SSH" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assets:install "$HTTPDOCS_PATH"/web --symlink | |
$BASE_SSH "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assets:install "$HTTPDOCS_PATH"/web --symlink | |
else | |
skip_task "execute_assets_install" | |
fi | |
} | |
execute_assetic_dump() { | |
if [ "$DRY_RUN" == "N" ]; then | |
echo "$BASE_SSH" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assetic:dump "$ASSETIC_ENV" | |
$BASE_SSH "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assetic:dump "$ASSETIC_ENV" | |
else | |
skip_task "execute_assetic_dump" | |
fi | |
} | |
execute_file_touch() { | |
if [ "$DRY_RUN" == "N" ]; then | |
echo "$BASE_SSH" "$SERVER_USER"@"$SERVER_IP" touch "$HTTPDOCS_PATH"/app/config/parameters.yml | |
$BASE_SSH "$SERVER_USER"@"$SERVER_IP" touch "$HTTPDOCS_PATH"/app/config/parameters.yml | |
else | |
skip_task "execute_file_touch" | |
fi | |
} | |
color_output() { | |
echo -e "\033[$2m$1\033[0m" | |
} | |
execute_task() { | |
echo "" | |
color_output "-> started '$1'" "$START_TASK_COLOR" | |
"$1" | |
color_output "<- finished '$1'" "$END_TASK_COLOR" | |
} | |
skip_task() { | |
echo "[SKIPPED] $1" | |
} | |
title_label() { | |
color_output "$1" "$START_END_SCRIPT_COLOR" | |
} | |
fn_exists() | |
{ | |
[ `type -t $1`"" == 'function' ] | |
} | |
START_END_SCRIPT_COLOR=37 | |
START_TASK_COLOR=33 | |
END_TASK_COLOR=36 | |
################################ | |
# script execution starts here # | |
################################ | |
# check if config file exists | |
if [ ! -e 'deploy_config.sh' ]; then | |
echo "Error: Config file not found (deploy_config.sh)" | |
exit 1 | |
fi | |
if [ ! -e 'rsync.exclude' ]; then | |
echo "Error: rsync config file not found (rsync.exclude)" | |
exit 1 | |
fi | |
source deploy_config.sh | |
# check environment config | |
if [ "$1" == "" ]; then | |
echo "Error: Environment required: use deploy_sf2 <env>" | |
exit 1 | |
fi | |
if ! fn_exists "$1_env"; then | |
echo "Error: environment config function $1_env not found" | |
exit 1 | |
fi | |
echo "Running deploy for $1 environment" | |
"$1_env" | |
# read dry-run option | |
echo "Execute dry run? (*/N)" | |
read DRY_RUN | |
title_label "-> Deploy started at: $(date)" | |
if [ "$DRY_RUN" == "N" ]; then | |
color_output "-> MODE: EXECUTE" 33 | |
else | |
color_output "-> MODE: DRY RUN" 33 | |
fi | |
BASE_SSH='ssh' | |
if [ ! "$SERVER_PORT" == "" ]; then | |
BASE_SSH=$BASE_SSH" -p $SERVER_PORT" | |
fi | |
if [ ! "$CERTIFICATE" == "" ]; then | |
BASE_SSH=$BASE_SSH" -i $CERTIFICATE" | |
fi | |
execute_task "execute_rsync" | |
execute_task "execute_schema_update" | |
execute_task "execute_clear_cache" | |
execute_task "execute_assets_install" | |
execute_task "execute_assetic_dump" | |
execute_task "execute_file_touch" | |
echo "" | |
title_label "Deploy finished at: $(date)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment