Blogs

Upgrading two git repositories automatically

There is a simple way of upgrading or executing a command immediatly after a push has been done.

We just need to go to the server repository (the one which is going to receive the push), and enter in hooks (.git/hooks or hooks if it's a bare repository).

Then, we rename the post-receive.sample to post-receive, without extension, and add this content:

echo "********************"

echo "Post receive hook: Updating User Staging"

echo "********************"

cd ../live

GIT_DIR='.git'

git pull origin master

echo "********************"

echo "Post receive hook: Updating User Staging"

echo "********************"

You'll just have to change the ../live path with the place where your live git code lives, and the next time you make a commit, the live directory will be automatically updated with a git pull.

It is not the perfect way of going live, is my case this is a staging server, so it's fine. If you need to go to "real" live, Capistrano is what you are looking for. We'll speak about it next weeks.

categorias: 

Capistrano config.rb

set :application, "bounty app"

#set :repository,  "localhost:/var/www/git/bountyrepo"

set :repository,  "localhost:/var/www/git/blessed"


set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names

# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`

#



default_run_options[:pty] = true

set :use_sudo, false


#role :web, "localhost"                          # Your HTTP server, Apache/etc

#role :app, "localhost"                          # This may be the same as your `Web` server

#role :db,  "your primary db-server here", :primary => true # This is where Rails migrations will run

#role :db,  "your slave db-server here"

#

#set :deploy_to, "/var/www/html/staging"



task :staging do

  role :web, "localhost"

  set :deploy_to, "/var/www/html/staging"

  #set :deploy_via, :remote_cache

  #after('deploy:symlink', 'cache:clear')

end

task :live do
  role :web, "localhost"
  set :deploy_to, "/var/www/html/live"
  #set :deploy_via, :remote_cache
  #after('deploy:symlink', 'cache:clear')
end
task :live2 do
  role :web, "localhost"
  set :deploy_to, "/var/www/html/live2"
  #set :deploy_via, :remote_cache
  #after('deploy:symlink', 'cache:clear')
end
# if you're still using the script/reaper helper you will need
# If you are using Passenger mod_rails uncomment this:
# namespace :deploy do
#   task :start do ; end
#   task :stop do ; end
#   task :restart, :roles => :app, :except => { :no_release => true } do
#     run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
#   end
# end
#
#
namespace:deploy do
    task:start do
    end
    task:stop do
    end
    task:finalize_update do
        run "chmod -R g+w #{release_path}"
    end
    task:restart do
    end
 after "deploy:restart" do
   #add any tasks in here that you want to run after the project is deployed
     run "rm -rf #{release_path}.git"
  end
end

 

categorias: 

Developing under Linux Apache in windows

Contradictory? Yes, a bit, but you cannot allways choose the systems and architecture in which you are working.

solution? Runing apache under linux instead of runing wamp or some weird solutions like that (i don't like at all, sorry).

First, install vbox: https://www.virtualbox.org/

Second, download the iso of your preffered linux distro, and install it.

Third, when you machine is running, go to Devices>install guest additions.

Now you have to come back to your linux machine, and install a few things, kernel upgrades included (if needed).

 

  • yum install gcc -y
  • yum install kernel sources -y
  • yum install kernel-devel -y

 

 

Reboot your system, and mount:

 

  • mkdir /media/VirtualBoxGuestAdditions
  • mount -t vboxsf /dev/cdrom /media/VirtualBoxGuestAdditions

 

 

 

categorias: 

Centos tips

 

 

  • Configuring your network to start when booting: chkconfig network on (via http://nixcraft.com/centos-rhel-fedora/18643-centos-linux-6-2-eth0-netwo...)
  • configuring services to start apache (or any other daemon) when system boots: chkconfig --level 2345 httpd on
  • ... more coming
  • Override Apache permissions problem: "You don't have permission to access ... on this server". Simply execute: setenforce 0

 

categorias: 

Accessing centos apache/httpd from vbox host

This is the scenario. You installed vbox in your Mac, windows or Linux computer. Then you´ve installed Centos or Red Hat (or any other Red Hat flavor) in this virtual box.

Next step, installed httpd (apache2) and... even it is running and httpd status confirms it with a "running" message, it cannot be accesible from your host machine.

The problem is on iptables. Red Hat by default denies access to this machine from other (external) machines. Solution? Very easy, open iptables file:

vim /etc/sysconfig/iptables

(vim is my favourite editor for a loooong long time)

Look for this line:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

and after that, add this one:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

Restart your services and everything done:

service iptables restart

Thank to http://www.fliquidstudios.com/2009/06/18/creating-a-virtual-development-...

categorias: 

git Integration Manager Workflow tutorial

 

IN BLESSED

mkdir gitlab/blessedrepo

cd gitlab/blessedrepo

git init

 

Creating new files:

vim README

adding:

git add .

git commit -m "first file in blessed repository"

git push

 

IN DEVELOPERS

mkdir developer2

cd developer2

git clone /Users/air/gitlab/blessedrepo

ls

blessedrepo

ls blessedrepo/

README

cd blessedrepo

vim fileindev2.html

git add .

 

 

MacBook-Air-de-Air:blessedrepo air$ git commit -m "added file by developer2"

[master 422f2e5] added file by developer2

 1 file changed, 2 insertions(+)

 create mode 100644 fileindev2.html

MacBook-Air-de-Air:blessedrepo air$ 

 

 

get changes from main repository:

 

MacBook-Air-de-Air:blessedrepo air$ git pull

Already up-to-date.

MacBook-Air-de-Air:blessedrepo air$

 

 

Getting changes from a developer. In Blessedrepository, we execute:

 

 

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

.git/                 fileindev2.html       thirdfileindev1.html  

README                secondfile.html       

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

remote: Counting objects: 4, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From /Users/air/gitlab/developer2/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Updating d3bb3f1..422f2e5

Fast-forward

 fileindev2.html | 2 ++

 1 file changed, 2 insertions(+)

 create mode 100644 fileindev2.html

MacBook-Air-de-Air:blessedrepo air$

 

 

Now, Blessedrepository has the new files:

 

MacBook-Air-de-Air:blessedrepo air$ ls

README secondfile.html

fileindev2.html thirdfileindev1.html

MacBook-Air-de-Air:blessedrepo air$ 

Now, developer1 wants to get changes in main Repository:
MacBook-Air-de-Air:blessedrepo air$ git pull
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /Users/air/gitlab/developer1/publicrepo/../../blessedrepo
   21f5117..422f2e5  master     -> origin/master
Updating d3bb3f1..422f2e5
Fast-forward
 fileindev2.html | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 fileindev2.html
MacBook-Air-de-Air:blessedrepo air$

 

Now, test conflicts. dev 1 and dev2 edit the same file, 

 

 

MacBook-Air-de-Air:blessedrepo air$ git add .

MacBook-Air-de-Air:blessedrepo air$ git commit -m "added by dev1"

[master 80f7afa] added by dev1

 Committer: Air <[email protected]>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:


    git config --global user.name "Your Name"

    git config --global user.email [email protected]


After doing this, you may fix the identity used for this commit with:


    git commit --amend --reset-author


 1 file changed, 2 insertions(+)

MacBook-Air-de-Air:blessedrepo air$ 

 


 

 

Developer 2, the same:

 

 

MacBook-Air-de-Air:blessedrepo air$ git add 

Nothing specified, nothing added.

Maybe you wanted to say 'git add .'?

MacBook-Air-de-Air:blessedrepo air$ git add .

MacBook-Air-de-Air:blessedrepo air$ git commit -m "changes by dev2 in same file"

[master 20b26a8] changes by dev2 in same file

 Committer: Air <[email protected]>

    git commit --amend --reset-author

 1 file changed, 2 insertions(+)

MacBook-Air-de-Air:blessedrepo air$ 

 

 

Time to pull changes from developer1 and 2 in Blessed Repository:

 

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

From /Users/air/gitlab/developer2/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Already up-to-date.

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer2/blessedrepo/

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From /Users/air/gitlab/developer2/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Updating 422f2e5..20b26a8

Fast-forward

 secondfile.html | 2 ++

 1 file changed, 2 insertions(+)

MacBook-Air-de-Air:blessedrepo air$ 

 

 

and from the other developer (where we expect the conflict):

 

MacBook-Air-de-Air:blessedrepo air$ git pull /Users/air/gitlab/developer1/publicrepo/blessedrepo/

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From /Users/air/gitlab/developer1/publicrepo/blessedrepo

 * branch            HEAD       -> FETCH_HEAD

Auto-merging secondfile.html

CONFLICT (content): Merge conflict in secondfile.html

Automatic merge failed; fix conflicts and then commit the result.

MacBook-Air-de-Air:blessedrepo air$ 

 

 

RESOLVE CONFLICTS

git mergetool

 

 

 

categorias: 

private git repositories in bitbucket

Let me got directly to the point. The bitbucket documentation is wrong, on the begining you are just suposed to do a git remote add origin

in the directory which you want to commit. But this will not work:

fatal: Not a git repository (or any of the parent directories): .git

Solution? Init the repository:

git init

git remote add origin https://[email protected]/ACCOUNT/REPOSITORY.git

git push -u origin master

will also don´t work :-(. The problem is that the message error is all but obvious.

 

error: src refspec master does not match any.

error: failed to push some refs to 'https://[email protected]/ACCOUNT/REPOSITORY.git'

 

But, think... we need to have something to commit before sending this "thing", don't we?

Then:

git add .

git commit -m "first commit with all the contents

And, finally, we send the commits with the changes in our code:

git push -u origin master

 

remote: bb/acl: hispamedios is allowed. accepted payload.

To ....

 

Nice, isn't it?

categorias: 

Theming you module

Docs are not allways the best part in programming languages, frameworks or CMS. Sometimes you try to make something and you find problems, just because poor documentation.

It's my situation just now. I was trying to create tpl.php files for a module, and it is really easy... if you follow exactly all the steps.

First, hook_menu:

 

 

/**

 * Implements hook_menu().

 */

function mymodule_menu() {

$items = array();

 

/*

* Category reviews section 

*/

$items['reviews'] = array(

'title'             => 'Bounty reviews',

'description'       => 'Show review categories.',

'page callback'     => 'listofProducts',

  'page arguments'    => array('bounty_settings'),

'access callback'   => 'user_access',

'access arguments'  => array('administer site configuration'),

'type'              => MENU_NORMAL_ITEM,

'file'              => 'includes/bounty_reviews.inc',

);

 

return $items;

}

 

 

Secondly, you could think that just creating the listofProducts should be enought. Well, not at all, you need the theme hook, to show the content using the tpl.php of you choose:

 

/**

 * Implements hook_theme().

 */

function mymodule_theme($existing, $type, $theme, $path){

$path = drupal_get_path('module', 'mymodule'); // . '/templates';

// ADD THE templates DIRECTORY

$path = $path . '/templates'; 

return array(

// as in 'theme('verbose_method',...)

'main_reviews' => array(

'template' => 'main_page_reviews',

'path' => $path,

'variables' => array('forums' => NULL, 'topics' => NULL,'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),

),

//...

);

}

 

And, ending with the magic:

 

/**

 * List of  reviewable products

 *

 */

function listofProducts(){

$output = theme('list_products');

return $output;

}

That's all. If you forget the _theme hook you can be struggling for hours, just receiving a beauty WSOD (White Screen Of the Death) and no more information.

You wellcome :-).

 

Solving error 500 in Symfony2

Having the typical error 500 in Symfony2? Well, it is very tipical, not just in Symfony but in Drupal and other web frameworks and CMS. Solving it can be a big headache... if you don't know where to see.

In Drupal it is easy to solve it using show all errors in php (on index.php of Drupal, for example). In Symfony2 you can use this tip:

Go to the root of your app. Then execute a clean cache:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }php app/console cache:clear{/syntaxhighlighter}What we achieve with that is being able to see error messages on console, after you execute this command. Messages that you will not allways see en error.logs of apache or ngnix.

categorias: 

Symfony2: Not a git repository

Ok, you want to install a bundly in Symfony2, and you are going to use git. You go to your root directory... but, here is the problem

Command:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }git submodule add git://github.com/simplepie/simplepie.git vendor/simplepie{/syntaxhighlighter}

Yes, it's Simplepie bundles for Symfony2. Ok, the error:

 

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }fatal: Not a git repository (or any of the parent directories): .git{/syntaxhighlighter}

It's quite simple. You don't have initialized git:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }$git init
> Initialized empty Git repository in /var/www/symlabs/[project]/.git/
{/syntaxhighlighter}

Try again and... Yes, you welcome :-)

 

categorias: