This project is being deprecated and will no longer receive updates or contributions. OpenShift has moved on to version 4.x and this project was a great enabler for kick starting development of applications on OpenShift 3.x. The tools of DevOps have evolved and grown towards a GitOps approach and so the evolution of Labs CI/CD has moved that way too.
For this teams new approach to tooling and automation checkout these two repositories:
This project is an Ansible inventory for loading an OpenShift cluster with some frequently used projects, apps and tools on a Red Hat Open Innovation Lab residencies. Using the openshift-applier
, cluster content is loaded from templates and param files in a repeatable, config-as-code way.
Running this Ansible inventory will first create three project namespaces: labs-ci-cd
, labs-dev
and labs-test
. Subsequently it will create a bunch of commonly used ci-cd-tools
such as Jenkins, Nexus and Sonar. It will also create a collection of jenkins-slaves
that can be used in builds such as npm
, maven
and golang
to name a few. Apps can be added also by applying their Jenkinsfile
as a buildConfig with an example (java-app) is included as a reference.
The diagaram below shows the components that get created by running the playbook's bootstrap
and tools
inventories.
The layout of the project is like most standard ansible-playbooks
with a simplified view of the key parts shown below:
.
βββ site.yml
βββ requirements.yml
βββ inventory
βΒ Β βββ group_vars
βΒ Β βΒ Β βββ all.yml
βΒ Β βββ host_vars
βΒ Β | βββ ...
βΒ Β βββ hosts
βββ params
βΒ Β βββ jenkins-slaves
βΒ Β βββ **
βββ secrets
βΒ Β βββ ...
site.yml
is a playbook that sets up some variables and drives the openshift-applier
role.requirements.yml
is a manifest which contains the Ansible modules needed to run the playbook inventory/host_vars/*.yml
is the collection of objects we want to insert into the cluster written according to the convention defined by the openshift-applier role.inventory/hosts
is where the targets
are defined for grouping of the various inventories to be run eg bootsrap
for creating projects and roles bindingsparams
is a set of parameter files to be processed along with their respective OpenShift template. The convention here is to group files by their application.The Ansible layer is very thin; it simply provides a way to orchestrate the application of OpenShift templates across one or more OpenShift projects. All configuration for the applications should be defined by an OpenShift template and the corresponding parameters file.
There are multiple Ansible inventories which divide the type of components to be built and deployed to an OpenShift cluster. These are broken down into three sections:
bootstrap
- Located in inventory/host_vars/projects-and-policies.yml
contains a collection of objects used to create project namespaces and bind roles to groups for those namespace in OpenShifttools
- Located in inventory/host_vars/ci-cd-tooling.yml
contains the collection of Jenkins slaves, Jenkins S2I and other CI/CD tooling deployments such as SonarQube, Nexus and others.apps
- Located in inventory/host_vars/app-build-deploy.yml
contains definitions for the Java reference app's build and deployyum install libselinux-python
.It should be noted that non-docker executions will utilize the inventory directory included in this repo by default. If you would like to specify a custom inventory for any of the below tasks, you can do so by adding -i /path/to/my/inventory
to the command
oc login -u <user> https://<server>:<port>/
ansible-galaxy install -r requirements.yml --roles-path=roles
ansible-playbook site.yml
If labs-ci-cd
already exists on your OpenShift cluster and you want to create a new instance of labs-ci-cd
with its own name eg john-ci-cd
, run the "unique projects" playbook. This playbook is useful if you're developing labs-ci-cd and want to test your changes. With a unique project name, you can safely try out your changes in a test cluster that others are using.
ansible-playbook site.yml -e ci_cd_namespace=another-ci-cd -e dev_namespace=another-dev -e test_namespace=another-test
Or please look here for other variables you can change.
Note:
After running the playbook, the pipeline should execute in Jenkins, build the spring boot app, deploy artifacts to nexus, deploy the container to the dev stage and then wait approval to deploy to the demo stage. See Common Issues
labs-ci-cd
will default to deploying a persistent Jenkins, if you do not wish to use persistent jenkins please add on the extra variable jenkins_persistence_type
and set it to ephemeral
For Example:
ansible-playbook site.yml -e jenkins_persistence_type=ephemeral
In some cases you might not want to deploy all of the components in this repo; but only a subset such as Jenkins and the customisations to it.
ansible-playbook site.yml \
-e "include_tags=jenkins,ci,projects"
The goal of this repository is to:
A few additional guiding principles:
1) Fork the repo and open PR's
2) Add all new components to the inventory with appropriate namespaces and tags
3) Extended the Jenkinsfile
with steps to verify that your components built/deployed correctly
4) For now, it is your responsibility to run the CI job. Please contact an admin for the details to set the CI job up.
5) The tests/slaves/Jenkinsfile
gets run as part of CI and will spin up a new Jenkins instance from this repositories code and validate each of the provided slaves can be accessed and contain their expected binary on the path.
nexus_validate_certs: false
as a work around.error: build error: Failed to push image: unauthorized: authentication required
. See this issue