Skip to content

Instantly share code, notes, and snippets.

@luizhenriquefbb
Created July 26, 2020 21:37
Show Gist options
  • Save luizhenriquefbb/f93a376b9e5e9e9f3590093f9b0e99c5 to your computer and use it in GitHub Desktop.
Save luizhenriquefbb/f93a376b9e5e9e9f3590093f9b0e99c5 to your computer and use it in GitHub Desktop.
The first post is about deploying ONLY with git. How to configure a server to "listen" to pushes on a particular branch and automatically update itself.

Git deploy

English 🇺🇸

Deploy with Git

That is it! You read right. If you are building small applications and don't need to prepare a super complex environment to deploy it and just want to keep the code on an updated server, you can set up a bare repository on your remote machine and "listen" changes on the master. So, with a push, you can always update the code on the remote machine.

Step 1: Create the repository that will listen to the pushes on GIT and the folder where the files will be stored

# create repository that will be listening the pushes
git init --bare bare_repository

# where the files will be stored
mkdir repository

step 2: Configure what must be done after each push

on the hooks folder, create a file named post-receive and configure what must be done.

#!/usr/bin/env bash

echo "checking out"
git --work-tree="<path_to_repository>" checkout -f

# install any new dependency...
echo "cd"
cd "<path_to_repository>"
echo "updating"
yarn # if we are using node for instance ....

step 3: non your developing environment create a "remote" to your server

git remote add deploy <username>@<remote_ip>:<path_to_bare_repository>

step 4: do the push / deploy :)

git push deploy HEAD:master

Done !!

Git deploy

Português 🇧🇷

Deploy com Git

Isso mesmo que você leu. Se você está construindo aplicações pequenas e não precisa preparar um ambiente super complexo para fazer um deploy de uma aplicação e quer apenas manter o código em um servidor atualizado, você pode configurar um bare repository na sua máquina remota e "ouvir" mudanças na master. Assim, com um push, você pode sempre atualizar o código na máquina remota.

Passo 1: Crie o repositório que ouvirá os pushes no GIT e a pasta onde os arquivos ficarão armazenados

# crie o repositorio que "ouvira os push's"
git init --bare bare_repository

# onde os arquivos ficarão armazenados
mkdir repository

Passo 2: Configure o que deve ser feito após o pull como instalar dependências

Na pasta hooks, crie um arquivo chamado post-receive e configure o que deve ser feito após o push

#!/usr/bin/env bash

echo "checking out"
git --work-tree="<path_to_repository>" checkout -f

# caso precise atualizar as dependencias...
echo "cd"
cd "<path_to_repository>"
echo "updating"
yarn # nesse exemplo, estamos usando node

Passo 3: no seu ambiente de desenvolvimento crie um "remote" para o repositório remoto

git remote add deploy <username>@<remote_ip>:<path_to_bare_repository>

Passo 4: Faça o push / deploy :)

git push deploy HEAD:master

Prontinho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment