This repository contains the scripts that students can use to validate that their homework assignment will pass.
The automatic grading process requires a private student repository at https://homework-gitea.apps.shared.na4.openshift.opentlc.com.
A skeleton student repository is provided at https://github.com/redhat-gpte-devopsautomation/ocp4_app_deploy_homework_template.
See the homework assignment lab on instructions what to implement. Also see the README files in the skeleton repo on how to build and deploy the applications.
As part of the grading the student’s scripts are being executed by a pipeline. If the entire pipeline finishes successfully the homework assignment is graded as passed. If the pipeline fails the homework assignmend is graded as failed.
Students can verify that the homework assignment will pass by running the pipeline themselves before submitting the assignment.
-
Make sure you are logged in as a
cluster-admin
user (e.g.system:admin
). -
Create a Jenkins Project (e.g.
gpte-jenkins
) in your cluster.oc new-project gpte-jenkins --display-name "GPTE Homework Grading Jenkins"
-
Deploy a persistent Jenkins (the parameters in JENKINS_OPTS define that Jenkins should start Agent Pods immediately every time a build is started rather than waiting for another build to finish).
oc new-app jenkins-persistent --param JENKINS_SERVICE_NAME=homework-jenkins --param JNLP_SERVICE_NAME=homework-jenkins-jnlp --param ENABLE_OAUTH=true --param MEMORY_LIMIT=4Gi --param VOLUME_CAPACITY=10Gi --param DISABLE_ADMINISTRATIVE_MONITORS=true --env JENKINS_JAVA_OVERRIDES="-Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=300" -n gpte-jenkins oc set resources dc/homework-jenkins --limits=memory=4Gi,cpu=4 --requests=memory=2Gi,cpu=2 -n gpte-jenkins
-
Create a custom Cluster-Role and grant it to the
jenkins
service account to annotate projects. Also allow thejenkins
service account to create projects.oc create clusterrole gpte-namespace-patcher --verb=patch --resource=namespaces oc adm policy add-cluster-role-to-user gpte-namespace-patcher -z homework-jenkins -n gpte-jenkins oc adm policy add-cluster-role-to-user self-provisioner -z homework-jenkins -n gpte-jenkins # Cluster-Reader is necessary for FTL oc adm policy add-cluster-role-to-user cluster-reader -z homework-jenkins -n gpte-jenkins
-
Ensure that a group
GPTE-APP-DEPLOY-HOMEWORK
exists on the cluster.oc adm groups new GPTE-APP-DEPLOY-HOMEWORK
-
Ensure that the GPTE-APP-DEPLOY-HOMEWORK group has view permission to the
gpte-jenkins
project. When requesting cluster access to create homework the student’s user will be added to this group.oc policy add-role-to-group view GPTE-APP-DEPLOY-HOMEWORK -n gpte-jenkins
-
Once Jenkins is up and running log into Jenkins.
-
In Jenkins create a new Item of type Pipeline.
-
Use the following settings in the Item:
-
Name: Grade Advanced Application Deployment Homework
-
Check the checkbox next to "This build is parametrized"
-
Create seven parameters:
Parameter Type Description GUID
String
GUID to prefix all projects. Use the GUID provided to you when you requested your homework environment.
CREDENTIAL_NAME
String
Name of the credential in Jenkins holding the student’s OpenTLC/Gitea User ID and Gitea Password (e.g. wkulhane-redhat.com). The User ID is also used to grant admin access for created projects and set the project requester field.
REPO
String
Name of the private repository (do not include the hostname and user of Gitea)
CLUSTER
String
Grading Cluster base URL. E.g. shared.na.openshift.opentlc.com
SETUP
Boolean
Default: true, If true will create all necessary projects. If false assumes that projects are already there and only pipelines need to be executed.
DELETE
Boolean
Default: true, If true will delete all created projects after a successful run.
SUBMIT_GRADE
Boolean
Default: false, If true will submit the result of the pipeline run to the LMS.
-
-
Use
https://github.com/redhat-gpte-devopsautomation/ocp4_app_deploy_homework_grading
as the Git Repo,*/master
as the Branch to build andJenkinsfile
as the Jenkinsfile. -
Uncheck the checkbox Lightweight Checkout
-
If this is a shared Jenkins (e.g. on the NA GPTE Cluster) allow students to start builds:
-
Log into Jenkins
-
Navigate to Manage Jenkins → Configure Global Security
-
Leave Matrix based security and check the checkboxes under Job to allow authenticated users to Build and Cancel builds.
-
Also check the checkboxes under Credentials to allow authenticated users to Create credentials.
-
Click Save.
-
-
Create the custom agent image that will be used to run the pipeline:
oc new-build https://github.com/redhat-gpte-devopsautomation/ocp4_app_deploy_homework_grading.git --strategy=docker --name=jenkins-agent-homework
Now you are ready to try the pipeline. Run the pipeline and provide the appropriate parameters for your environment.
The pipeline will:
-
Check out your source code repository
-
Call your shell scripts to
-
Create projects
-
Setup Jenkins
-
Setup the Development Project
-
Setup the Production Project
-
-
Execute the pipeline for your application for the initial (green) deployment.
-
Check that the application returns the correct application name
-
Execute the pipeline again to execute the blue deployment
-
Again check that the application returns the correct application name
-
Delete the projects
If the pipeline completes successfully you have passed the homework assignment.
-
The Nexus Operator should already be running in the
opentlc-shared
project. -
Make sure you are logged in as a
cluster-admin
user (e.g.system:admin
). -
Create a GPTE Operators Project in your cluster.
oc new-project gpte-operators --display-name "GPTE Operators"
-
Deploy the Gitea Operator
oc apply -f https://raw.githubusercontent.com/wkulhanek/gitea-operator/v0.17.0/deploy/crds/gpte.opentlc.com_giteas_crd.yaml oc apply -f https://raw.githubusercontent.com/wkulhanek/gitea-operator/v0.17.0/deploy/cluster_role.yaml oc create sa gitea-operator -n gpte-operators oc adm policy add-cluster-role-to-user gitea-operator system:serviceaccount:gpte-operators:gitea-operator oc apply -f https://raw.githubusercontent.com/wkulhanek/gitea-operator/v0.17.0/deploy/operator.yaml -n gpte-operators
-
Deploy the Sonarqube Operator
oc apply -f https://raw.githubusercontent.com/wkulhanek/sonarqube-operator/v0.17.0/deploy/crds/gpte.opentlc.com_sonarqubes_crd.yaml oc apply -f https://raw.githubusercontent.com/wkulhanek/sonarqube-operator/v0.17.0/deploy/cluster_role.yaml oc create sa sonarqube-operator -n gpte-operators oc adm policy add-cluster-role-to-user sonarqube-operator system:serviceaccount:gpte-operators:sonarqube-operator oc apply -f https://raw.githubusercontent.com/wkulhanek/sonarqube-operator/v0.17.0/deploy/operator.yaml -n gpte-operators
-
Make sure you are logged in as a
cluster-admin
user (e.g.system:admin
). -
Create a Homework CICD Project (e.g.
gpte-hw-cicd
) in your cluster.oc new-project gpte-hw-cicd --display-name "GPTE Homework CI/CD Tools"
-
Make a directory to keep the Custom Resource Definitions.
mkdir $HOME/gpte-homework
-
Create the Homework Gitea Custom Resource:
cat << EOF > $HOME/gpte-homework/homework-gitea.yaml apiVersion: gpte.opentlc.com/v1alpha1 kind: Gitea metadata: name: homework-gitea spec: giteaImageTag: 1.11.4 giteaRoute: homework-gitea.apps.shared-na4.na4.openshift.opentlc.com giteaSsl: true giteaVolumeSize: 20Gi postgresqlVolumeSize: 20Gi EOF
-
Deploy the Homework Gitea:
oc apply -f $HOME/gpte-homework/homework-gitea.yaml -n gpte-hw-cicd
-
Log into the Homework Gitea at https://homework-gitea.apps.shared-na4.na4.openshift.opentlc.com
-
Register an account (this first account will be a site adminstrator)
-
Create the Homework Sonarqube Custom Resource:
cat << EOF > $HOME/gpte-homework/homework-sonarqube.yaml apiVersion: gpte.opentlc.com/v1alpha1 kind: Sonarqube metadata: name: homework-sonarqube spec: postgresqlVolumeSize: 10Gi sonarqubeVolumeSize: 10Gi sonarqubeSsl: True sonarqubeRoute: homework-sonarqube.apps.shared-na4.na4.openshift.opentlc.com EOF
-
Deploy the Homework Sonarqube:
oc apply -f $HOME/gpte-homework/homework-sonarqube.yaml -n gpte-hw-cicd
-
Log into the Homework Sonarqube at https://homework-sonarqube.apps.shared-na4.na4.openshift.opentlc.com
-
User id
admin
with passwordadmin
-
Change the password (to the usual)
-
Create the Homework Nexus Custom Resource:
cat << EOF > $HOME/gpte-homework/homework-nexus.yaml apiVersion: gpte.opentlc.com/v1alpha1 kind: Nexus metadata: name: homework-nexus spec: nexusNewAdminPassword: redhat nexusRoute: homework-nexus.apps.shared-na4.na4.openshift.opentlc.com nexusRegistryRoute: homework-nexus-registry.apps.shared-na4.na4.openshift.opentlc.com nexusVolumeSize: 60Gi nexusSsl: True nexusImageTag: latest nexusCpuRequest: 4 nexusCpuLimit: 4 nexusMemoryRequest: 2Gi nexusMemoryLimit: 2Gi EOF
-
Deploy the Homework Nexus:
oc apply -f $HOME/gpte-homework/homework-nexus.yaml -n gpte-hw-cicd
-
Log into the Homework Nexus at https://homework-nexus.apps.shared-na4.na4.openshift.opentlc.com
-
User id
admin
with passwordredhat
-
Enable Anonymous access in the wizard
-
Validate that the expected repositories are created (docker, jboss, maven-all-public, maven-central, npm, npm-all, redhat-ga and releases)
-
On the left select Repository → Cleanup Policies
-
Create a new Cleanup Policy for Container images
-
Name:
CleanContainerImages
-
Format: 'docker'
-
Published Before: check the checkbox and enter
1
-
Click
Create Cleanup Policy
-
-
Create a new Cleanup Policy for Maven artifacts
-
Name:
CleanMaven
-
Format: 'maven2'
-
Published Before: check the checkbox and enter
3
-
Click
Create Cleanup Policy
-
-
Apply Cleanup Policy for Containers
-
Navigate back to Repository → Repositories
-
Select
docker
-
Add Cleanup Policy
CleanContainerImages
to the applied cleanup policies -
Click
Save
-
-
Apply Cleanup Policy for Releases
-
Navigate back to Repository → Repositories
-
Select
releases
-
Add Cleanup Policy
CleanMaven
to the applied cleanup policies -
Click
Save
-
-
Apply Cleanup Policy for Maven Central Artifacts
-
Navigate back to Repository → Repositories
-
Select
maven-central
-
Add Cleanup Policy
CleanMaven
to the applied cleanup policies -
Click
Save
-
-
Apply Cleanup Policy for Redhat Maven Artifacts
-
Navigate back to Repository → Repositories
-
Select
redhat-ga
-
Add Cleanup Policy
CleanMaven
to the applied cleanup policies -
Click
Save
-
-
Apply Cleanup Policy for Redhat Jboss Artifacts
-
Navigate back to Repository → Repositories
-
Select
jboss
-
Add Cleanup Policy
CleanMaven
to the applied cleanup policies -
Click
Save
-
-
Update Redeploy Permissions for
releases
anddocker
to allow students to publish artifacts and container images multiple times using the same version-
Navigate to Repository → Repositories
-
Select
releases
-
Change Hosted / Deployment Policy to Allow redeploy
-
Click
Save
-
Navigate to Repository → Repositories
-
Select
docker
-
Change Hosted / Deployment Policy to Allow redeploy
-
Click
Save
-