Deploy with GIT x Deploy with Gulp

7

I still can not figure out what the best deploy of a site is. I explain the way I'm doing:

GIT

  • I started a local repository
  • I hosted my repository on some service like GitHub / Bitbucket
  • I joined the server via SSH and clone the direct repository of this service
  • Whenever I update the site on my local PC, I give a PUSH back to GitHub / BitBucket, I enter the site via SSH and I give a PULL to update the files.

This way I can keep everything versioned without needing FTP and I find it fast. But is this a good practice to deploy with GIT?

GULP

With GULP, things change a bit. There are two folders: dist which is the "production" or deploy folder, so I understand; and the app folder which is the folder I'm working in, development folder.

If I do deploy with GIT, is there a way to CLONATE only the DIST folder on the server via SSH? And if you are deploying with GULP itself via FTP, would it be a good practice?

I know (or think I know) to deploy both ways, but I wanted to understand a more correct practice of doing that. I use GIT to version my projects and wanted to use GULP, but I do not know if I should version the two folders (dist and app).

    
asked by anonymous 09.07.2015 / 13:34

1 answer

1

On deploy with git you can improve it by following these steps:

1. Add a bare repository on the production server.

This bare repository does not contain the working copy files. Basically it is the contents of the .git folder in place of the working copy.

   $ git init --bare ~/git/projeto.git

2. Add hook post-receive

This scrtipt is executed when the push of the local machine is completed and moves the files to a place. It is in project.git / hooks / and is called a 'post-receive' (if there is no create). You can use vim to edit or create it. The script checks if the correct branch is pushed (not implementing a development branch for example).

#!/bin/bash
#
# Um exemplo de script para o hook post-receive que atualiza os arquivos de um diretório.

TARGET="/var/www/projeto"
GIT_DIR="/var/git/projeto.git"
BRANCH="master"

while read oldrev newrev ref
do
     # Apenas checa se o branch enviado é o master (ou qualquer outro ramo que você gostaria de fazer o deploy)
     if [[ $ref = refs/heads/$BRANCH ]];
     then
          echo "Referencia $ref recebida. Atualizando ${BRANCH} branch para  produção..."
          git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
     else
          echo "Referencia $ref recebida. Nada foi feito: Somente a ${BRANCH} branch pode atualizar este servidor."
     fi
done 

3. Add the remote repository to your local repository

    $ cd ~/caminho/para/copia-de-trabalho/
    $ git remote add producao ssh://usuario@servidor/var/git/projeto.git

4. Push the production server

You can now push the master branch to the production server:

$ git push producao master

And every time you need to perform a deploy to the production server, just do a push. I hope I have helped.

    
30.03.2017 / 16:31