Commit b3697087 authored by Ilya Rassadin's avatar Ilya Rassadin
Browse files

Improved deployments to non-cetera hosting environments

Prior to this change, we've struggled to deploy to external environments
 in case document root folder is not named "www". We need to either create
 a symlink or completely rewrite deploy job to make it work.
Both options required extra efforts from devops team, were error prone
 and symlink option is not reliable by itself: there are chances that
 symlink will be deleted and then deploy will be broken in terms of the
 results but the deployment job will be green, so it is hard to notice
 that something got broken.
Now we can rename DOC_ROOT to any arbitrary value, and this means
 we can deploy www to whatever folder name on the remote server we needed.
parent fe7a38e7
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -4,6 +4,14 @@
    user: www-data
    group: www-data
  script:
    - |
      # Proceed only if DOC_ROOT_NAME is set, non-empty, and not "www"
      #  and www directory exists in current working directory
      #  and $DOC_ROOT_NAME directory not exists
      if [[ -n "${DOC_ROOT_NAME+x}" && -n "$DOC_ROOT_NAME" && "$DOC_ROOT_NAME" != "www" && -d "www" && ! -e "$DOC_ROOT_NAME" ]]; then
          mv www "$DOC_ROOT_NAME"
          echo "renamed www to $DOC_ROOT_NAME"
      fi
    - rsync --links --safe-links -avz --chown=$user:$group -e "ssh $SSH_OPTS" $CI_PROJECT_DIR/www/ $DEPLOY_HOST_PATH/www/
  dependencies:
    - setup_environment_vars
@@ -32,15 +40,26 @@
    group: www-data
    RSYNC_PARAMS: '--delete --dry-run'
  script:
    - chmod 755 $CI_PROJECT_DIR
    - chmod 750 $CI_PROJECT_DIR
    - 'which curl || (apt-get update -y && apt-get install curl -y)'
    - curl -O https://gitlab.cetera.ru/boilerplate/ci/raw/master/rsync-filter-std
    - *set_rsync_filter
    - echo "PROJECT_FILTER set to $PROJECT_FILTER; user set to $user; group set to $group"
    - |
      # Proceed only if DOC_ROOT_NAME is set, non-empty, and not "www"
      #  and www directory exists in current working directory
      #  and $DOC_ROOT_NAME directory not exists
      if [[ -n "${DOC_ROOT_NAME+x}" && -n "$DOC_ROOT_NAME" && "$DOC_ROOT_NAME" != "www" && -d "www" && ! -e "$DOC_ROOT_NAME" ]]; then
          mv www "$DOC_ROOT_NAME"
          echo "renamed www to $DOC_ROOT_NAME"
      fi
    - rsync --links --safe-links -avz --chown=$user:$group -e "ssh $SSH_OPTS" --filter="merge rsync-filter-std" --filter="merge $PROJECT_FILTER" $RSYNC_PARAMS $CI_PROJECT_DIR/ $DEPLOY_HOST_PATH/
  after_script:
    - if [ $PROJECT_CMS_TYPE = bitrix ] && [ $SKIP_SETTINGS_EXTRA_DEPLOYMENT != true ]; then curl -o /tmp/.settings_extra.php https://gitlab.cetera.ru/boilerplate/ci/raw/master/.settings_extra.php; fi
    - if [ $PROJECT_CMS_TYPE = bitrix ] && [ $SKIP_SETTINGS_EXTRA_DEPLOYMENT != true ]; then rsync -avz --chown=$user:$group -e "ssh $SSH_OPTS" /tmp/.settings_extra.php $DEPLOY_HOST_PATH/www/bitrix/; fi
    - |
      if [[ $PROJECT_CMS_TYPE = bitrix && $SKIP_SETTINGS_EXTRA_DEPLOYMENT != true ]]; then
          curl -o /tmp/.settings_extra.php https://gitlab.cetera.ru/boilerplate/ci/raw/master/.settings_extra.php
          rsync -avz --chown=$user:$group -e "ssh $SSH_OPTS" /tmp/.settings_extra.php $DEPLOY_HOST_PATH/$DOC_ROOT_NAME/bitrix/
      fi
  dependencies:
    - setup_environment_vars
  only:
+5 −0
Original line number Diff line number Diff line
@@ -86,6 +86,11 @@ before_script:
  export SKIP_SETTINGS_EXTRA_DEPLOYMENT=${SKIP_SETTINGS_EXTRA_DEPLOYMENT:-"false"}
  echo "SKIP_SETTINGS_EXTRA_DEPLOYMENT=$SKIP_SETTINGS_EXTRA_DEPLOYMENT" >> cetera_build.env

  DOC_ROOT_NAME_VAR="${CETERA_VAR_PREFIX}_DOC_ROOT_NAME"
  DOC_ROOT_NAME=${!DOC_ROOT_NAME_VAR}
  export DOC_ROOT_NAME=${DOC_ROOT_NAME:-"www"}
  echo "DOC_ROOT_NAME=$DOC_ROOT_NAME" >> cetera_build.env

  USER_VAR="${CETERA_VAR_PREFIX}_USER"
  user=${!USER_VAR}
  user=${user:-"www-data"}