Bash-Only Deployment

49
Bash-Only Deployment Andrea Francia

Transcript of Bash-Only Deployment

Page 1: Bash-Only Deployment

Bash-Only Deployment

Andrea Francia

Page 2: Bash-Only Deployment

Introduzione

Page 3: Bash-Only Deployment

A cosa ci serve avere il deploy automatico?

chiedere al pubblico

Page 4: Bash-Only Deployment

Scrivere un sistema di orchestration

Page 5: Bash-Only Deployment

Perché non usare la Bash?

chiedere al pubblico

Page 6: Bash-Only Deployment

Perché usare la Bash?

Page 7: Bash-Only Deployment

è onnipresente(e anche preinstallata su tutti(*) i sistemi operativi)

Page 8: Bash-Only Deployment

non ha dipendenze (*)(continua a funzionare anche dopo che hai incasinato tutte le gemme

di ruby)

Page 9: Bash-Only Deployment

fa una cosa sola(la maggior parte delle persone la

usa senza aver mai aperto il manuale)

Page 10: Bash-Only Deployment

è stabile(è già fuori moda)

https://twitter.com/Dreamoid/status/436974284666179584

Page 11: Bash-Only Deployment

Cosa vediamo oggi?

• Poor Mans Testing (in Bash) • Idempotenza (in Bash) • Deployment (over SSH)

Page 12: Bash-Only Deployment

Poor Mans Testing

Page 13: Bash-Only Deployment

Cos'è il testing automatico?

Page 14: Bash-Only Deployment

Perché può essere utile in Bash?

Page 15: Bash-Only Deployment

Come si fa? (DEMO)

Page 16: Bash-Only Deployment

Idempotenza

Page 17: Bash-Only Deployment

Qual è il problema con il deploy non idempotenti?

chiedere al pubblico

Page 18: Bash-Only Deployment

Cosa vuol dire idempotenza?

chiedere al pubblico

Page 19: Bash-Only Deployment

Uno script di deploy è idempotente è come lavarsi le mani, la prima

volta che le lavi diventano pulite, la seconda restano pulite

Page 20: Bash-Only Deployment

mkdir cartella

Page 21: Bash-Only Deployment
Page 22: Bash-Only Deployment
Page 23: Bash-Only Deployment

Come risolvere il problema?

Page 24: Bash-Only Deployment

I quattro metodi per ottenere l’idempotenza

Page 25: Bash-Only Deployment

Metodo 1: la ruspa

Page 26: Bash-Only Deployment

Metodo 2: la sonda

Page 27: Bash-Only Deployment

Metodo 3: la sovrascrittura

Page 28: Bash-Only Deployment

Metodo 4: l’opzione segreta (aka: Usare comandi già idempotenti)

Page 29: Bash-Only Deployment

“Metodo” 5(*): la finta

• (*) C’è un motivo perché questo è il 5^ metodo di quattro. Non a caso si chiama “la finta”!.

Page 30: Bash-Only Deployment

Esempi con apt-get

Page 31: Bash-Only Deployment
Page 32: Bash-Only Deployment

Altri esempi con apt-get

• unzip -h > /dev/null || sudo apt-get install unzip -y

• git --help > /dev/null || sudo apt-get install git -y

• nginx -v || sudo apt-get install nginx -y

Page 33: Bash-Only Deployment

Esempi con i symlinks

Page 34: Bash-Only Deployment
Page 35: Bash-Only Deployment

Una soluzione

Page 36: Bash-Only Deployment

Altra soluzione

Page 37: Bash-Only Deployment

Qual è la soluzione migliore?

Page 38: Bash-Only Deployment

Alcuni comandi sono già idempotenti di natura

• chown -R qmaill:root /var/log/qmail

• chmod -R 750 /var/log/qmail

Page 39: Bash-Only Deployment

Approfondimenti

• Aggiungere una riga al file hosts in modo idempotente (vedi file idempotenza-file-hosts.txt)

• Creare un repository Git in modo idempotente (vedi file idempotenza-git-repo.txt)

• Creare utenti in modo idempotenti.

Page 40: Bash-Only Deployment

Deployment con Bash+SSH

Page 41: Bash-Only Deployment

Deployment o Provisioning?

chiedere al pubblico

Page 42: Bash-Only Deployment

Cosa intendo io con Deployment

Page 43: Bash-Only Deployment

Quali sono i problemi da risolvere?

Page 44: Bash-Only Deployment

Come lo faccio io? (DEMO)

Page 45: Bash-Only Deployment

Recap

Page 46: Bash-Only Deployment

Cosa abbiamo visto?

• Testing in Bash

• Idempotenza in Bash

• Deployment con solo SSH+Bash

Page 47: Bash-Only Deployment

Prossime puntate?

• Roundtrip code deploy using git over SSH

• Fully automated package installation

• Test Driven Development in Bash

• … altro?

http://andreafrancia.it/devops.html

Page 48: Bash-Only Deployment

Conclusioni

• La Bash è stupida (… o è semplice?)

• La Bash è vecchia (… è matura?)

• La Bash è brutta (… o tiene lontano i cacciatori di medaglie?)

Page 49: Bash-Only Deployment

Q/A@andreafrancia

[email protected] +39 3209437233