Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni Syvanen committed Apr 27, 2018
2 parents 359d76a + 9afda65 commit 4a5af91
Show file tree
Hide file tree
Showing 19 changed files with 203 additions and 54 deletions.
19 changes: 19 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# How to Contribute

We welcome contributions from the community. Here are a few ways you can help us improve.

## Open an Issue

If you see something you'd like changed, but aren't sure how to change it, submit an issue describing what you'd like to see.

## Submit a Pull Request

If you feel like getting your hands dirty, feel free to make the change yourself. Here's how:

1. Fork the repo on Github, and then clone it locally.
2. Create a branch named appropriately for the change you are going to make.
3. Make your code change.
4. Push your code change up to your forked repo.
5. Open a Pull Request to merge your changes to this repo. The comment box will be filled in automatically via a template.

See [Using Pull Requests](https://help.github.com/articles/using-pull-requests/) got more information on how to use GitHub PRs.
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#### What does this PR do?
Brief explanation of the code or documentation change you've made

#### How should this be tested?
Include commands to run your new feature, and also post-run commands to validate that it worked. (please use code blocks to format code samples)

#### Is there a relevant Issue open for this?
Provide a link to any open issues that describe the problem you are solving.

#### Who would you like to review this?
cc: @redhat-cop/containers-approvers
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ Typically the things required to build a pipeline sample include:
- etc.

See our [basic spring boot](./basic-spring-boot) example for a very simple reference architecture.

## Automated Deployments

These pipeline quickstarts include an Ansible inventory through which they can be automatically deployed and managed using the [OpenShift Applier](https://github.com/redhat-cop/casl-ansible/tree/master/roles/openshift-applier) role.
2 changes: 1 addition & 1 deletion basic-spring-boot/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openshift.withCluster() {
env.NAMESPACE = openshift.project()
env.POM_FILE = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml"
env.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?/, '')
env.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?/, '').replaceAll("/", '')
echo "Starting Pipeline for ${APP_NAME}..."
def projectBase = "${env.NAMESPACE}".replaceAll(/-dev/, '')
env.STAGE1 = "${projectBase}-dev"
Expand Down
51 changes: 26 additions & 25 deletions basic-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,38 @@ This example demonstrates how to implement a full end-to-end Jenkins Pipeline fo
* "One Click" instantiation of a Jenkins Pipeline using OpenShift's Jenkins Pipeline Strategy feature
* Promotion of an application's container image within an OpenShift Cluster (using `oc tag`)
* Promotion of an application's container image to a separate OpenShift Cluster (using `skopeo`) - Coming Soon!
* Automated rollout using the [openshift-appler](https://github.com/redhat-cop/casl-ansible/tree/master/roles/openshift-applier) Ansible role.

## Quickstart
## Automated Quickstart

Run the following commands to instantiate this example.
This quickstart can be deployed quickly using Ansible. Here are the steps.

1. Clone [this repo](https://github.com/redhat-cop/container-pipelines.git) and the [casl-ansible](https://github.com/redhat-cop/casl-ansible.git) repo.
2. Log into an OpenShift cluster, then run the following command.
```
cd ./basic-spring-boot
oc create -f projects/projects.yml
oc process openshift//jenkins-ephemeral | oc apply -f- -n basic-spring-boot-dev
oc process -f deploy/template.yml --param-file=deploy/dev/params | oc apply -f-
oc process -f deploy/template.yml --param-file=deploy/stage/params | oc apply -f-
oc process -f deploy/template.yml --param-file=deploy/prod/params | oc apply -f-
oc process -f build/template.yml --param-file build/dev/params | oc apply -f-
$ oc login
$ ansible-playbook -i ./applier/inventory/ /path/to/casl-ansible/playbooks/openshift-cluster-seed.yml
```

At this point you should have 3 projects deployed (`basic-spring-boot-build`, `basic-spring-boot-dev`, `basic-spring-boot-stage`, and `basic-spring-boot-prod`) with our [Spring Rest](https://github.com/redhat-cop/spring-rest.git) demo application deployed to all 3.

## Architecture

The following breaks down the architecture of the pipeline deployed, as well as walks through the manual deployment steps

### OpenShift Templates

The components of this pipeline are divided into two templates.

The first template, `build/template.yml` is what we are calling the "Build" template. It contains:
The first template, `applier/templates/build.yml` is what we are calling the "Build" template. It contains:

* A `jenkinsPipelineStrategy` BuildConfig
* An `s2i` BuildConfig
* An ImageStream for the s2i build config to push to

The build template contains a default source code repo for a java application compatible with this pipelines architecture (https://github.com/redhat-cop/spring-rest).

The second template, `deploy/template.yml` is the "Deploy" template. It contains:
The second template, `applier/templates/deployment.yml` is the "Deploy" template. It contains:

* A tomcat8 DeploymentConfig
* A Service definition
Expand All @@ -49,33 +51,32 @@ The idea behind the split between the templates is that I can deploy the build t
This project includes a sample `Jenkinsfile` pipeline script that could be included with a Java project in order to implement a basic CI/CD pipeline for that project, under the following assumptions:

* The project is built with Maven
* The `Jenkinsfile` script is placed in the same directory as the `pom.xml` file in the git source.
* The OpenShift projects that represent the Application's lifecycle stages are of the naming format: `<app-name>-dev`, `<app-name>-stage`, `<app-name>-prod`.

For convenience, this pipeline script is already included in the following git repository, based on our [Spring Boot Demo App](https://github.com/redhat-cop/spring-rest) app.

https://github.com/redhat-cop/spring-rest
This pipeline defaults to use our [Spring Boot Demo App](https://github.com/redhat-cop/spring-rest).

## Bill of Materials

* One or Two OpenShift Container Platform Clusters
* OpenShift 3.5+ is required.
* Access to GitHub

## Implementation Instructions
## Manual Deployment Instructions

### 1. Create Lifecycle Stages

For the purposes of this demo, we are going to create three stages for our application to be promoted through.

- `basic-spring-boot-build`
- `basic-spring-boot-dev`
- `basic-spring-boot-stage`
- `basic-spring-boot-prod`

In the spirit of _Infrastructure as Code_ we have a YAML file that defines the `ProjectRequests` for us. This is as an alternative to running `oc new-project`, but will yeild the same result.

```
$ oc create -f projects/projects.yml
$ oc create -f applier/projects/projects.yml
projectrequest "basic-spring-boot-build" created
projectrequest "basic-spring-boot-dev" created
projectrequest "basic-spring-boot-stage" created
projectrequest "basic-spring-boot-prod" created
Expand All @@ -86,7 +87,7 @@ projectrequest "basic-spring-boot-prod" created
For this step, the OpenShift default template set provides exactly what we need to get jenkins up and running.

```
$ oc process openshift//jenkins-ephemeral | oc apply -f- -n basic-spring-boot-dev
$ oc process openshift//jenkins-ephemeral | oc apply -f- -n basic-spring-boot-build
route "jenkins" created
deploymentconfig "jenkins" created
serviceaccount "jenkins" created
Expand All @@ -97,7 +98,7 @@ service "jenkins" created

### 4. Instantiate Pipeline

A _deploy template_ is provided at `deploy/template.yml` that defines all of the resources required to run our Tomcat application. It includes:
A _deploy template_ is provided at `applier/templates/deployment.yml` that defines all of the resources required to run our Tomcat application. It includes:

* A `Service`
* A `Route`
Expand All @@ -109,34 +110,34 @@ This template should be instantiated once in each of the namespaces that our app

Deploy the deployment template to all three projects.
```
$ oc process -f deploy/template.yml --param-file=deploy/dev/params | oc apply -f-
$ oc process -f applier/templates/deployment.yml --param-file=applier/params/deployment-dev | oc apply -f-
service "spring-rest" created
route "spring-rest" created
imagestream "spring-rest" created
deploymentconfig "spring-rest" created
rolebinding "jenkins_edit" configured
$ oc process -f deploy/template.yml --param-file=deploy/stage/params | oc apply -f-
$ oc process -f applier/templates/deployment.yml --param-file=applier/params/deployments-stage | oc apply -f-
service "spring-rest" created
route "spring-rest" created
imagestream "spring-rest" created
deploymentconfig "spring-rest" created
rolebinding "jenkins_edit" created
$ oc process -f deploy/template.yml --param-file=deploy/prod/params | oc apply -f-
$ oc process -f applier/templates/deployment.yml --param-file=applier/params/deployment-prod | oc apply -f-
service "spring-rest" created
route "spring-rest" created
imagestream "spring-rest" created
deploymentconfig "spring-rest" created
rolebinding "jenkins_edit" created
```

A _build template_ is provided at `build/template.yml` that defines all the resources required to build our java app. It includes:
A _build template_ is provided at `applier/templates/build.yml` that defines all the resources required to build our java app. It includes:

* A `BuildConfig` that defines a `JenkinsPipelineStrategy` build, which will be used to define out pipeline.
* A `BuildConfig` that defines a `Source` build with `Binary` input. This will build our image.

Deploy the pipeline template in dev only.
```
$ oc process -f build/template.yml --param-file build/dev/params | oc apply -f-
$ oc process -f applier/templates/build.yml --param-file applier/params/build-dev | oc apply -f-
buildconfig "spring-rest-pipeline" created
buildconfig "spring-rest" created
```
Expand All @@ -148,5 +149,5 @@ At this point you should be able to go to the Web Console and follow the pipelin
Cleaning up this example is as simple as deleting the projects we created at the beginning.

```
oc delete project basic-spring-boot-dev basic-spring-boot-prod basic-spring-boot-stage
oc delete project basic-spring-boot-build basic-spring-boot-dev basic-spring-boot-prod basic-spring-boot-stage
```
22 changes: 22 additions & 0 deletions basic-spring-boot/applier/inventory/group_vars/seed-hosts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openshift_cluster_content:
- object: projects
content:
- name: "create environments"
file: "{{ inventory_dir }}/../projects/projects.yml"
file_action: create
- object: deployments
content:
- name: "deploy dev environment"
template: "{{ inventory_dir }}/../templates/deployment.yml"
params: "{{ inventory_dir }}/../params/deployment-dev"
- name: "deply stage environment"
template: "{{ inventory_dir }}/../templates/deployment.yml"
params: "{{ inventory_dir }}/../params/deployment-stage"
- name: "deply prod environment"
template: "{{ inventory_dir }}/../templates/deployment.yml"
params: "{{ inventory_dir }}/../params/deployment-prod"
- object: builds
content:
- name: "deploy build pipeline to dev"
template: "{{ inventory_dir }}/../templates/build.yml"
params: "{{ inventory_dir }}/../params/build-dev"
2 changes: 2 additions & 0 deletions basic-spring-boot/applier/inventory/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[seed-hosts]
localhost ansible_connection=local
4 changes: 4 additions & 0 deletions basic-spring-boot/applier/params/build-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APPLICATION_NAME=spring-rest
NAMESPACE=basic-spring-boot-build
SOURCE_REPOSITORY_URL=https://github.com/redhat-cop/container-pipelines.git
SOURCE_REPOSITORY_REF=master
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APPLICATION_NAME=spring-rest
NAMESPACE=basic-spring-boot-dev
SA_NAMESPACE=basic-spring-boot-dev
SA_NAMESPACE=basic-spring-boot-build
READINESS_RESPONSE=status.:.UP
READINESS_PATH=/health
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APPLICATION_NAME=spring-rest
NAMESPACE=basic-spring-boot-prod
SA_NAMESPACE=basic-spring-boot-dev
SA_NAMESPACE=basic-spring-boot-build
READINESS_RESPONSE=status.:.UP
READINESS_PATH=/health
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APPLICATION_NAME=spring-rest
NAMESPACE=basic-spring-boot-stage
SA_NAME=jenkins
SA_NAMESPACE=basic-spring-boot-dev
SA_NAMESPACE=basic-spring-boot-build
READINESS_RESPONSE=status.:.UP
READINESS_PATH=/health
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
apiVersion: v1
kind: List
items:
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-spring-boot-build
creationTimestam: null
displayName: Spring Rest App - Build
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-spring-boot-dev
creationTimestam: null
displayName: Dev - Spring Rest App
displayName: Spring Rest App - Dev
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-spring-boot-stage
creationTimestam: null
displayName: Staging - Spring Rest App
displayName: Spring Rest App - Stage
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-spring-boot-prod
creationTimestam: null
displayName: Prod - Spring Rest App
displayName: Spring Rest App - Prod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,65 @@ metadata:
version: 1.2.0
name: generic-java-jenkins-pipeline
objects:
- apiVersion: v1
kind: ImageStream
labels:
xpaas: 1.4.8
metadata:
annotations:
openshift.io/display-name: Red Hat OpenJDK 8
openshift.io/provider-display-name: Red Hat, Inc.
version: 1.4.8
name: redhat-openjdk18-openshift
namespace: ${IMAGE_STREAM_NAMESPACE}
spec:
tags:
- annotations:
description: Build and run Java applications using Maven and OpenJDK 8.
iconClass: icon-rh-openjdk
openshift.io/display-name: Red Hat OpenJDK 8
sampleContextDir: undertow-servlet
sampleRepo: https://github.com/jboss-openshift/openshift-quickstarts
supports: java:8
tags: builder,java,openjdk,hidden
version: '1.0'
from:
kind: DockerImage
name: registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:1.0
name: '1.0'
- annotations:
description: Build and run Java applications using Maven and OpenJDK 8.
iconClass: icon-rh-openjdk
openshift.io/display-name: Red Hat OpenJDK 8
sampleContextDir: undertow-servlet
sampleRepo: https://github.com/jboss-openshift/openshift-quickstarts
supports: java:8
tags: builder,java,openjdk
version: '1.1'
from:
kind: DockerImage
name: registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:1.1
name: '1.1'
- annotations:
description: Build and run Java applications using Maven and OpenJDK 8.
iconClass: icon-rh-openjdk
openshift.io/display-name: Red Hat OpenJDK 8
sampleContextDir: undertow-servlet
sampleRepo: https://github.com/jboss-openshift/openshift-quickstarts
supports: java:8
tags: builder,java,openjdk
version: '1.2'
from:
kind: DockerImage
name: registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:1.2
name: '1.2'
- apiVersion: v1
kind: ImageStream
metadata:
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
- kind: "BuildConfig"
apiVersion: "v1"
metadata:
Expand All @@ -33,9 +92,9 @@ objects:
type: "JenkinsPipeline"
jenkinsPipelineStrategy:
jenkinsfilePath: ${PIPELINE_SCRIPT}
env:
- name: "BUILD_CONTEXT_DIR"
value: "demo"
env:
- name: "APPLICATION_SOURCE_REPO"
value: "${APPLICATION_SOURCE_REPO}"
- apiVersion: v1
kind: BuildConfig
metadata:
Expand Down Expand Up @@ -69,13 +128,17 @@ parameters:
- description: Git source URI for application
name: SOURCE_REPOSITORY_URL
required: true
value: https://github.com/redhat-cop/spring-rest.git
value: https://github.com/redhat-cop/container-pipelines.git
- description: Git branch/tag reference
name: SOURCE_REPOSITORY_REF
value: "master"
- description: Path within Git project to build; empty for root project directory.
name: CONTEXT_DIR
value:
value: basic-spring-boot
- description: Source code repo for demo app
name: APPLICATION_SOURCE_REPO
required: true
value: https://github.com/redhat-cop/spring-rest.git
- description: Path within Git project pointing to the pipeline run script
name: PIPELINE_SCRIPT
value: Jenkinsfile
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions basic-spring-boot/build/dev/params

This file was deleted.

1 change: 1 addition & 0 deletions basic-tomcat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This example demonstrates how to implement a full end-to-end Jenkins Pipeline fo
* "One Click" instantiation of a Jenkins Pipeline using OpenShift's Jenkins Pipeline Strategy feature
* Promotion of an application's container image within an OpenShift Cluster (using `oc tag`)
* Promotion of an application's container image to a separate OpenShift Cluster (using `skopeo`)
* Automated rollout using the [openshift-appler](https://github.com/redhat-cop/casl-ansible/tree/master/roles/openshift-applier) Ansible role.

## Quickstart

Expand Down
Loading

0 comments on commit 4a5af91

Please sign in to comment.