MediaWiki-Vagrant

From Freephile Wiki
Revision as of 14:31, 3 March 2015 by Freephile (talk | contribs) (describes password login to Console)

Jump to navigation Jump to search

MediaWiki-Vagrant.png

Using mw:MediaWiki-Vagrant, you can setup a development instance of MediaWiki in a snap. Specifically tuned for development of the MediaWiki software, you get all the tools needed to dive right in to coding and patching.

You'll notice in the screenshot that the VM comes pre-configured with shared folders to the host system so that you do not even need to SSH to the VM to see the puppet modules and logs. You can work right on these from your host system.

screenshot showing aspects of the MediaWiki-Vagrant system


Deploy MediaWiki-Vagrant to Amazon[edit | edit source]

How to Deploy your MediaWiki-Vagrant instance to Amazon Web Services (AWS)

There is this article that explains how to do this, but I didn't want to create a separate VagrantFile. After not succeeding, I should probably go back and try that approach.

Using multiple providers (AWS, Rackspace, VirtualBox, VMWare) with the same virtual machine is not a feature of Vagrant. Supposedly this limitation will be removed in a future version of Vagrant. But there is a work-around that you can use to accomplish this -- by creating a multi-machine environment. We are describing that work-around. There are some "cheap" solutions that tell you to either delete, or rename the hidden .virtualbox directory in your project source. Don't do that. That's just deleting the information that you'd need for using the existing provider. Or, only do that if you are trying to permanently switch the provider used in your project -- which is not the case here. To get a fully compatible MediaWiki-Vagrant setup that works for both localhost VirtualBox deployments and cloud Amazon AWS deployments, then read on.

Caveats[edit | edit source]

The MediaWiki-Vagrant setup is designed for local development and NOT for security, so it may not be suitable for running in the cloud.

The MediaWiki-Vagrant box is setup with NFS shares. The Vagrant-aws plugin has nominal support for shared folders using rsync, so sharing the ~/vagrant folder might work, but it's unkown how well this works. And it's unknown exactly how to disable the synced folders in Vagrantfile-extra.rb that is defined in the Vagrantfile

Pre-requisites[edit | edit source]

AWS Account[edit | edit source]

You obviously need an AWS account, which you can get for free. So head over to Amazon and create one. You'll need to create a IAM user and a set of "Access" and "Secret" keys for this user at https://console.aws.amazon.com (Dashboard -> Users -> User Actions -> Manage Access Keys) Hint: if you want another user "Bob" to be able to login to your Amazon Console, they can't just use their email address. You'll want to create a "Login Alias" which is a custom URL for accessing Amazon e.g. https://example.signin.aws.amazon.com/console You also must assign Bob a password in IAM. Then Bob can signin at the Login Alias using the password that you gave him in IAM.

Console Tools[edit | edit source]

It may be helpful to have the command line tools for Elastic Cloud installed so that you can test your connection ability. For Ubuntu,

sudo apt-get install ec2-api-tools
ec2-describe-regions -v --auth-dry-run --aws-access-key KEY --aws-secret-key KEY

Rather than specifying your keys on the command line, you may want to set them in ~/.bashrc and source the file to bring them into your current shell session. [1]

export AWS_ACCESS_KEY=THISISJUSTANEXAMPLE
export AWS_SECRET_KEY=ThisIsNotARealSecretEnterYourSecretHere


Vagrant-AWS Plugin[edit | edit source]

You need the vagrant-aws plugin (https://github.com/mitchellh/vagrant-aws)

cd ~/vagrant
vagrant plugin install vagrant-aws

Status[edit | edit source]

When you do a vagrant status check of your current MediaWiki-Vagrant setup, you'll see something like this:

Current machine states:

default                   poweroff (virtualbox)

The VM is powered off. To restart the VM, simply run `vagrant up`


The machine is called default and the provider is virtualbox.

If your virtual machine is not powered off, then do so with vagrant halt

Boxes[edit | edit source]

Each 'box' in vagrant is specific to a provider, so we'll need to get a new box that will run on AWS.


vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
vagrant box list

You need to create a custom stanza in Vagrantfile-extra.rb[2]

The items you'll need are:

  1. aws.access_key_id
  2. aws.secret_access_key
  3. aws.keypair_name
  4. aws.ami

To get the access_key_id and secret_access_key, you login to your AWS account. Here are the instructions http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html

To get the keypair_name, you need to create (or upload) a keypair into your AWS Console for the region. It's easy to create a keypair in the AWS console, and as soon as you do, it will prompt you to download the .pem file. Save the .pem file to your ~/.ssh/ directory, and ensure the file mode is 400

chmod 400 ~/.ssh/my-aws-keys.pem

Need to find the image (AMI) you want. You can search for Ubuntu images at http://cloud-images.ubuntu.com/locator/ec2/ The latest Ubuntu version used in MediaWiki-Vagrant as of March 2015 is Trusty-Tahr (or 14.04 LTS) You need to choose the region that you want to host in. So for example if you want to host in Oregon state, then you want the "US West" region for Amazon. Searching for "trusty 64 west" we can see several options for the AMD64 architecture

Instance Type hvm:ebs AMI-ID ami-a6b8e7ce


Customize Vagrantfile-extra.rb[edit | edit source]

I tried to customize the Vagrantfile-extra.rb but couldn't quite understand the required structure

 1 # -*- mode: ruby -*-
 2 # vi: set ft=ruby :
 3 #
 4 # Sample 'extra' configuration file for MediaWiki-Vagrant
 5 # -------------------------------------------------------
 6 # http://www.mediawiki.org/wiki/Mediawiki-Vagrant
 7 #
 8 # This file contains examples of some customizations you may wish to
 9 # apply to your virtual machine. To use it, copy this file to its parent
10 # directory (i.e., the repository root directory).
11 #
12 # To apply a customization, uncomment its line by removing the leading
13 # '#'. Then save the file and run 'vagrant halt' followed by 'vagrant up'.
14 #
15 # Useful details about the structure and content of this file can be
16 # found in the Vagrant documentation, at:
17 # <http://docs.vagrantup.com/v2/vagrantfile/index.html>.
18 #
19 VAGRANTFILE_API_VERSION = "2"
20 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
21   
22     config.vm.provider :virtualbox do |vb|
23         # For a full list of options you can pass to 'modifyvm', see
24         # <http://www.virtualbox.org/manual/ch08.html>.
25 
26         # Boot the VM in graphical mode:
27         # vb.gui = true
28 
29         # Increase memory allocation from 768MB to 1GB:
30         # vb.customize ['modifyvm', :id, '--memory', '1024']
31         vb.customize ['modifyvm', :id, '--memory', '2048']
32 
33         # But limit the virtual machine to 1 CPU core:
34         # vb.customize ['modifyvm', :id, '--cpus', '1']
35 
36         # Fix dns resolution problem
37         vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'off']
38         vb.customize ['modifyvm', :id, '--natdnsproxy1', 'off']
39     end
40     
41     # override the box used for MediaWiki-Vagrant with a box for AWS
42     # we added this box at the command-line with 
43     # vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
44     config.vm.define "default_virtualbox"
45     config.vm.define "default_aws", autostart:false do |default_aws|
46       default_aws.vm.box = "dummy"
47     end
48     
49     supported_providers = %w(virtualbox aws)
50     active_provider = ENV['VAGRANT_ACTIVE_PROVIDER'] # it'd be better to get this from the CLI --provider option
51     supported_providers.each do |provider|
52       next unless active_provider.nil? || active_provider == provider
53       config.vm.define "default_#{provider}" do |box|
54         box.vm.provider :aws do |aws, override|
55           aws.access_key_id = 'RedactedSecret'
56           aws.secret_access_key = 'RedactedSecret'
57           aws.keypair_name = "eqt-mw-keys"
58 
59           aws.ami = "ami-7747d01e"
60 
61           override.ssh.username = "ubuntu"
62           override.ssh.private_key_path = "/home/greg/.ssh/eqt-mw-keys.pem"
63         end
64       end
65     end
66     
67     
68 #     config.vm.provider :aws do |aws, override|
69 #         aws.access_key_id = 'RedactedSecret'
70 #         aws.secret_access_key = 'RedactedSecret'
71 #         aws.keypair_name = "eqt-mw-keys"
72 # 
73 #         aws.ami = "ami-7747d01e"
74 # 
75 #         override.ssh.username = "ubuntu"
76 #         override.ssh.private_key_path = "/home/greg/.ssh/eqt-mw-keys.pem"
77 #     end
78     
79     
80 
81 
82 end

Test or Run[edit | edit source]

When you're done with the customizations to the Vagrantfile-extra.rb

vagrant status
## status looks good?
vagrant up --provider=aws


Resources[edit | edit source]

This is the official 'response' to this issue. It offers a gist that supposedly addresses the problem of running multiple providers, but I wasn't able to figure out how to apply that to the MediaWiki-Vagrant setup.

There is a somewhat related issue in Phabricator that requests a web front-end to make deployment easier. https://phabricator.wikimedia.org/T53782


References[edit source]

  1. For some reason, this didn't work for me the first time, so I regenerated keys, and it worked.
  2. Don't edit Vagrantfile since that is distributed by MediaWiki-Vagrant and you won't be able to upgrade your environment