Outils pour utilisateurs

Outils du site


issue101:c_c

For any reader who has ever developed anything that needed to be tested or run on a system outside of the local development server or workstation, you’ve probably hoped for an easy way to control a test environment, or to emulate the target server. This is essentially what vagrant wants to offer. It’s a tool that creates a configuration file for a server - specifications, OS, what to install, and links to the sources (such as ISOs). This is then run through vagrant, which created a VirtualBox virtual machine running everything outlined in the vagrant file.

Pour tous les lecteurs qui ont développé quelque chose qui a besoin d'être testé sur un système extérieur au serveur de développement local ou à la station de travail, vous avez probablement rêvé d'une façon simple de contrôler un environnement de test ou d'émuler le serveur cible. C'est essentiellement ce que Vagrant propose. C'est un outil qui crée un fichier de configuration pour un serveur : les spécifications, l'OS, ce qu'il faut installer et les liens vers les sources (telles que des ISO). On l'essaie alors via Vagrant qui crée une machine virtuelle VirtualBox qui va exécuter tout ce qui est listé dans le fichier Vagrant.

Now…you may be asking yourself why you wouldn’t just do this by hand? If you’re going to need the development server on and off (such as web development, where certain combinations of software and OSes, or particular versions are common), or if you need to be able to pass the exact development environment to other people. Such as when working in a team. This way, you can just share the vagrantfile (and, possibly, the source files), and the other team members will be up and running swiftly.

Maintenant… vous pourriez vous demander pourquoi ne pas le faire tout simplement à la main ? Si vous allez avoir besoin d'allumer et d'éteindre le serveur de développement (tel qu'un développement sur le Web, où certaines combinaisons de logiciels et d'OS, ou des versions particulières sont fréquentes) ou si vous avez besoin de transmettre l'environnement de développement exact à d'autres personnes, dans un travail en équipe, vous pourrez alors juste échanger le Vagrantfile (et probablement les fichiers source) et les autres membres de l'équipe pourront démarrer rapidement.

Vagrant also handles certain aspects - such as installing guest additions, enabling SSH access, and various other aspects. It also ensures the networking interface is bridged, so that you can access software running on the server from your local network. For anyone who uses a local Apache install and virtual hosts for their web projects, this is one way of creating virtual machines of your server. Running the actual software you’ll encounter on deployment. If you, like me, tend to delete virtual machines the moment you’re done with them because they’re hogging your hard drive space, Vagrant is a perfect match. Keep the vagrantfile, and delete everything else. Space saved!

Vagrant gère aussi certaines particularités, telles qu'installer un invité et ses options, permettre l'accès SSH et divers autres aspects. Il assure aussi que l'interface réseau est reliée et que vous pourrez donc accéder à des logiciels tournant sur le serveur depuis votre réseau local. Pour tous ceux qui utilisent une installation Apache locale et des hôtes virtuels pour leur projet Internet, c'est une façon de créer des machines virtuelles sur vos serveurs. Utiliser le logiciel va vous aider pour le déploiement. Si vous, comme moi, avez tendance à détruire les machines virtuelles au moment où vous n'en avez plus besoin parce qu'elles monopolisent votre espace disque, Vagrant est parfait. Vous conservez simplement le Vagrantfile et effacez tous le reste. Économie d'espace !

How does it work?

Comment cela fonctionne-t-il ?

Vagrant must be installed (it’s a command-line tool), as well as VirtualBox. In Ubuntu it’s as simple as sudo apt-get install vagrant virtualbox. If you’re using a different host OS, you’ll need to check how best to install them.

Vagrant doit être installé (c'est un outil qui utilise la ligne de commande), de même que VirtualBox. Sous Ubuntu, c'est aussi simple que sudo apt-get install vagrant virtualbox. Si vous utilisez une autre distribution, vous devrez chercher la meilleure façon de les installer.

Once Vagrant is installed, you can either download a Vagrantfile (there are many posted on github, or on http://www.vagrantbox.es/), or create one yourself. Creating one on your own is something I haven’t yet done. As such, we’ll focus on the more common scenario of using a pre-built Vagrantfile. If there is interest in creating custom Vagrantfiles, send me an email, and I will follow up this article at a later date. A rough scenario is using vagrant init, and then adjusting the default Vagrantfile to suit your needs.

Une fois que Vagrant est installé, vous pouvez soit télécharger un Vagrantfile (on en trouve beaucoup sur github ou sur http://www.vagrantbox.es/), soit en créer un vous-même. Créer son propre fichier est quelque chose que je n'ai pas encore fait. Pour l'instant, nous allons nous focaliser sur le scénario le plus commun qui consiste à utiliser un Vagrantfile existant. Si utiliser son propre fichier Vagrant présente quelque intérêt, envoyez-moi un courriel et j'écrirai une suite à cet article plus tard. Une approche basique consiste à utiliser la commande « vagrant init », puis d'ajuster le Vagrantfile créé par défaut pour satisfaire vos besoins.

Getting started

Commençons

For the sake of this article, I’ll be using a prebuilt Vagrantfile called “django-python3-vagrant”. See the Further Reading for a link.

Pour les besoins de cet article, j'utiliserai un Vagrantfile préfabriqué nommé « django-python3-vagrant ». Voir le lien dans les lectures complémentaires en fin d'article.

Download the file:

Téléchargez le fichier :

git clone https://github.com/FlipperPA/django-python3-vagrant.git

git clone https://github.com/FlipperPA/django-python3-vagrant.git

Then cd into the folder:

Puis déplacez-vous dans le dossier :

cd django-python3-vagrant

cd django-python3-vagrant

Unfortunately, this vagrantfile is geared towards utopic - which is no longer located on the Ubuntu server. So, time to edit the Vagrantfile !

Malheureusement, ce Vagrantfile a été écrit pour Utopic, qui ne se trouve plus sur les serveurs Ubuntu. Il va donc falloir éditer le Vagrantfile !

On line 6, you’ll want to change the line from “django_config.vm.box = “utopic64”” to “django_config.vm.box = “trusty64””.

En ligne 6 vous devrez modifier « jango_config.vm.box = “utopic64” » en « django_config.vm.box = “trusty64” »

Replace line 10 with the following:

Remplacez la ligne 10 par ce qui suit :

django_config.vm.box_url = “https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

django_config.vm.box_url = “https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

Here, you need to run: vagrant up Once that command finishes running, you can log into the VM using vagrant ssh Upon login, you’ll be greeted by some instructions on creating a django project. Follow them. However, on the runserver step, you’ll need to replace 0.0.0.0:8000 with the actual IP of the server. Find this using ipconfig. For example: python manage.py runserver 192.168.1.200:8000

Là vous allez devoir exécuter :

vagrant up

Quand cette commande se termine, vous pourrez entrer dans la machine virtuelle en tapant :

vagrant ssh

Une fois connecté, vous serez accueilli par quelques instructions vous indiquant comment créer un projet django. Suivez-les. Toutefois, sur l'instruction runserver vous allez devoir remplacer 0.0.0.0:8000 par l'IP du serveur. Trouvez-la en utilisant ipconfig. Par exemple : python manage.py runserver 192.168.1.200:8000

After that, you can access the django instance using the IP address of the server. To stop the VM: vagrant halt In previous versions, this was vagrant shutdown. So if halt doesn’t work for you, try shutdown. To delete the VM: vagrant destroy

Après cela vous pouvez accéder à l'instance de django en utilisant l'adresse IP du serveur.

Pour arrêter la machine virtuelle (VM) :

vagrant halt

Dans les versions précédentes la commande était shutdown. Donc si halt ne fonctionne pas dans votre cas, essayez shutdown.

Pour détruire la machine virtuelle :

vagrant destroy

If you run into issues, make sure of the following things: • You’re using the right IP in both your browser, and the runserver command. • You’re running the vagrant commands from the folder that contains the Vagrantfile Hopefully, this will be of use to anyone who need to frequently create the same (or similar) virtual machines. If you have questions, comments, or suggestions, feel free to contact me at lswest34+fcm@gmail.com. Have a Vagrantfile you can’t live without? Or a Vagrant tip that saves time? Email them to me, and I’ll compile them into an article.

Si vous rencontrez des problèmes, assurez-vous des éléments suivants :

- vous utilisez la bonne adresse IP à la fois dans votre navigateur et dans la commande runserver ;

- vous lancez les commandes vagrant depuis le dossier qui contient le Vagrantfile.

Normalement, ceci devrait être utile pour toute personne qui a besoin de créer fréquemment la même machine virtuelle (ou une machine approchante). Si vous avez des questions, des commentaires ou des suggestions, n'hésitez pas à me contacter à lswest34+fcm@gmail.com. Vous avez un Vagrantfile tout à fait indispensable ? Ou une astuce sur Vagrant qui permet de gagner du temps ? Envoyez-moi un courriel et je rassemblerai toutes ces idées dans un article.

Further Reading

Pour aller plus loin :

https://github.com/FlipperPA/django-python3-vagrant - Vagrantfile

http://vagrantbox.es - des box pré-construites

https://www.vagrantup.com/ - page d'accueil de Vagrant

issue101/c_c.txt · Dernière modification : 2015/10/05 17:50 de auntiee