Keyboard Time: 25 mins, Automation Wait Time: 5 mins
Scenarios: Instructor-Led, Self-Paced
Create a GitOps Environment Deployment project from a template.
Configure it to monitor the Application Build project for new images.
Create a token so that the CI job can write back the constructed manifests back to it’s own project.
Do a dry run to see if the manifests update as expected.
While in ‘yourpersonalgroup’ (created in a prior lab) Click New project (button) and then Click Import project
On the ‘Import project’ page, Click Repository by URL
On the next page, for ‘Git repository URL’ Paste https://gitlab.com/guided-explorations/gl-k8s-agent/gitops/envs/world-greetings-env-1.git
In ‘Project name’ Type World Greetings Env 1 (likely already be defaulted to this)
Scroll down to ‘Visibility Level’
Click Public.
Near the bottom of the page Click Create project (button)
When the import is complete, you will be placed in the default landing page of the project.
Instructor-Led Classroom: Please ask the instructor whether to use Token Option 1: Using a Project Access Token (Paid Licenses Only Feature) or Token Option 2: Using a Personal Access Token (PAT)
Self-paced: Try Token Option 1: Using a Project Access Token (Paid Licenses Only Feature) first. If your instance does not have a specific GitLab paid license feature you will be directed to Token Option 2: Using a Personal Access Token (PAT).
IMPORTANT: Requires a paid GitLab license, even an ultimate trial will not have the Project Level Access Token Feature. The project menu choice Settings => Access Tokens will not exist. You will need to use “Token Option 2” below.
While in ‘yourpersonalgroup/world-greetings-1’ (created in a prior lab), on the left navigation, Click Settings => Access Tokens
This menu option will not exist if you do not have a paid GitLab license. You will need to use “Token Option 2” below.
Under ‘Add a project access token’, for Token name, Type WriteRepository
Under ‘Select a role’, Select Maintainer
Under ‘Select scopes’
Click Create project access token (button)
Use copy and paste to record the following in a temporary document (do not hand type tokens):
On the left navigation, Click Project Information => Members
In the search prompt Type WriteRepository
The user list should return one entry
In the listing, under “WriteRepository”, copy the user name that starts with “project_” and ends with “_bot” - do not include the @
sign.
In the previous temporary document, record:
In the upper right of the page Click [your Avatar icon] and then Click Edit profile
On the left naviagion, Click Access Tokens
Under ‘Add a personal access token’, for Token name, Type WriteRepository
Under ‘Select scopes’
Click Create personal access token (button)
In a NEW browser tab, open the project ‘yourpersonalgroup/world-greetings-env-1’ again (this time we are at the PROJECT level).
On the left navigation, Click Settings => CI/CD
To the right of ‘Variables’, Click Expand
Click Add variable
For Key, Copy and Paste PROJECT_COMMIT_TOKEN
In the Value field Copy and Paste [the temporary document value for PROJECT_COMMIT_TOKEN]
Under Flags, Deselect Protect variable
Under Flags, Select Mask variable
Click Add variable
To add another variable, Click Add variable
For Key, Copy and Paste PROJECT_COMMIT_USER
In the Value field Copy and Paste [the temporary document value for PROJECT_COMMIT_USER]
Under Flags, Deselect Protect variable
Click Add variable
Among the existing variables in the ‘yourpersonalgroup/world-greetings-env-1’ project, you should have the two new variables PROJECT_COMMIT_TOKEN and PROJECT_COMMIT_USER.
These permissions are least privilege, in part, because the CI/CD Variables are only published at the project level.
In a new browser tab, open your ‘yourpersonalgroup/hello-world’ Project. (IMPORTANT: not the same project you are in now)
On the left navigation panel, Click Packages & Registries => Container Registry
Next to the line item ending in “/main”, Click [the Clipboard icon]
IMPORTANT: Switch back to ‘yourpersonalgroup/world-greetings-env-1’ Project
In the left navigation, Click Repository => Files
On the upper right of the Project page, Click Web IDE
In the files list, Click .gitlab-ci.yml
Under ‘variables:’ Find IMAGE_NAME_TO_MONITOR
In the quoted value, Remove the existing value
Paste your copied image path
The result should be something like IMAGE_NAME_TO_MONITOR: “registry.gitlab.com/somegroups/classgroup/yourpersonalgroup/hello-world/main”
Click Create commit…
Select Commit to main branch (change from “Create a new branch”)
Click Commit
In the very bottom left, immediately after the text ‘Pipeline’ Click [the pipeline number which is preceeded with a #] (Or on the left navigation Click CI/CD => Pipelines and Click [the status badge] or [pipeline #] for the latest running pipeline)
Expand the Downstream pipeline with the great than arrow (>
).
Possible error messages (not an exhaustive list):
level=fatal msg="authenticating creds for \"registry.gitlab.com\": Requesting bear token: invalid status code from registry 403 (Forbidden)”
.
level=fatal msg="error logging into \"registry.gitlab.com\": invalid username/password"
can be caused by:
being incorrectly named,
at the wrong group level or
having invalid values or accidental swapping of the values (e.g. User Id in READ_REG_TOKEN)
READ_REG_USER starting with @
(this should be left off)
having incorrect permissions in the token (should be “read_registry”, not “read_repository”)
The error message:
remote: GitLab: You are not allowed to push code to protected branches on this project. ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to
can be caused by:
[Automation wait: ~3 min] Watch the pipeline complete through the ‘update-staging-manifests’ job.
The update-staging-manifests job should complete successfully.
To get back to the Web IDE, Click [the browser back button]
Click [the browser refresh button]
In the files list on the left Click manifests > hello-world.staging.yaml
Search for - image:
The image reference should be the registry pointer to your Application Project, followed by the latest-prod image version (“1.0.0” if you only built the Application Project twice, maybe higher if you did more builds)
Be sure you refreshed the browser
In the files list on the left Click manifests > hello-world.production.yaml
Search for - image:
The image version tag does not match staging. (If all labs were done as described it should say registry.gitlab.com/_replace-with-hello-world-service-container-registry-path_:5.5.5
)
In a NEW browser tab, open ‘yourpersonalgroup/world-greetings-env-1’ again.
Shortcut - right click the project heading in the left navigation and Click Open Link in New Tab)
In the left navigation Click CI/CD => Pipelines
Find the last non-skipped pipeline and Click it’s [Status badge] or [Pipeline #] to open the pipeline.
Expand the Downstream pipeline with the great than arrow (>
).
NOTE: Depending on your screen width, you may need to use the horizontal scroll bar under the pipeline to find the update-production-manifests job.
Next to the update-production-manifests job, Click [the play button]
[Automation wait: ~1 min] Wait until the update-production-manifests job has a green check next to it.
In the browser tabs, Switch back to [the Web IDE tab]
Click [the browser refresh button]
In the files list on the left Click manifests > hello-world.production.yaml
Search for - image:
The image reference and version tag should match the staging manifest (hello-world.staging.yaml) which should be the latest-prod tagged image in the Hello World Application Build project.
This source project followed several specific principles that makes it this easy to use as a template:
Create a GitOps Environment Deployment project from a template.
Configure it to monitor the Application Build project for new images.
Create a token so that the CI job can write back the constructed manifests back to it’s own project.
Do a dry run to see if the manifests update as expected.