Created
February 28, 2014 22:22
-
-
Save rkmax/9281250 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
| #!//usr/bin/env bash | |
| verify_git_tag() { | |
| git show-ref --tags --quiet --verify -- "refs/tags/$1" | |
| } | |
| refresh_git_repo() { | |
| git clean -f | |
| git fetch origin --quiet > /dev/null 2>&1 | |
| } | |
| deploy_files() { | |
| local from=$1 | |
| local to_dest=$2 | |
| local exclude=$3 | |
| [ -d "$to_dest" ] && rm -rf "$to_dest" | |
| mkdir -p "$to_dest" | |
| rsync -a --exclude-from "$exclude" "$from/" "$to_dest/" | |
| } | |
| if [ -z $1 ]; then | |
| echo "Debe definir al menos la version a desplegar"; | |
| exit | |
| else | |
| version_tag=$1 | |
| fi | |
| if [ -z $2 ]; then | |
| base_dest="/var/www" | |
| else | |
| base_dest="$2" | |
| fi | |
| if [ -z $3 ]; then | |
| base_conf="/root/siiac-deploy" | |
| else | |
| base_conf="$3" | |
| fi | |
| repository="[email protected]:rkmax/incoder-siia.git" | |
| link_orig="${base_dest}/repository" | |
| link_dest="${base_dest}/current" | |
| rsync_excl="${base_conf}/exclude.txt" | |
| rsync_dest="${base_dest}/${version_tag}" | |
| http_user="http" | |
| # 1. verificamos si el directorio existe | |
| # Clonamos el repositorio | |
| if [ ! -d $link_orig ]; then | |
| mkdir -p $link_orig | |
| fi | |
| # 2. Verificamos que exista el repositorio | |
| if [ ! -f "$link_orig/.git/config" ]; then | |
| git clone $repository $link_orig | |
| fi | |
| # 2.b nos movemos a la carpeta | |
| cd $link_orig | |
| # 3. Optenemos los cambios del repositorio | |
| refresh_git_repo | |
| # 4. La version debe existir | |
| if verify_git_tag $version_tag; then | |
| git checkout $version_tag | |
| else | |
| echo "La version no existe" | |
| exit 1 | |
| fi | |
| # 5. copiamos parameters.yml | |
| cp "${base_conf}/parameters.yml" "$link_orig/app/config/parameters.yml" || { | |
| echo "El archivo parameters.yml no existe"; | |
| exit 1 | |
| } | |
| # 6. ejecutamos composer.phar | |
| ~/.scripts/composer.phar install --optimize-autoloader | |
| # 7. Ejecutamos node.js deploy | |
| npm install | |
| grunt | |
| # 7. Enviamos los archivos al lugar de despliegue | |
| deploy_files $link_orig $rsync_dest $rsync_excl | |
| # 8. comandos post composer | |
| cd $rsync_dest | |
| sudo setfacl -R -m "${USER}:rwx" -m "${http_user}:rwx" app/cache app/logs | |
| sudo setfacl -dR -m "${USER}:rwx" -m "${http_user}:rwx" app/cache app/logs | |
| php app/console ca:cl --env prod | |
| php app/console ca:w --env prod | |
| php app/console assetic:dump --env prod | |
| ln -sf $rsync_dest $link_dest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment