Precisa de um ambiente que simule o servidor onde fará o deploy do projeto? Cansado de lidar com as diferenças entre sistemas operacionais, versões etc?
Esta semana tive a oportunidade de conhecer o Vagrant. Um sistema que trabalha com a API do Virtual Box. Nele é possível de uma maneira fácil criar uma máquina virtual com as características que precisar para simular o ambiente online.
O tutorial abaixo mostra um resumo do que li a respeito para criar uma VM com Ubuntu, python2.6, virtualenv, etc.
- Baixe e instale a Oracle VM Virtual Box (https://www.virtualbox.org/wiki/Downloads)
- Baixe e instale o Ruby (http://rubyinstaller.org/downloads/)
- Baixe o Development Kit (http://rubyinstaller.org/downloads/)
- Installation Instructions (https://github.com/oneclick/rubyinstaller/wiki/Development-Kit)
- While installation is (in general) simple, please ensure you carefully follow each step below.
- Preparation
- If you previously installed the legacy DevKit devkit-3.4.5r3-20091110.7z, its artifacts were extracted into each Ruby installation and need to be manually removed. Remove the gcc.bat, make.bat, and sh.bat stub batch files in <RUBY_INSTALL_DIR>\bin and the <RUBY_INSTALL_DIR>\devkit subdirectory for each Ruby installation using the legacy DevKit.
- If you previously installed one of the legacy self-extracting DevKit’s, follow the SFX DevKit upgrade instructions.
- Download Files
- The current DevKit is available at the RubyInstaller download page with older versions available at the archives page. As backup, check our GitHub downloads page.
- Extract Files
- Left double-click the self-extracting executable (SFX) downloaded from Step 2 and choose a directory (without spaces) to install the DevKit artifacts into. For example, C:\DevKit. NOTE: the SFX is really a 7-Zip archive with a bit of embedded magic. If you already have 7-Zip installed, you can simply right-click it and extract it’s contents as you would a normal 7z archive. In the instructions that follow, the directory that you selected is identified as <DEVKIT_INSTALL_DIR>.
- Run Installation Scripts
- cd <DEVKIT_INSTALL_DIR> from Step 3 above.
- ruby dk.rb init to generate the config.yml file to be used later in this Step. Your installed Rubies will be listed there (only those installed by a RubyInstaller package are detected at present).
- edit the generated config.yml file to include installed Rubies not automagically discovered or remove Rubies you do not want to use the DevKit with.
- [optional] ruby dk.rb review to review the list of Rubies to be enhanced to use the DevKit and verify the changes you made to it are correct.
- finally, ruby dk.rb install to DevKit enhance your installed Rubies. This step installs (or updates) an operating_system.rb file into the relevant directory needed to implement a RubyGems pre_install hook and a devkit.rb helper library file into <RUBY_INSTALL_DIR>\lib\ruby\site_ruby. NOTE: you may need to use the --force option to update (with backup of the originals) the above mentioned files as discussed at the SFX DevKit upgrade FAQ entry.
- Test Installation
- Confirm your Ruby environment is correctly using the DevKit by running gem install rdiscount --platform=ruby. RDiscount should install correctly and you should see Temporarily enhancing PATH to include DevKit... in the screen messages. Next run ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html" to confirm that the rdiscount gem is working.
- Adicione o caminho da pasta bin do ruby da instalção feita no Path. Ex. C:\Ruby193\bin
- Execute o comando: gem install vagrant
- Antes de criar sua maquina, crie uma pasta para abrigar os arquivos de configuraçao:
- mkdir vagrant-machine
- cd vagrant-machine
- vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
- vagrant init lucid32
- vagrant up
- Acesse via ssh a maquina virtual:
- pelo putty, conecte em vagrant@127.0.0.1 na porta 2222, com a senha vagrant
- Instale os pacotes de desenvolvimento:
- sudo apt-get install python2.6 python2.6-dev libxml2-dev libxslt1-dev python-libxml2 python-setuptools git-core build-essential libxml2-dev libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev libgeoip-dev memcached libmemcached-dev python-mysqldb libmysqlclient16-dev python-virtualenv
- Se por ventura der algo errado, tente o mesmo comando acima mas adicione no fim o --fix-missing
- É necessário a instalação de alguns pacotes para tudo funcionar perfeitamente, além dos acima. Execute os comandos abaixo, caso não instalar como comando acima:
- sudo apt-get update
- sudo apt-get install mysql-client
- sudo apt-get install libmysqlclient16-dev
- sudo apt-get install python-virtualenv
- sudo apt-get build-dep python-imaging
- Vá até a home do usuário e rode o comando abaixo para atualizar o apt-get e outros pacotes:
- sudo sh postinstall.sh
- Vá no VagrantFile no diretorio que instalou o passo 6.a e edite.
- Descomente a linha: # config.vm.forward_port 80, 8080 e configure para as portas que deseja utilizar no windows quando rodar os projetos. Ex:
- config.vm.forward_port 8000, 8000
- # config.vm.forward_port 9000, 9000
- Reinicie o Vagrant com o comando: vagrant reload no seu prompt do windows
O tutorial acima funciona e estou utilizando-o a muito tempo. Depois de um tempo, apareceu a seguinte mensagem:
New release 'precise' available.
Run 'do-release-upgrade' to upgrade to it.
Tentei atualizar e tive problemas. Perdeu-se o compartilhamento da pasta com o Windows, bem como problemas para instalação dos pacotes PIL e MySQL-python.
Resolvi com a reinstalação do começo, sem fazer esta atualização.
hasta!
Nenhum comentário:
Postar um comentário