Create your own git server easily with Chef and the Vagrant AWS plugin: Part 1.
- Part 1: Get the latest Chef on your EC2 target.
- Part 2: Install your private Git server.
- Part 3: Automatically backup your repositories to S3.
Table of Contents
Free private git server with unlimited repositories?
Remove the enslavement of having a private Github account. Gitolite is an open source git server in which you may have as many repositories as you desire. In this series of articles I will demonstrate how to create a git server on EC2 that is automatically backed up to S3. If you are a new signup to Amazon Web Services (AWS), a micro EC2 instance and up to 5 GBs of S3 storage are free for the first 12 months.
Why use Vagrant?
With the introduction of the Vagrant AWS plugin (and hopefully many more provider plugins to follow), Vagrant is no longer just for creating and managing development environments. Here are some reasons why Vagrant is useful managing non-development environments:
- You don't have to manually rsync provisioner changes to the production server as Vagrant does that automatically.
- You can easily integrate
ENVvariables with the provisioning tool.
- Handy vagrant commands such as
vagrant provision, and
vagrant destroyjust work.
- Encourages a faster work flow where you first develop your provisioner recipes on a local provider (Virtualbox, VMWare) and then deploy to the production provider (AWS, Rackspace, etc).
- With respect to the Vagrant AWS plugin you can manage multiple machines in different regions.
Part 1 Goal. Get the latest Chef on your EC2 target.
- Sign up with AWS and create your keypair and security group. Follow this article to the tee. For the security group you only have to enable port 22 for SSH access. Make sure you download your AWS security credentials and private key.
- Fill in the below environmental variables in
~/.profile— or other place you prefer — with the AWS credentials and private key from Step 1. Also add a path to your local public ssh key as this is going to be used later when setting up the git server.
- Make a directory for Vagrant workspaces. Personally, I use a directory called
- Make sure you have the latest Vagrant version, which at the time of this writing is
1.3.3. I don't guarantee anything in this article unless at least Vagrant
- Install Berkshelf. Berkshelf aids in managing and creating Chef cookbooks. Version at the time of this writing is
- Install Vagrant plugins.
- Install a Berkshelf cookbook boilerplate.
- Install a Vagrant box set with an AWS provider.
- Remove the Berkshelf generated Vagrantfile with this one.
- Ready to
vagrant up! Actually, it is
vagrant up --provider=awsand don't forget the
- Last, test the assertions made in the previous step.
# Just an EXAMPLE export AWS_ACCESS_KEY_ID="********************" export AWS_SECRET_ACCESS_KEY="****************" export AWS_KEYPAIR_NAME="my-key-pair-here" export MY_PUBLIC_SSH_KEY_PATH=$HOME/.ssh/id_rsa.pub export MY_PRIVATE_AWS_SSH_KEY_PATH=$HOME/.ssh/aws.pem
source ~/.profilein the command window/pane you intend to the run
vagrant up --provider=aws(see below).
$ mkdir ~/WorkSpaces
$ gem install berkshelf
$ vagrant plugin install vagrant-aws # (0.3.0) $ vagrant plugin install vagrant-berkshelf # (1.3.3) $ vagrant plugin install vagrant-omnibus # (1.1.1)
vagrant-awsplugin handles communication with an EC2 or VPC instance. The
vagrant-berkshelfplugin integrates Berkshelf with Vagrant, and the
vagrant-omnibusplugin handles installing the latest Chef on your target.
$ cd ~/WorkSpaces $ berks cookbook git-server $ cd git-server $ bundle install
create git-server/files/default create git-server/templates/default create git-server/attributes create git-server/definitions create git-server/libraries create git-server/providers create git-server/recipes create git-server/resources create git-server/recipes/default.rb create git-server/metadata.rb create git-server/LICENSE create git-server/README.md create git-server/Berksfile create git-server/Thorfile create git-server/chefignore create git-server/.gitignore run git init from "./git-server" create git-server/Gemfile create git-server/Vagrantfile
berks cookbookcommand will install a bunch of files. Don't be too concerned with what each individual file is for but just know that it creates an orthodox layout for Chef cookbooks and Vagrant projects.
$ vagrant box add aws-basic https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box Downloading or copying the box... Extracting box...e: 0/s, Estimated time remaining: --:--:--) Successfully added box 'aws-basic' with provider 'aws'!
Vagrant.configure("2") do |config| config.vm.hostname = "git-server" config.vm.box = "aws-basic" config.vm.boot_timeout = 120 config.omnibus.chef_version = :latest config.vm.provider :aws do |aws, override| aws.access_key_id = ENV['AWS_ACCESS_KEY_ID'] aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] aws.keypair_name = ENV['AWS_KEYPAIR_NAME'] aws.security_groups = ['your-security-group-here'] aws.instance_type = "t1.micro" aws.ami = "ami-d0f89fb9" override.ssh.username = "ubuntu" override.ssh.private_key_path = ENV['MY_PRIVATE_AWS_SSH_KEY_PATH'] end end
config.vm.boot_timeout = 120gives SSH connections a little more time. The AMI,
ami-d 0f89fb9, is an Ubuntu 12.04 64-bit image for the
us-east-1azone that supports micro instances, which again are free for 12 months if you are a new AWS signup. You can choose a different AMI id here but be forewarned as some of the AMI ids I tested did not work as advertised.
$ vagrant up --provider=aws Bringing machine 'default' up with 'aws' provider... [default] Warning! The AWS provider doesn't support any of the Vagrant high-level network configurations (`config.vm.network`). They will be silently ignored. [default] Launching an instance with the following settings... [default] -- Type: t1.micro [default] -- AMI: ami-c30360aa [default] -- Region: us-east-1 [default] -- Keypair: <your key pair name> [default] -- Security Groups: ["your-security-group-here"] [default] -- Block Device Mapping:  [default] -- Terminate On Shutdown: false [default] Waiting for instance to become "ready"... [default] Waiting for SSH to become available... [default] Machine is booted and ready for use! [default] Rsyncing folder: /Users/christian/WorkSpaces/git-server/ => /vagrant [default] Installing Chef 11.6.0 Omnibus package...
vagrant up --provider=awswill create a new EC2 instance and then install the latest Chef on it via the Vagrantfile
config.omnibus.chef_version = :latestsetting.
vagrant upand not
vagrant up --provider=aws.
vagrant up --provider=awsrun in which an EC2 instance was successfully created you don't need to provide the
--provider=awsswitch to commands such as
vagrant provision, and
vagrant up --provider=awsprocess hangs at the
Waiting for SSH to become available...you either didn't set a security group that has SSH access or your PATH to the AWS private key is incorrect.
vagrant ssh # should login successfully and get the Ubuntu 12.04 banner $ chef-client -v # should output "Chef: 11.6.0" (latest at the time of this writing)
Stay tuned as in part 2 I will build on these steps revealing a drop-dead simple Git server installation.
- Pushed on 09/27/2013 by Christian