deployment made easy with git

12
Deploy easily! with

Upload: igor-santos

Post on 21-Jan-2017

1.089 views

Category:

Technology


0 download

TRANSCRIPT

Deploy easily!with

Igor SantosWeb developer

● From Rio de Janeiro, Brazil

● PHP Developer for ~6 years

● Ruby and JS Developer for fun

● Playing around with git for ~2 years

slideshare.net/igorsantos07

0. Introduction

● Knows what Git is?● Have ever used Git in the command line?● Have ever deployed code?

○ How? SCP? WGet?● Anyone developing in the production server?

1. Git Basics

● Commit: Saves changes with a description● Pull: Get commits from a server● Push: Send commits to a server● Remotes

○ A remote machine that has a copy of the repository and accepts your commits

○ In a common centralized organization you usually have one, but it's possible to have many

○ Example: main repo is BitBucket or Google Code, mirrored to GitHub

2. Configure your serverigor@local$ ssh [email protected]

password: **********

santos@bluenose$ mkdir repos

santos@bluenose$ cd repos

santos@bluenose$ pwd

/users/cs/santos/repos

santos@bluenose$ git clone «repo» myRep --bare

This creates a clone of that repository that works just as another repository: with all administrative data, but not useable for development, as the code is not really checked in - just the Git meta-data.

Take note

igor@local$ cd dev/myCode

igor@local$ git remote add prod ssh://[email protected]:/users/cs/santos/repos/myRep

igor@local$ "Hi there!" > README.mkd

igor@local$ git commit "+ Adding readme"

igor@local$ git push prod

2. Configure your server

Name given to the remote server

Complete repository URL

No line break!

igor@local$ git commit "+ Adding readme"

igor@local$ git push prod

Q: OK, so... where's my README file?A: In the repository!Q: I can't see it. «not really a question»

2. Configure your server

3. Git Hooks

● 2 types: client and server hooks

● Client:○ pre/post-commit○ [prepare-]commit-msg○ post-checkout, post-merge

● Server:○ pre/post-receive Once per push○ update Once per pushed branch

http://git-scm.com/book/en/Customizing-Git-Git-Hooks

3. Git Hooks

Simple copy

$ cat hooks/post-receive#!/bin/shGIT_WORK_TREE=/var/www/mysite git checkout -f

Opposite of git clone --bare: copies the entire repository code, without git data. By default does that with the master branch, but you can use other options here as well.GIT_WORK_TREE tells git where it would copy stuff.

3. Git HooksComplete deployment scripthttps://bitbucket.org/igorsantos07/calen-do/src/3fea92ee46c1/git-hooks/update

4. Advanced ideas

GitHub and other Git online repositories have options to do HTTP requests with code information after pushes, similar to post-receive hooks. This data can be used to trigger a deployment script in the server.

There's also an online service called DeployHQ, where you can configure any

repository (SVN/Git/Hg) and many deploy methods (FTP/SFTP/S3/Rackspace).

It deploys new code using the chosen method.

4. Adv.ideas

deployhq.com