diff --git a/HowtoPacker.md b/HowtoPacker.md new file mode 100644 index 00000000..155aa6a6 --- /dev/null +++ b/HowtoPacker.md @@ -0,0 +1,134 @@ +# HowtoPacker + +Packer est un outil permettant de créer des images identiques destinées à +différentes plateformes à partir d'une configuration unique. + +# Terminologie + +## Builder +Composant permettant de créer une image pour une plateforme donnée. Le résultat +d'un build est nommé un *artifact*. + +(Amazon EC2, Azure, Docker, QEMU, VirtualBox, VMWare, DigitalOcean, etc.) + +## Provisionner +Composant permettant de configurer une image suite au build. + +(Ansible, Chef, Puppet, Salt, Shell, etc.) + +## Post-processor +Composant prenant comme entrée le résultat d'un build ou d'un autre post-processor +pour créer un nouvel *artifact*. + +**Examples** +- [Vagrant] Créer une box vagrant pour VirtualBox en utilisant l'*artifact* du +builder VirtualBox. +- [Atlas] Envoyer une box vagrant vers Atlas. +- [Docker Tag] Tagger l'image résultant d'un build Docker. +- [Docker Push] Envoyer une image Docker vers un registry (Docker Hub). + +## Template +Fichier JSON définissant les paramètres de tous les composants énumérés +précedemment. + +**Exemple** +```json +{ + "variables": { + "atlas_token": "xxxxxxxx" + }, + "builders": [ + { + "type": "virtualbox-iso", + "vm_name": "evolinux-debian-8.7.1-amd64", + "guest_os_type": "Debian_64", + "iso_url": "https://cdimage.debian.org/debian-cd/8.7.1/amd64/iso-cd/debian-8.7.1-amd64-netinst.iso", + "iso_checksum": "453312bf56fc45669fec5ebc0f025ac7", + "iso_checksum_type": "md5", + "disk_size": 10240, + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_wait_timeout": "10000s", + "headless": true, + "boot_wait": "10s", + "http_directory": "preseed", + "boot_command": [ + "", + "auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/jessie.cfg ", + "" + ], + "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now", + "vboxmanage": [ + [ "modifyvm", "{{.Name}}", "--memory", "512" ], + [ "modifyvm", "{{.Name}}", "--cpus", "1" ] + ] + }, + { + "type": "docker", + "image": "buildpack-deps:jessie", + "commit": true + } + ], + "provisioners": [ + { + "only": ["docker"], + "type": "ansible", + "playbook_file": "./docker.yml", + "groups": ["ansible-test"] + }, + { + "only": ["virtualbox-iso"], + "type": "ansible", + "playbook_file": "./playbook.yml", + "groups": ["ansible-test"] + } + ], + "post-processors": [ + [{ + "type": "vagrant", + "compression_level": "9", + "output": "debian-{{user `debian_version`}}-amd64_{{.Provider}}.box", + "only": ["virtualbox-iso"] + }, + { + "type": "atlas", + "token": "{{user `atlas_token`}}", + "artifact": "evolix/evolinux", + "artifact_type": "vagrant.box", + "metadata": { + "created_at": "{{timestamp}}", + "provider": "virtualbox" + } + }], + [ + { + "type": "docker-import", + "repository": "evolix/evolinux-base", + "tag": "latest" + }, + "docker-push" + ] + ] +} +``` + +## Utilisation + +### Valider un template +`$ packer validate