Seminario team working - 21-1-2015

Post on 16-Jul-2015

327 views 0 download

transcript

Sviluppare in TeamAlessandro Loffredo

Sviluppare in Team

• Condivisione codice

• Condivisione ambiente

• Linguaggio PHP

• HTTP debug

• Esempio PHP + IaaS

Ambienti di esecuzione

• Sviluppo

• Test

• Produzione

• Opzionali: Staging, Demo..

Condivisone del Codice

Version Control Systems

• Tracciare la storia del codice sorgente (e non solo)

• Gestire l’accesso concorrente in scrittura

• Mantenere versioni diverse dello stesso codice

Version Control Systems

• Centralizzati (CVS, SVN..)

- 2 metodi: “file locking” e “version merging”

- repository centrale (single point of failure)

• Distribuiti (Git, Mercurial, Bazaar..)

- molteplici repository “centrali” (locali)

- veloce (operazioni in locale)

Git

• Sviluppato inizialmente da Linus Torvalds per mantenere i sorgenti di Linux

• Ideale per il versionamento di contenuti testuali

• Largamente diffuso (secondo dopo Subversion)

Git - Branching e Merging

Git - Workflow multipliSubversion-Style Workflow Integration Manager Workflow (GitHub)

Dictator and Lieutenants Workflow

Git - Staging Area

Git - git init

Git - git add

Git - git commit

Git - git add

Git - git remote add

Git - git push

Git - git pull

Git - .gitignore# C project*.o*.so*.a*.out

# Java project*.class*.jar*.war

# Directorybin/

# Editor backups*~

Condivisone ambiente di sviluppo

Condivisone ambiente di sviluppo

Ossia l’ambiente (gli ambienti) dove verrà eseguito il progetto in fase di sviluppo

• Configurazione hardware

• Sistema operativo

• Software e librerie installate

• Uno strumento per creare ambienti di sviluppo basati si macchine virtuali

• Studiato con l’obiettivo di creare ambienti simili o identici a quelli dei server in produzione

• Creato da M. Hashimoto

• Supporta VirtualBox e VMWare Fusion

Vagrant - Installazione

1.VirtualBox

2.Vagrant installer (Linux, Windows, OSX ecc..)

3.Scaricare una Vagrant box

Vagrant - Box

• Un’immagine di una macchina virtuale Vagrant pronta all’uso

• Sono disponibili al download Vagrant Box per molte piattaforme (Linux, Windows, BSD)

Vagrant - Comandi

• $ vagrant init #crea un Vagrantfile base

• $ vagrant up #avvia la macchina virtuale (se necessario la crea)

• $ vagrant ssh #accede alla macchina virtuale

• $ vagrant halt #spegne la vm

• $ vagrant destroy #calcella la vm

Vagrant - VagrantfileVAGRANTFILE_API_VERSION  =  "2"  BOX_NAME  =  "trusty64"  BOX_URI  =  "https://cloud-­‐images.ubuntu.com/vagrant/trusty/current.box"  

Vagrant.configure(VAGRANTFILE_API_VERSION)  do  |config|  

   config.vm.box  =  BOX_NAME      config.vm.box_url  =  BOX_URI      config.vm.network  :forwarded_port,  host:  8080,  guest:  80      config.vm.synced_folder  ".",  "/vagrant",  type:  "nfs"  

   config.vm.provider  :virtualbox  do  |vb|          vb.customize  ["modifyvm",  :id,  "-­‐-­‐memory",  "512"]      end            config.vm.provision  "puppet"  do  |puppet|          puppet.manifests_path  =  "puppet/manifests"          puppet.module_path  =  "puppet/modules"      end  

end  

• Tool per la gestione automatica di infrastrutture

• Gestisce provisioning e configurazione

• Automatizza i task ripetitivi (backup, upgrade..)

Puppet è una (no “la”) soluzione per fare il setup, gestire e aggiornare infrastrutture composte da molteplici server

LAMP Stack

Puppet

Non serve definire il “come”..

.. ma il “cosa”

Puppet - Manifest

Puppet - Package

Puppet - Class

Puppet - Moduli

• In Puppet un modulo è una collezione di risorse (servizi, package..), classi e template.

• Aiutano a distribuire e favoriscono il riuso del codice

• Run out-of-the-box

• GitHub!

Ricapitolando

• Usando Vagrant tutti gli sviluppatori hanno a disposizione lo stesso Sistema Operativo dei server in produzione.

• Usando Puppet/Chef viene garantito che il Sistema Operativo sia configurato in modo identico su una vm con Vagrant, una vm in cloud o un server fisico.

PHPPersonal Home Page (1994)

PHP: Hypertext Preprocessor (1997)

Richiesta di una pagina html statica

GET index.html

<!DOCTYPE html><html> <head> <title>Title</title></head>

<body> <!-- page content --> </body></html>

Client Side

Server Side

Richiesta di una pagina php

GET index.php

<!DOCTYPE html><html> <head> <title>Title</title></head>

<body> <!-- page content --> </body></html>

Client Side

Server Side

PHP - In breve

• Un linguaggio interpretato nato per il web

• Permette di costruire pagine web dinamiche

• Consente di interagire con un database

PHP - Una pagina<html> <head> <title>PHP Test</title> </head> <body> <?php

echo '<p>Ciao mondo!</p>';$ora = date('H:i');echo '<p>Sono le '.$ora.'</p>';

?> </body></html>

PHP - Alcune variabili d’ambiente

• $_SERVER[‘REMOTE_ADDR’]

• $_SERVER['REQUEST_METHOD']

• $_GEThttp://example.com?a=1&b=2&c=d $_GET['a'] == 1 …

• $_POSTContiene le variabili definite nel body della richiesta HTTP

HTTP debug

cURL

CURL is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.

cURL - HTTP GET$ curl -v http://example.com/ * Connected to example.com (93.184.216.34) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.37.1 > Host: example.com > Accept: */* > < HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: max-age=604800 < Content-Type: text/html < Date: Tue, 20 Jan 2015 09:57:54 GMT < Expires: Tue, 27 Jan 2015 09:57:54 GMT < Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT < Server: ECS (iad/182A) < Content-Length: 1270 < <!doctype html> <html> …

cURL - HTTP POST$ curl -v -XPOST -d foo=bar http://example.com/ * Connected to example.com (93.184.216.34) port 80 (#0) > POST / HTTP/1.1 > User-Agent: curl/7.37.1 > Host: example.com > Accept: */* > Content-Length: 7 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 7 out of 7 bytes < HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: max-age=604800 < Content-Type: text/html < Date: Wed, 21 Jan 2015 01:15:04 GMT < Expires: Wed, 28 Jan 2015 01:15:04 GMT < Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT < Server: EOS (lax004/2811) < Content-Length: 1270 < <!doctype html> <html> …

Postman (HTTP client)

Hacker News news.ycombinator.com

alessandro@svloop.com

Riferimenti• http://git-scm.com/about

• https://try.github.io

• http://git-scm.com/book

• http://docs.vagrantup.com/v2/getting-started/index.html

• http://docs.puppetlabs.com/pe/latest/quick_start_helloworld.html

• https://github.com/himerya/vagrant-puppet-lnmp