-
-
Save revollat/18d5913a8349952a40cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| # } | |
| execute_rsync() { | |
| if [ "$DRY_RUN" == "y" ]; then | |
| RSYNC_DRYRUN=--dry-run | |
| else | |
| RSYNC_DRYRUN= | |
| fi | |
| echo rsync -vaz --delete "$RSYNC_DRYRUN" -e "ssh -p $SERVER_PORT" --stats --progress --exclude-from 'rsync.exclude' . "$SERVER_USER"@"$SERVER_IP":"$HTTPDOCS_PATH" | |
| rsync -vaz --delete "$RSYNC_DRYRUN" -e "ssh -p $SERVER_PORT" --stats --progress --exclude-from 'rsync.exclude' . "$SERVER_USER"@"$SERVER_IP":"$HTTPDOCS_PATH" | |
| } | |
| execute_schema_update() { | |
| if [ "$DRY_RUN" == "y" ]; then | |
| SCHEMA_UPDATE= | |
| else | |
| SCHEMA_UPDATE=--force | |
| fi | |
| echo ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH/app/console doctrine:schema:update $SCHEMA_UPDATE" | |
| ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH/app/console doctrine:schema:update $SCHEMA_UPDATE" | |
| } | |
| execute_clear_cache() { | |
| if [ "$DRY_RUN" == "y" ]; then | |
| skip_task "execute_clear_cache" | |
| else | |
| echo ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" rm -rf "$HTTPDOCS_PATH"/app/cache/* | |
| ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" rm -rf "$HTTPDOCS_PATH"/app/cache/* | |
| fi | |
| } | |
| execute_assets_install() { | |
| if [ "$DRY_RUN" == "y" ]; then | |
| skip_task "execute_assets_install" | |
| else | |
| echo ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assets:install "$HTTPDOCS_PATH"/web --symlink | |
| ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assets:install "$HTTPDOCS_PATH"/web --symlink | |
| fi | |
| } | |
| execute_assetic_dump() { | |
| if [ "$DRY_RUN" == "y" ]; then | |
| skip_task "execute_assetic_dump" | |
| else | |
| echo ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assetic:dump "$ASSETIC_ENV" | |
| ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" "$PHPBIN" "$HTTPDOCS_PATH"/app/console assetic:dump "$ASSETIC_ENV" | |
| fi | |
| } | |
| execute_file_touch() { | |
| if [ "$DRY_RUN" == "y" ]; then | |
| skip_task "execute_file_touch" | |
| else | |
| echo ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" touch "$HTTPDOCS_PATH"/app/config/parameters.yml | |
| ssh -p "$SERVER_PORT" "$SERVER_USER"@"$SERVER_IP" touch "$HTTPDOCS_PATH"/app/config/parameters.yml | |
| 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=36 | |
| END_TASK_COLOR=33 | |
| ################################ | |
| # 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? (y/*)" | |
| read DRY_RUN | |
| title_label "-> Deploy started at: $(date)" | |
| if [ "$DRY_RUN" == "y" ]; then | |
| color_output "-> MODE: DRY RUN" 33 | |
| else | |
| color_output "-> MODE: EXECUTE" 33 | |
| 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