Deploy with GIT x Deploy with Gulp

Asked

Viewed 308 times

7

I still can’t figure out which is the best deploy on a site. I explain how I’m doing:

GIT

  • I started a local repository
  • I hosted my repository on some service like Github/Bitbucket
  • I hacked into the server via SSH and clone the direct repository of that service
  • Whenever I update the site on my PC (local), I give a PUSH again pro Github/ Bitbucket, enter the hosting site via SSH and give a PULL to update the files.

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


GULP

Already with GULP the thing changes a little. There are two folders: dist which is the "production" or deploy folder as I understand it; and the folder app which is the folder I’m working on, development folder.

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


I know (or think I know) how to deploy both ways, but I wanted to understand a more correct practice of doing this. I use GIT to promote my projects and wanted to use GULP, but I don’t know if I should see both folders (dist and app).

  • So Israel, in the case of Gulp the app folder is where the source of the project is and it is it that you must Convert the dist folder has no need for versioning since it is the deploy, it just needs to publish even...

  • You can use a git post-receive hook to generate dist using Gulp as soon as you receive it on the server. So you can keep dist out of versioning and decrease file transfer load.

  • Additionally, you can set up a webhook on github to update your server automatically. So you don’t need to access the server via ssh every time you change the code.

1 answer

1

On the git deploy you can improve it by following the following steps:

1. Add a Bare repository to the production server.

This "Bare" repository does not contain the working copy files. It’s basically the contents of the . git folder instead of the working copy.

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

2. Add the post-receive hook

This scrtipt runs when the local machine push is completed and moves the files to one place. It is in project.git/Hooks/ and is called 'post-receive' (if there is no create). You can use vim to edit it or create it. The script checks whether 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 to production server

Now you can push the master branch to the production server:

$ git push producao master

And every time you need to deploy to the production server, just push. I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.