DevNet Sandbox: CI/CD Sandbox

DevNet Sandbox: CI/CD Sandbox

Hello World Example - Instructions

Sandbox Overview

This Hello World example provides a simple example of CI/CD basic mechanisms and flow.

It doesn't provide exhaustive detail into CI/CD or the tools we use in the Sandbox, rather just provides you with the basic instructions and background to get the idea of the basic interactions and purpose. We recommend you do much more experimentation and learning after we give you your first taste here!

This Sandbox uses our CI/CD DevNet Sandbox toolset / pipeline to create and deploy a minimal Ubuntu image onto Kubernetes.

The tools and pipeline we have put together for you in this Sandbox are shown below:

We'll user these tools in the following hello world instructions to reach our goal of deploying a simple Ubuntu image onto Kubernetes, simply by commiting code to our repository in Gogs.

You can find out more about each one of these tools and this DevNet Sandbox in the Sandbox details within our catalog itself, or via the following the deep link in the email we send you with your connection credentials in it.

Gogs (Internal to the CICD Sandbox)

The Gogs IP address is: http://10.10.20.24:3000

Gogs is a private source code control system anyone can deploy locally, written in Go. We use it as a public GitHub alternative here, so you have your own playground!

You can create, manage and commit your code exactly as you would with github. With this CI/CD Sandbox you can then quickly see your code built into a container and deployed automatically onto Kubernetes by Drone - I.e. use the CI/CD toolchain we have set up for you!

We have pre-configured a Gogs account for you, called 'Test', as part of setting up the Sandbox that you can use, with the credentials test/test.

You can create your own account in Gogs, but you'll need to make Drone aware of this account so it can pick up commits to your code and run the CICD toolchain on them. You might want to have a go at this after the initial Hello World example here.

For this hello world, we'll just use the 'Test' account.

Drone (Internal to the CICD Sandbox)

Drone is located at: http://10.10.20.23

The credentials are test/test

Drone is a CI/CD tool, which can pull your code from Gogs and build/publish/deploy it to Kubernetes nodes or other targets.

The drone account is already aware of our Gogs deployment in this Sandbox, which means you can also use test account, i.e. test/test, with minimal configuration knowledge (or again, you can go ahead and create your own Gogs account, but working with that account is out of scope of this Hello World).



Setting Up the Hello World...


Download Required Example Files

Background

For Drone to be able to know how to execute a CI/CD pipeline for us, it uses three main stages:

There are many other options here, but these are the main items. In this hello world example, we're just going to use Publish and Deploy.

Drone expects these stages to be built into a .yml file. For our Hello World example, we have one here for you to use: https://raw.githubusercontent.com/DevNetSandbox/sbx_cicd/master/drone/.drone.yml

We also need to provide the Docker container image we would normally use to publish to Docker Hub, after our code has been added. This comes in the form of a DockerFile, an example of which for this purpose is available here: https://raw.githubusercontent.com/DevNetSandbox/sbx_cicd/master/drone/Dockerfile

We'll use these two example files for this Hello World and edit them to match your accounts.

Instructions

We provide a dedicated Linux DevBox which contains few toolchains for development. The details tools installed can be found in the tab details of your Sandbox. They include git command line tools, which work with Gogs.

Note that the .drone.yml file will be hidden, but it will be there in your new directory. In the terminal window try ls -la to view hidden files, too.

Editing the Drone Pipeline .YML file for our CICD Pipeline Example

Background

We need to edit the Drone .yml file that Drone will use to be able to automate:

Instructions

We provide a dedicated Linux DevBox which contains few toolchains for development. The details tools installed can be found in the tab details of your Sandbox. They include git command line tools, which work with Gogs.

pipeline:
   publish:
       image: plugins/docker
       dockerfile: Dockerfile
       repo: drone:5000/cicd-helloworld
       registry: drone:5000
       insecure: true
       tags: "${DRONE_BUILD_NUMBER}"
   deploy:
       image: devnetsandbox/kube:v2
       kubernetes_server: http://master:8001/
       namespace: default
       deployment: demo-app-cicd
       container: cicd-helloworld
       repo: drone:5000/cicd-helloworld
       registry: drone:5000
       insecure: true
       tag: "${DRONE_BUILD_NUMBER}"

Run the Hello World CI/CD Publish & Deploy!

Background

Great! So, we now have our accounts ready and our files complete, that tell Drone which accounts to use from our CI/CD publish and deploy (Gogs, Docker Registry and Kubernetes).

Let's try it out!

We've synced Gogs with Drone already for you, so when we create a new repo in Gogs, Drone will hook up to it automatically and wait for code commits to it, before executing our Pipeline specified in the .YML file.

First, we need to create a new repo in Gogs, do this with the following commands which initialise, sync and set up config for a new Gogs repo with our directory here in DevBox.

Feel free to look up these git commands to understand more about what they are doing.

Note: we're using the 'test' account we set up for you on Gogs, but you could use your own if you feel plucky and want to change the default commands below to match!

  1. Open a terminal window
  2. Log into the DevBox, by SSH'ing into 10.10.20.50, using developer/cisco123
  3. Navigate to the cicd_example_repo folder we created in the last section

Now, we can start our CI / CD pipeline build, by committing and pushing our new files to our repo. Drone will register this commit through the use of a 'Webhook' and start the CI/CD pipeline using the instructions in .drone.YML!

Note: Every time you want to run a new pipeline execution from this point and automatically re-build, store and deploy your code on a container, you just need to re-issue the below commands and use a different commit message in step6 below that suits the reason why you are re-commiting and pushing your code to Gogs!

  1. git add .
  2. git commit -m "initial build"
  3. git push -u origin master

If required to authenticate, use test / test for username / password.



Watch the CI/CD action!

Drone

You can visit Drone http://10.10.20.23 for the build progress.

The commit sync between Gogs and Drone should be automatic. Please wait a few minutes for the build, publish and deployment to start and finish!

Docker Registry

The Docker image should be updated to registry as well if Drone build succeeded. Check out your repo at http://drone:5000/v2/_catalog

Kubernetes

Visit http://10.10.20.21:8001/api/v1/namespaces/kubernetes-dashboard/services/kubernetes-dashboard:80/proxy to see your container 'demo-app-cicd' pod deployment on Kubernetes!



Pod service validation

use command: kubectl describe pod | grep IP to retrieve IP address of the pod just deployed, and then access the httpd service from your browser: http://10.40.0.x

Conclusion

And there you have it! From one code commit, you built a new container, stored on Docker Registry and deployed onto Kubernetes!

Hope you enjoyed your first step into the world of CI/CD. There's much more to learn on CI/CD and we hope you keep building up your knowledge with the aid of this Sandbox!

Happy Sandboxing!