A DevOps deployment requires quickly provisioned infrastructure that adapts to application needs. The Vagrant VM workflow in the DevOps lab build's first step yielded some files containing code that creates and describes the lab infrastructure. Git version control software, or other preferred infrastructure as code tools, protects that code and archives older versions as we make changes.
A Git commit saves a consistent state -- a separate copy -- of the project on the DevOps lab machine. It enables the user to return to a previous fixed point if changes mess up the code. Learn to use GitHub, a distributed version control platform, as the central repository for infrastructure code, freeing saved versions from only existing on one computer.
⇇ Create a
Before checking in infrastructure as code using Git and GitHub, install Vagrant and spin up the VMs for this DevOps lab as immutable infrastructure. Or start here to get the lab up and running.
Start using Git
Install Git on the lab machine; it might automatically install when git runs for the first time. Have the terminal open in your project folder where the Vagrantfile resides.
Configure Git to let it know who you are with some Git config commands and your name and email address:
Then initialize Git in that folder, add the VagrantFile and commit the current file with the following commands:
Make changes in the DevOps lab freely; you can be confident that the deployment can roll back to this state at any time. Use GitHub to commit any time you make a significant and successful change. Use git add to add any new files. Try wild cards like git add *.sh to add all the shell scripts. During the following DevOps learning exercises, I will remind you to commit changes along the way.
The files for the experiments in this article are available to clone from my GitHub repository:
Clone the files then copy some to your project folder. Then make all of the shell scripts executable:
Author's note: There are a few listings that are too long to include in the text of this article, but are available in the repository.
New to Git and distributed version control? Here are some Git examples and Jenkins-Git integration tutorials designed to help you master the popular source code versioning tool:
- The five basic Git commands beginners need to master
- Undo a commit and manipulate commit history with this git reset --hard example
- Learn to git revert a commit with the bash shell
- Use the git cherry-pick command across Git branches
- Change the Git editor to Notepad++
- Where the Windows Git configuration files are stored
- Learn to integrate Maven plugins, Jenkins and Artifactory
- Make continuous integration part of your DevOps journey with this Jenkins CI tutorial