During the first 3 labs we've utilized a new project and built upon it. For labs 4-6 we will use a project that we've created for you, this will help with the copy/pasting.
Navigate to the CICD boilerplate project located at: https://gitlab.com/jeffkala/workshop-implementing-cicd-pipelines
Click on the Fork button which is in the top right of the page.
- Select a Namespace for the Project to be forked into: (should be your GitLab username).
- Make sure
Branches to includeis set toall.
Now clone the GitLab repo in to your codespace environment. This will allow everything to be managed from this single place.
@jeffkala ➜ /workspaces/workshop-implementing-cicd (main) $ git clone git@gitlab.com:jeffkala/workshop-implementing-cicd-pipelines.git
Cloning into 'workshop-implementing-cicd-pipelines'...
remote: Enumerating objects: 597, done.
remote: Counting objects: 100% (484/484), done.
remote: Compressing objects: 100% (467/467), done.
remote: Total 597 (delta 298), reused 0 (delta 0), pack-reused 113 (from 1)
Receiving objects: 100% (597/597), 212.95 KiB | 9.68 MiB/s, done.
Resolving deltas: 100% (324/324), done.Once the forked repository is cloned into codespace you will see it in your files.
From within the workshop-implementing-cicd-pipelines directory validate your remote is properly set.
@jeffkala ➜ /workspaces/workshop-implementing-cicd-documentation/workshop-implementing-cicd-pipelines (main) $ git remote -v
origin git@gitlab.com:jeffkala/workshop-implementing-cicd-pipelines.git (fetch)Finally, lets allow our same SSH Key we generated previously in Lab 1. Basic Git Operations. In GitLab you do the follow:
- Go to the
workshop-implementing-cicd-pipelinesrepository and navigate to Settings -> Repository -> Deploy Keys. - You will notice that
Enabled Deploy Keystab is empty currently. Click onPrivately accessible deploy keysand you will see the SSH Key we setup previously. ClickEnabled.
- Navigate back to
Enabled Deploy Keysand you will see the SSH key shows up now!!
- Finally, we edit the key and make sure we check the box for
Grant write permission to this key
- Lastly, with the deploy keys set you'll see a
pushremote has been setup.
@jeffkala ➜ /workspaces/workshop-implementing-cicd-documentation/workshop-implementing-cicd-pipelines (main) $ git remote -v
origin git@gitlab.com:jeffkala/workshop-implementing-cicd-pipelines.git (fetch)
origin git@gitlab.com:jeffkala/workshop-implementing-cicd-pipelines.git (push)-
Go to the
workshop-implementing-cicd-pipelinesrepository and navigate to Settings -> CI/CD -> Runners. -
Click on
Other Project Available Runnersand click enabled for this project button.
Due to the nature of GitHub's codespaces; and the docker networking within; there is an initial requirement to update the Nornir inventory file.
- Execute the containerlab deploy command which based on the topology file will auto assign mgmt interfaces to the lab equipment.
Navigate to clab directory:
@jeffkala ➜ /workspaces/workshop-implementing-cicd (main) $ cd ../clab/
Delete the existing clab deployment
clab destroy -t ~/workshop-implementing-cicd-documentation/clab/clab-ceos-lab
Start the topology:
@jeffkala ➜ /workspaces/workshop-implementing-cicd /clab (main) $ sudo containerlab deploy --topo ceos-lab.clab.yml
╭─────────┬──────────────┬─────────┬────────────────╮
│ Name │ Kind/Image │ State │ IPv4/6 Address │
├─────────┼──────────────┼─────────┼────────────────┤
│ ceos-01 │ arista_ceos │ running │ 172.24.78.10 │
│ │ ceos:4.32.0F │ │ N/A │
├─────────┼──────────────┼─────────┼────────────────┤
│ ceos-02 │ arista_ceos │ running │ 172.24.78.11 │
│ │ ceos:4.32.0F │ │ N/A │
├─────────┼──────────────┼─────────┼────────────────┤
│ ceos-03 │ arista_ceos │ running │ 172.24.78.12 │
│ │ ceos:4.32.0F │ │ N/A │
├─────────┼──────────────┼─────────┼────────────────┤
│ ceos-04 │ arista_ceos │ running │ 172.24.78.13 │
│ │ ceos:4.32.0F │ │ N/A │
╰─────────┴──────────────┴─────────┴────────────────╯
-
Now that the lab has been deployed in the Codespace environment, and we have the mgmt IPs of the equipment we must update the Nornir inventory host file with the assigned IPs.
-
To get started we will checkout the GitLab branch called
Lab_4_Source_Code_Checkswhere we will update our Nornir inventory and push the code up to run the code checks. -
Navigate and Checkout the Working Branch
From within the Codespace terminal change into the newly cloned fork.
cd ../workshop-implementing-cicd-pipelines/cicd_workshop/Next, checkout the Lab_4_Source_Code_Checks branch.
git switch Lab_4_Source_Code_Checks- Now navigate to
cicd_workshop-->inventory-->hosts.yaml
Validate the host definitions hostname field with the correct IP address from the containerlab deploy command output.
For example the file should look like this.
---
ceos-01:
hostname: "172.24.78.10"
... omitted ...
ceos-02:
hostname: "172.24.78.11"
... omitted ...
ceos-03:
hostname: "172.24.78.12"
... omitted ...
ceos-04:
hostname: "172.24.78.13"
... omitted ...Lab 4 is all about the project level source code checks.
When you open the .gitlab-ci.yml file you will notice we have some defaults, workflow details, stages, and more.
Next, we will look at the stages: section which tells our pipeline what stages and what order they should be executed in.
stages: # List of stages for jobs, and their order of execution
- "lab-4-lint-and-format"
- "lab-4-pytest"You will finally see the include: section which is where we can add additional gitlab-ci files. We will add more files to this section throughout labs 5 and 6.
include:
- local: ".gitlab/ci/lab-4-includes.gitlab-ci.yml"Lets now review the details of that included file to see what source code checks we're running.
- Navigate to
.gitlab/ci/lab-4-includes.gitlab-ci.ymlwithin the forked repository. - Notice that each of our jobs have a
name, but more importantly it has astagewhere that job name and detail is linked to a stage we had in our.gitlab-ci.ymlfile.
yamllint-job:
stage: "lab-4-lint-and-format"Each job then has an execution strategy and commands.
yamllint-job:
stage: "lab-4-lint-and-format"
script:
- "echo 'Linting Nornir YAML inventory files..'"
- "uv run invoke yamllint"In this yamllint-job we're echoing a simple description, followed by running yamllint from within our uv environment.
- Notice this file has all our other source code checks we want to enforce. Some simple explanations are below.
- yamllint - Validate all our YAML files in the project are formatted to our standards, e.g. all strings should be wrapped in double quotes.
- j2lint - Our source code has a Jinja2 templates directory. This directory holds all the templates we will use to generate our Arista configurations. J2Lint validates these template files follow best practices.
- ruff - We use ruff in two stages. The first lints and formats our source codes python files. The second does ruff formatting checks to find python antipatterns etc.
- pytest - Finally, we have some basic unittest in the project that are unittest validating the source code itself. This checks only for tests under the
tests/unitfolder.
As you can see this is a ton of source code checks. It keeps our projects clean, and following best practices for multiple different file types and frameworks.
Now that we understand lab 4, and the source code checks, lets update and run the pipeline.
These are the two assumptions before you should push your code up:
-
Ensure you've updated your Nornir inventory files from here.
-
Navigate to the main
.gitlab-ci.ymlpipeline file and update your tag to what you deployed in the first lab. Make sure to update the tag with the one you created!
---
default:
image: "ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER"
tags:
- "jeff-local-runner" # Update using CICD Runner Tag you used!- Commit and Push your code up!
git add -A;git commit -m "lab4 updates";git push -u origin Lab_4_Source_Code_Checks- Go into your GitLab UI and navigate to the forked project.
- Navigate to Builds from the side menu and click on Pipelines.
- Watch your Pipeline run








