• Stars
    star
    523
  • Rank 84,684 (Top 2 %)
  • Language
    Shell
  • Created about 10 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CI/CD Demo on OpenShift

For a CI/CD demo using Tekton Pipelines and Argo CD on OpenShift refer to: https://github.com/siamaksade/openshift-cicd-demo

CI/CD Demo - OpenShift Container Platform 4.6

This repository includes the infrastructure and pipeline definition for continuous delivery using Jenkins, Nexus, SonarQube and Eclipse Che on OpenShift.

Introduction

On every pipeline execution, the code goes through the following steps:

  1. Code is cloned from Gogs, built, tested and analyzed for bugs and bad patterns
  2. The WAR artifact is pushed to Nexus Repository manager
  3. A container image (tasks:latest) is built based on the Tasks application WAR artifact deployed on WildFly
  4. If Quay.io is enabled, the Tasks app container image is pushed to the quay.io image registry and a security scan is scheduled
  5. The Tasks container image is deployed in a fresh new container in DEV project (pulled form Quay.io, if enabled)
  6. If tests successful, the pipeline is paused for the release manager to approve the release to STAGE
  7. If approved, the DEV image is tagged in the STAGE project. If Quay.io is enabled, the image is tagged in the Quay.io image repository using Skopeo
  8. The staged image is deployed in a fresh new container in the STAGE project (pulled form Quay.io, if enabled)

The following diagram shows the steps included in the deployment pipeline:

The application used in this pipeline is a JAX-RS application which is available on GitHub and is imported into Gogs during the setup process: https://github.com/OpenShiftDemos/openshift-tasks

Prerequisites

  • 10+ GB memory

Get OpenShift 4

Download and install CodeReady Containers in order to create a local OpenShift 4 cluster on your workstation. Otherwise create an OpenShift 4 cluster on the public cloud or the infrastructure of your choice.

Automated Deploy on OpenShift

You can se the scripts/provision.sh script provided to deploy the entire demo:

./provision.sh --help
./provision.sh deploy 
./provision.sh delete 

If you want to use Quay.io as an external registry with this demo, Go to quay.io and register for free. Then deploy the demo providing your quay.io credentials:

./provision.sh deploy --enable-quay --quay-username quay_username --quay-password quay_password

In that case, the pipeline would create an image repository called tasks-app (default name but configurable) on your Quay.io account and use that instead of the integrated OpenShift registry, for pushing the built images and also pulling images for deployment.

Manual Deploy on OpenShift

Create the following projects for CI/CD components, Dev and Stage environments:

# Create Projects
oc new-project dev --display-name="Tasks - Dev"
oc new-project stage --display-name="Tasks - Stage"
oc new-project cicd --display-name="CI/CD"

# Grant Jenkins Access to Projects
oc policy add-role-to-group edit system:serviceaccounts:cicd -n dev
oc policy add-role-to-group edit system:serviceaccounts:cicd -n stage

And then deploy the demo:

# Deploy Demo
oc new-app jenkins-ephemeral -n cicd  
oc new-app -n cicd -f cicd-template.yaml

To use custom project names, change cicd, dev and stage in the above commands to your own names and use the following to create the demo:

oc new-app -n cicd -f cicd-template.yaml --param DEV_PROJECT=dev-project-name --param STAGE_PROJECT=stage-project-name

JBoss EAP vs WildFly

This demo by default uses the WildFly community image. You can use the JBoss EAP enterprise images provide by Red Hat by simply editing the tasks build config in the Tasks - Dev project and changing the builder image from wildfly to jboss-eap70-openshift:1.5. The demo would work exactly the same and would build the images using the JBoss EAP builder image. If using Quay, be sure not to leave the JBoss EAP images on a publicly accessible image repository.

Troubleshooting

  • If Maven fails with /opt/rh/rh-maven33/root/usr/bin/mvn: line 9: 298 Killed (e.g. during static analysis), you are running out of memory and need more memory for OpenShift.

  • If running into Permission denied issues on minishift or CDK, run the following to adjust minishift persistent volume permissions:

    minishift ssh
    chmod 777 -R /var/lib/minishift/
    

Demo Guide

  • Take note of these credentials and then follow the demo guide below:

    • Gogs: gogs/gogs
    • Nexus: admin/admin123
    • SonarQube: admin/admin
  • A Jenkins pipeline is pre-configured which clones Tasks application source code from Gogs (running on OpenShift), builds, deploys and promotes the result through the deployment pipeline. In the CI/CD project, click on Builds and then Pipelines to see the list of defined pipelines.

    Click on tasks-pipeline and Configuration and explore the pipeline definition.

    You can also explore the pipeline job in Jenkins by clicking on the Jenkins route url, logging in with the OpenShift credentials and clicking on tasks-pipeline and Configure.

  • Run an instance of the pipeline by starting the tasks-pipeline in OpenShift or Jenkins.

  • During pipeline execution, verify a new Jenkins slave pod is created within CI/CD project to execute the pipeline.

  • If you have enabled Quay, after image build completes go to quay.io and show that a image repository is created and contains the Tasks app image

  • Pipelines pauses at Deploy STAGE for approval in order to promote the build to the STAGE environment. Click on this step on the pipeline and then Promote.

  • After pipeline completion, demonstrate the following:

    • Explore the snapshots repository in Nexus and verify openshift-tasks is pushed to the repository
    • Explore SonarQube and show the metrics, stats, code coverage, etc
    • Explore Tasks - Dev project in OpenShift console and verify the application is deployed in the DEV environment
    • Explore Tasks - Stage project in OpenShift console and verify the application is deployed in the STAGE environment
    • If Quay enabled, click on the image tag in quay.io and show the security scannig results

  • Clone and checkout the eap-7 branch of the openshift-tasks git repository and using an IDE (e.g. JBoss Developer Studio), remove the @Ignore annotation from src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.java test methods to enable the unit tests. Commit and push to the git repo.

  • Check out Jenkins, a pipeline instance is created and is being executed. The pipeline will fail during unit tests due to the enabled unit test.

  • Check out the failed unit and test src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.java and run it in the IDE.

  • Fix the test by modifying src/main/java/org/jboss/as/quickstarts/tasksrs/service/UserResource.java and uncommenting the sort function in getUsers method.

  • Run the unit test in the IDE. The unit test runs green.

  • Commit and push the fix to the git repository and verify a pipeline instance is created in Jenkins and executes successfully.

Using Eclipse Che for Editing Code

You can install Eclipse Che on OpenShift 4 using the OperatorHub. Follow the Installing Che on OpenShift 4 from OperatorHub docs in order to install Eclipse Che 7. Alternatively, if you OpenShift cluster is accessible over the internet, you can use the hosted Eclipse Che service at https://che.openshift.io .

You can then follow these instructions to use Eclipse Che for editing code in the above demo flow.

More Repositories

1

openshift-cicd-demo

OpenShift CI/CD demo with Tekton and Argo CD
Shell
66
star
2

openshift-gitops-getting-started

https://www.openshift.com/learn/topics/gitops/
64
star
3

tekton-cd-demo

CI/CD demo with Tekton on OpenShift
Shell
61
star
4

pipelines-examples

OpenShift Pipelines Examples based on Tekton
Shell
31
star
5

cart-service

Cart service is one of the microservices in CoolStore which is a containerised polyglot microservices application consisting of services based on JBoss Middleware, NodeJS, Spring, Netflix OSS and more running on OpenShift
Java
25
star
6

jenkins-s2i-example

Smarty
20
star
7

tekton-pipelines-maven-demo

12
star
8

jenkins-blueocean

Jenkins Blue Ocean for OpenShift Jenkins S2I
11
star
9

wildfly-swarm-hystrix-example

Wildfly-Swarm Example using Hystrix
Java
10
star
10

openshift-demos-ansible

Ansible Roles and Playbook for Deploying OpenShift Demos
Shell
9
star
11

quay-mirror-pipeline

A Tekton Pipeline example for triggering on Quay image mirroring
4
star
12

ansible-openshift-coolstore

Ansible Role for Deploying CoolStore Demo on OpenShift
4
star
13

jenkins-slave-gradle

Gradle Jenkins Slave Image for use with OpenShift and Kubernetes
Dockerfile
4
star
14

docker-images

Shell
3
star
15

mapit-spring

JavaScript
3
star
16

ansible-openshift-quay

Ansible Role for Deploying Red Hat Quay Registry on OpenShift
3
star
17

devnation-cicd-demo

CI/CD Tips for DevNation Live
3
star
18

spring-petclinic-config

3
star
19

workshopper-template

Workshopper Template for Creating Workshop/Lab Guides
2
star
20

jenkins-slave-skopeo

Skopeo Jenkins Slave Image for use with OpenShift and Kubernetes
2
star
21

ansible-openshift-eclipse-che

Ansible Role for Deploying Eclipse Che (single user) on OpenShift
2
star
22

ansible-openshift-jenkins

Ansible Role for Deploying Jenkins on OpenShift
2
star
23

ansible-openshift-gogs

Ansible Role for Deploying Gogs Git Server on OpenShift
1
star
24

openshift-builds

Java
1
star
25

cluster-gitops-examples

1
star
26

dict-rest

Java
1
star
27

openshift-mobileresponse

Demo Application on OpenShift using Mobile Response APIs
HTML
1
star
28

sonarqube

SonarQube image for OpenShift
Shell
1
star
29

devsecops-demo

Shell
1
star
30

switchyard-samples

SwitchYard Samples
Java
1
star
31

tinyapp

TinyApp Sample Application
Java
1
star
32

coolstore-demo-guides

1
star
33

ansible-openshift-nexus

Ansible Role for Deploying Sonatype Nexus on OpenShift
Groovy
1
star
34

ansible-openshift-maistra

Ansible Role for Deploying Maistra (Istio, Jaeger, Kiali, and Prometheus) on OpenShift
1
star
35

maven-populator

Tool for mass deploying jar files into a maven repository
Java
1
star
36

siege-docker

Docker Image for Siege Load Testing Tool
Dockerfile
1
star