Skip to content

Commit e1f54a2

Browse files
committed
Add vagrant post part 1
1 parent 6d11c3e commit e1f54a2

File tree

3 files changed

+105
-11
lines changed

3 files changed

+105
-11
lines changed

Gemfile.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GEM
55
public_suffix (~> 2.0, >= 2.0.2)
66
colorator (1.1.0)
77
ffi (1.9.17)
8+
ffi (1.9.17-x86-mingw32)
89
forwardable-extended (2.6.0)
910
jekyll (3.4.0)
1011
addressable (~> 2.4)
@@ -42,9 +43,15 @@ GEM
4243
rouge (1.11.1)
4344
safe_yaml (1.0.4)
4445
sass (3.4.23)
46+
thread_safe (0.3.6)
47+
tzinfo (1.2.3)
48+
thread_safe (~> 0.1)
49+
tzinfo-data (1.2017.2)
50+
tzinfo (>= 1.0.0)
4551

4652
PLATFORMS
4753
ruby
54+
x86-mingw32
4855

4956
DEPENDENCIES
5057
jekyll (= 3.4.0)
@@ -54,7 +61,7 @@ DEPENDENCIES
5461
tzinfo-data
5562

5663
RUBY VERSION
57-
ruby 2.0.0p648
64+
ruby 2.3.3p222
5865

5966
BUNDLED WITH
60-
1.14.3
67+
1.14.6

_posts/2017-02-13-about-this-blog.markdown

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
layout: post
3+
title: "Vagrant kick start tips"
4+
date: 2017-04-24 09:40:49 -0500
5+
categories: vagrant
6+
tags: general
7+
---
8+
# Kick start with vagrant
9+
10+
[Vagrant](https://www.vagrantup.com/intro/index.html) is popular tool used for helping local development and testing. Here are some tips that has been very useful for me when setting up and using Vagrant
11+
12+
## Use box file
13+
14+
A common practice when using vagrant is to use shell script to provision the vm, for example:
15+
16+
in Vagrantfile
17+
18+
{% highlight ruby %}
19+
vm4.vm.provision "shell", path: "VagrantProvision/provision_centos7.sh"
20+
{% endhighlight %}
21+
22+
in provision_centos7.sh
23+
24+
{% highlight Bash shell scripts %}
25+
26+
#!/bin/bash
27+
set -x
28+
29+
sudo rpm -iUvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
30+
sudo yum update -y && sudo yum install -y net-tools wget ansible python-docker-py python-prettytable
31+
32+
# More setup ...
33+
34+
{% endhighlight %}
35+
36+
While This is helpful to make sure the changes made to the base image are versioned and can be share within teams, it can be slow when a base box needs to get build every time.
37+
38+
A better way would be to build the box file which just need to build once which will speed up the vm start up time significantly.
39+
40+
First, let's define our base image in Vagrantfile:
41+
42+
Here we use centos 7 as an example:
43+
44+
{% highlight ruby %}
45+
46+
config.vm.define "base" do |base|
47+
config.vm.provider :virtualbox do |vb|
48+
vb.name = "base"
49+
end
50+
base.vm.box = "centos/7"
51+
# config local network
52+
base.vm.network "private_network", ip: "192.168.3.9"
53+
base.vm.provision "shell", path: "VagrantProvision/provision_centos7.sh"
54+
end
55+
56+
{% endhighlight %}
57+
58+
Sample script for building box file :
59+
60+
{% highlight Bash shell scripts %}
61+
62+
echo "creating dir to hold box file ..."
63+
mkdir Boxes
64+
65+
echo "making sure base vm is down ..."
66+
vagrant destroy -f base
67+
68+
echo "starting base vm ..."
69+
vagrant up base
70+
71+
echo "starting cleaning up old box file ..."
72+
rm -f Boxes/centos7.box
73+
vagrant box remove --force file://Boxes/centos7.box
74+
75+
echo "packing the new image into Boxes/centos7.box"
76+
vagrant package --base base -o Boxes/centos7.box
77+
78+
echo "cleaning up base vm ..."
79+
vagrant destroy -f base
80+
81+
{% endhighlight %}
82+
83+
After the box file is build, change the vagrant file to refer to the local box file:
84+
85+
{% highlight ruby %}
86+
vm1.vm.box = "file://Boxes/centos7.box"
87+
{% endhighlight %}
88+
89+
Here we can skip the provisioning step when start the vm since all the changes needed as pre-build in the box file
90+
91+
92+
## Set up http proxy for vm
93+
94+
## Separate vm definition from Vagrant code
95+
96+
## Use vagrant cacher to speed up provision time

0 commit comments

Comments
 (0)