Skip to content

Commit

Permalink
Use OpenShift Applier
Browse files Browse the repository at this point in the history
  • Loading branch information
pabrahamsson committed Dec 11, 2017
1 parent 796948b commit 38e26d3
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 0 deletions.
3 changes: 3 additions & 0 deletions basic-python-flask/files/builds/dev/params
@@ -0,0 +1,3 @@
APPLICATION_NAME=flask-rest
NAMESPACE=basic-python-flask-build
SOURCE_REPOSITORY_URI=https://github.com/pabrahamsson/python-flask-rest.git
99 changes: 99 additions & 0 deletions basic-python-flask/files/builds/template.yml
@@ -0,0 +1,99 @@
apiVersion: v1
kind: Template
labels:
template: generic-python-jenkins-pipeline
metadata:
annotations:
description: Application template for Flask applications built using a Jenkins Pipeline
iconClass: icon-python
tags: flask, python, jenkins-ci
version: 1.0.0
name: generic-python-jenkins-pipeline
objects:
- kind: BuildConfig
apiVersion: v1
metadata:
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}-pipeline
namespace: ${NAMESPACE}
spec:
source:
type: Git
git:
uri: ${SOURCE_REPOSITORY_URI}
ref: ${SOURCE_REPOSITORY_REF}
contextDir: ${CONTEXT_DIR}
triggers:
- type: GitHub
github:
secret: ${GITHUB_WEBHOOK_SECRET}
- type: ConfigChange
strategy:
type: JenkinsPipeline
jenkinsPipelineStrategy:
jenkinsfilePath: ${PIPELINE_SCRIPT}
- kind: BuildConfig
apiVersion: v1
metadata:
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
spec:
output:
to:
kind: ImageStreamTag
name: ${APPLICATION_NAME}:latest
source:
binary: {}
type: Binary
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: ${IMAGE_STREAM_TAG_NAME}
namespace: ${IMAGE_STREAM_NAMESPACE}
type: Source
parameters:
- description: The name for the application.
name: APPLICATION_NAME
required: true
value: flask-rest
- description: The namespace to deploy into
name: NAMESPACE
required: true
- description: Git source URI for application
name: SOURCE_REPOSITORY_URI
required: true
value: https://github.com/redhat-cop/python-flask-rest.git
- description: Git branch/tag reference
name: SOURCE_REPOSITORY_REF
value: master
- description: Path within Git repository to build; empty for root of repository
name: CONTEXT_DIR
value:
- description: Path within Git repository pointing to the pipeline run script
name: PIPELINE_SCRIPT
value: Jenkinsfile
- description: Github trigger secret
from: '[a-zA-Z0-9]{8}'
generate: expression
name: GITHUB_WEBHOOK_SECRET
required: true
- description: Generic build trigger secret
from: '[a-zA-Z0-9]{8}'
generate: expression
name: GENERIC_WEBHOOK_SECRET
required: true
- description: Namespace in which the ImageStreams for Red Hat Middleware images are
installed. These ImageStreams are normally installed in the openshift namespace.
You should only need to modify this if you've installed the ImageStreams in a
different namespace/project.
name: IMAGE_STREAM_NAMESPACE
required: true
value: openshift
- description: Image stream tag for the image you'd like to use to build the application
name: IMAGE_STREAM_TAG_NAME
required: true
value: python:3.5
4 changes: 4 additions & 0 deletions basic-python-flask/files/deployments/dev/params
@@ -0,0 +1,4 @@
APPLICATION_NAME=flask-rest
NAMESPACE=basic-python-flask-dev
SA_NAMESPACE=basic-python-flask-build
READINESS_RESPONSE=status.:..success
4 changes: 4 additions & 0 deletions basic-python-flask/files/deployments/prod/params
@@ -0,0 +1,4 @@
APPLICATION_NAME=flask-rest
NAMESPACE=basic-python-flask-prod
SA_NAMESPACE=basic-python-flask-build
READINESS_RESPONSE=status.:..success
4 changes: 4 additions & 0 deletions basic-python-flask/files/deployments/stage/params
@@ -0,0 +1,4 @@
APPLICATION_NAME=flask-rest
NAMESPACE=basic-python-flask-stage
SA_NAMESPACE=basic-python-flask-build
READINESS_RESPONSE=status.:..success
137 changes: 137 additions & 0 deletions basic-python-flask/files/deployments/template.yml
@@ -0,0 +1,137 @@
apiVersion: v1
kind: Template
labels:
template: basic-python-flask
metadata:
annotations:
description: Application template for Flask applications built using a Jenkins Pipeline
iconClass: icon-python
tags: python, flask
version: 1.0.0
name: basic-python-fask
objects:
- apiVersion: v1
kind: Service
metadata:
annotations:
description: The web server's http port.
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
spec:
ports:
- port: 8080
targetPort: 8080
selector:
deploymentConfig: ${APPLICATION_NAME}
- apiVersion: v1
id: ${APPLICATION_NAME}-http
kind: Route
metadata:
annotations:
description: Route for application's http service.
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
spec:
host: ${HOSTNAME_HTTP}
to:
name: ${APPLICATION_NAME}
- apiVersion: v1
kind: ImageStream
metadata:
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
spec:
replicas: 1
selector:
deploymentConfig: ${APPLICATION_NAME}
strategy:
type: Rolling
template:
metadata:
labels:
application: ${APPLICATION_NAME}
deploymentConfig: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
spec:
containers:
- image: ${APPLICATION_NAME}
imagePullPolicy: Always
name: ${APPLICATION_NAME}
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
exec:
command:
- /bin/bash
- -c
- curl -s 'http://localhost:8080${READINESS_PATH}'
|grep -iq '${READINESS_RESPONSE}'
terminationGracePeriodSeconds: 60
triggers:
- imageChangeParams:
automatic: true
containerNames:
- ${APPLICATION_NAME}
from:
kind: ImageStreamTag
name: ${APPLICATION_NAME}:latest
type: ImageChange
- type: ConfigChange
- apiVersion: v1
groupNames: null
kind: RoleBinding
metadata:
creationTimestamp: null
labels:
template: basic-python-flask-template
name: jenkins_edit
namespace: ${NAMESPACE}
roleRef:
name: edit
subjects:
- kind: ServiceAccount
name: ${SA_NAME}
namespace: ${SA_NAMESPACE}
userNames:
- system:serviceaccount:${SA_NAMESPACE}:${SA_NAME}
parameters:
- description: The name for the application.
name: APPLICATION_NAME
required: true
value: flask-rest
- description: The namespace to deploy into
name: NAMESPACE
required: true
- description: Name of a service account that can deploy to this project
name: SA_NAME
required: true
value: jenkins
- description: Namespace of service account that can deploy to this project
name: SA_NAMESPACE
required: true
- description: 'Custom hostname for http service route. Leave blank for default hostname,
e.g.: <application-name>-<project>.<default-domain-suffix>'
name: HOSTNAME_HTTP
- description: 'URI to check for app health'
name: READINESS_PATH
required: true
value: '/health'
- description: 'String value expected back from readiness check'
name: READINESS_RESPONSE
required: true
value: 'Hello World!'
27 changes: 27 additions & 0 deletions basic-python-flask/files/projects/projects.yml
@@ -0,0 +1,27 @@
apiVersion: v1
kind: List
items:
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-python-flask-dev
creationTimestamp: null
displayName: Dev - Python Flask App
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-python-flask-stage
creationTimestamp: null
displayName: Staging - Python Flask App
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-python-flask-prod
creationTimestamp: null
displayName: Prod - Python Flask App
- kind: ProjectRequest
apiVersion: v1
metadata:
name: basic-python-flask-build
creationTimestam: null
displayName: Build - Jenkins is here
27 changes: 27 additions & 0 deletions basic-python-flask/inventory/group_vars/all.yml
@@ -0,0 +1,27 @@
---
openshift_cluster_content:
- object: projectrequest
content:
- name: basic-python-flask-spaces
file: "{{ inventory_dir }}/../files/projects/projects.yml"
file_action: create
- object: deployments
content:
- name: jenkins
namespace: basic-python-flask-build
template: openshift//jenkins-ephemeral
params: "{{ inventory_dir }}/../files/deployments/build/params"
- name: basic-python-flask-dev
template: "{{ inventory_dir }}/../files/deployments/template.yml"
params: "{{ inventory_dir }}/../files/deployments/dev/params"
- name: basic-python-flask-stage
template: "{{ inventory_dir }}/../files/deployments/template.yml"
params: "{{ inventory_dir }}/../files/deployments/stage/params"
- name: basic-python-flask-prod
template: "{{ inventory_dir }}/../files/deployments/template.yml"
params: "{{ inventory_dir }}/../files/deployments/prod/params"
- object: builds
content:
- name: jenkins
template: "{{ inventory_dir }}/../files/builds/template.yml"
params: "{{ inventory_dir }}/../files/builds/dev/params"
2 changes: 2 additions & 0 deletions basic-python-flask/inventory/hosts
@@ -0,0 +1,2 @@
[seed-hosts]
localhost

0 comments on commit 38e26d3

Please sign in to comment.