Code Monkey home page Code Monkey logo

labs-ci-cd's Introduction

Open Innovation Labs CI/CD

🏁 No Longer Being Maintained πŸŒ‡

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:

What's in the box?

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. whats-in-the-box.png

How it Works

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 bindings
  • params 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.

Multiple inventories

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 OpenShift
  • tools - 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 deploy

Getting Started

Prerequisites

  • Ansible 2.5 or above.
  • OpenShift CLI Tools
  • Access to the OpenShift cluster (Your user needs permissions to deploy ProjectRequest objects)
  • libselinux-python (only needed on Fedora, RHEL, and CentOS)
    • Install by running yum install libselinux-python.

Inventory Usage

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

Basic Usage

  1. Log on to an OpenShift server oc login -u <user> https://<server>:<port>/
  2. Clone this repository.
  3. Install the required openshift-applier dependency:
ansible-galaxy install -r requirements.yml --roles-path=roles
  1. To deploy everything please run:
ansible-playbook site.yml

Customised Install

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:

  • Only numbers, lowercase letters, and dashes are allowed in project names.

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

Persistent vs Ephemeral Jenkins

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

Running a Subset of the Inventory

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.

  1. See the docs in the openshift-applier repo.
  2. The only required tag to deploy objects within the inventory is projects, all other tags are optional
  3. Here is an example that runs the tags that provision projects, ci, and jenkins objects:
ansible-playbook site.yml \
    -e "include_tags=jenkins,ci,projects"

Scope and Direction

The goal of this repository is to:

  1. Bootstrap Labs residencies will all the tools necessary for a comprehensive, OpenShift native CI/CD pipeline
  2. Serve as a reference implementation of the openshift-applier model for Infrastructure-as-Code (IaC)

A few additional guiding principles:

  • This repository is built to ensure all the individual components are integrated and can be deployed together.
  • It is likely that your residency will need to remove some components in this inventory and then add others. Thus, every residency team is encouraged to create a fork of this repo and modify to their needs. A few things to consider for your fork:
  • Generally speaking, there should only be one tool per functional use case e.g. Sonatype Nexus is the artifact repository so we will not support JFrog Artifactory

Contributing

  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.

Common Issues

  • Issues with valid nexus certs like seen here. You can set the ansible variable nexus_validate_certs: false as a work around.
  • S2I Build fails to push image to registry with error: build error: Failed to push image: unauthorized: authentication required. See this issue

License

ASL 2.0

labs-ci-cd's People

Contributors

abaxo avatar bagnaram avatar bpleines avatar etsauer avatar haithamshahin333 avatar infosec812 avatar jacobsee avatar jtprichett avatar makentenza avatar mcanoy avatar mdanter avatar oybed avatar pabrahamsson avatar pcarney8 avatar rdebeasi avatar sabre1041 avatar sherl0cks avatar sirwalrus avatar springdo avatar tompage1994 avatar tylerauerbeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

labs-ci-cd's Issues

Add `template_action` and `file_action` where appropriate

When running the inventory with the latest Ansible/CASL code, an error is generated that the unprivileged user does not have rights to view requests at the cluster level.

To resolve this, the ProjectRequest items in the inventory/group_vars/all.yml need either template_action: create or file_action: create added to each item.

Have option to use private repos with Jenkins-s2i

Currently, the jenkins-s2i config needs to be in a public repo, but it would be nice to have the functionality to use private repos as well (important for Labs engagements with internally hosted GitLab instances)

Clean Up Params Files

build_params vs deploy_params is not being followed by convention, and it's confusing for new users. Let's consolidate these into something that is more meaningful. Perhaps each app has its own folder including all build / dev / test / uat params. I'm not a fan of 1 file per directory

Figure out why push to internal registry fails intermittently

Sometimes during builds of various images we get a failure:

Successfully built 1b59938f722b
Pushing image 172.30.1.1:5000/labs-ci-cd/mvn-build-pod:latest ...
error: build error: Failed to push image: unauthorized: authentication required

We need to determine why and how to prevent it.

Limit installable plugins based on SonarQube compatibility versions

Carried over from old repo

Currently, the plugins.sh script will attempt to install plugins without regard to if the latest plugin is compatible with the latest SonarQube version. Need to add logic to the plugins.sh script to limit the installable plugins and log incompatible plugins being requested.

Decompose Features

the inventory in ci-cd-bootstrap should contain the minimal things we need. we should move the other components into different inventories related to module functions e.g. static analysis vs pen-testing vs software supply chain. these different modules so be completely standalone except for optionally depending on the bootstrap.

This allows users to easily consume the components they need

Complete Slack Integration or Remove Slack and Support Hubot

our current slack integration with Jenkins requires a deployment config that supports the custom env variables for slack integration. the current inventory uses the out of the box ephemeral template which does not support these env vars, and we also don't have post roles in the openshift applier yet which would allow us to add such vars. so one of a few things needs to happen (in order of my preference):

  • drop the existing jenkins integration with slack in favor of a hubot deployment (@mcanoy has prototype work here)
  • add a post role (once available) to add the env vars needed to make the existing integration work
  • provide a custom jenkins deployment config to support the existing slack integration

Pin SonarQube version for each release

Currently, the SonarQube image is always the "latest" version of SonarQube, thus there is no guarantee that any given release of this project will have the same version of SonarQube.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.