mratorr
7/25/2016 - 3:24 PM

Deploy com o git - git --bare

# Entrar no servidor e fora da pasta do projeto

$ cd /home
$ mkdir repo && cd repo
$ mkdir site.git && cd site.git
$ git init --bare

$ cd hooks
$ vim post-receive

## Adicionar no arquivo
```
  #!/bin/sh
  git --work-tree=/home/rails/site --git-dir=/home/repo/site.git checkout -f
```
$ chmod +x post-receive

> /home/rails/site = pasta aonde esta o projeto
> /home/repo/site.git = pasta aonde ficara o hook do git

$ vim post-update
## Adicionar no arquivo
```
#!/bin/sh

APP_PATH=/home/rails/balada
export RAILS_ENV="production"
export PATH="/usr/local/rvm/gems/ruby-2.2.2/bin:/usr/local/rvm/rubies/ruby-2.2.2/bin:$PATH"
export GEM_PATH="/usr/local/rvm/gems/ruby-2.2.2:$GEM_PATH"
BUNDLE=/usr/local/rvm/gems/ruby-2.2.2/bin/bundle

cd ${APP_PATH}

echo '~> Post Update ============================'

echo '- Bundle Install'
RAILS_ENV=production $BUNDLE install

echo '- DB Migration'
RAILS_ENV=production $BUNDLE exec rake db:migrate

echo '- Assets Precompile'
RAILS_ENV=production $BUNDLE exec rake assets:precompile

echo '- Assets Sync'
RAILS_ENV=production $BUNDLE exec rake assets:sync

echo '- Create folder tmp'
mkdir -p tmp/

echo '- Create file restart'
touch tmp/restart.txt

```

$ chmod +x post-update

# Adicione ou altere no arquivo /etc/ssh/sshd_config

```
PermitUserEnvironment yes
```

# Variaveis globais colocar no arquivo /etc/environment

# Adicione os path da versao do ruby

```
env | grep -E "^(GEM_HOME|PATH|RUBY_VERSION|MY_RUBY_HOME|GEM_PATH)=" > ~/.ssh/environment
```

# reinicie o ssh

```
sudo /etc/init.d/ssh restart
```


# no servidor local
git remote add production ssh://user@mydomain.com/home/repo/site.git