DevOps is a big word that grown-ups use to talk about making sure that the computer programs they write work well and can be easily changed. It's kind of like building with LEGOs: π§° you want to make sure that all the pieces fit together nicely and that you can take them apart and put them back together again if you need to make changes.
To set up a DevOps environment, we need to use something called the "command line." The command line is like a magic window that lets you talk to the computer and tell it what to do. π±βπ
First, we need to open up the command line on our computer. On a Windows computer, you can do this by searching for Command Prompt
in the start menu. On a Mac, you can use the Terminal
app.
Once you have the command line open, we can start by installing Git. Git is a tool that helps us keep track of changes to our code, like a notebook but for computer programs.
You can install git by typing this command in the command line:
$ git
The $
sign is just a symbol that tells you that this is a command you should type in the command line.
Next, we can use Git to create a new folder on our computer for our DevOps project. We can do this by using the mkdir
command, like this:
$ mkdir devops-project
This command creates a new folder called "devops-project" in the current directory.
Now we can move into the new folder by using the cd
command, like this:
$ cd devops-project
Now that we are inside the devops-project folder, we can create a new file called main.py using the touch command:
$ touch main.py
Great! Now we have a new file called main.py
in our devops-project folder. This is where we will be writing our code.
Now, it is important to make sure our code is safe and doesn't get lost in case something happens to the computer. So, we'll create a remote repository where we will keep our code safe. We can use a website called GitHub to create the remote repository. First, you will have to create an account on GitHub if you haven't already. π
Once you are logged in, you can create a new repository by clicking the +
button in the top-right corner of the screen and selecting New repository
. Give your repository a name, like devops-project
, and click the Create repository
button. π€
Now, you need to link the local repository you created with the remote repository on GitHub. You can do this by using the git remote add
command, like this:
$ git remote add origin https://github.com/username/devops-project.git
Make sure to replace username
with your actual GitHub username.
Once the linking is done, you need to push the files from local to remote repository. For this you can use command:
$ git push -u origin master
Now your code is safe and sound in the remote repository, and you can continue working on your project without worrying
Awesome! Now that our code is safe in the remote repository, we can continue working on our project without worrying about losing it. π₯³
Next, we'll set up a tool called Jenkins to automatically build and test our code. Jenkins is like a robot that helps us make sure that our code works correctly and doesn't have any bugs. π
To install Jenkins, we can use the package manager for our operating system. If you're using a Debian or Ubuntu system, you can use the following command:
$ sudo apt-get update
$ sudo apt-get install Jenkins
On a Windows or Mac system, you can download the Jenkins installer from the official website and run it. Once Jenkins is installed, you can start it by running the following command:
$ service Jenkins start
You can access Jenkins by opening a web browser and going to the following address: http://localhost:8080. π
Once Jenkins is up and running, you'll need to create a new job
for our devops-project. A job is like a set of instructions for Jenkins to follow, telling it what to do with our code. To create a new job, click the New Item
link on the Jenkins home page and give it a name like "devops-project-build."
Under Source Code Management
, select Git
and enter the URL of our remote repository: https://github.com/username/devops-project.git.
Next, select Build when a change is pushed to GitHub
. This tells Jenkins to automatically build our code whenever we push changes to the remote repository.
In the Build
section, add a build step to run your code through test cases if you want. For example, if you are using python you can add a command like this:
$ pytest
Finally, save the job and Jenkins will begin building and testing our code every time we push changes to the remote repository. π¨
This is how we set up a DevOps environment and make sure our code is working well. And this is how Jenkins helps us to automate all the testing and building processes. Isn't that cool? Now you can be an awesome developer too and make amazing programs. πͺ