Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python Flask example w/ jenkins-slave builder + sonarqube #1

Merged
merged 3 commits into from
Dec 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions basic-python-flask/files/builds/dev/params
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APPLICATION_NAME=flask-rest
NAMESPACE=basic-python-flask-build
SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/python-flask-rest.git
67 changes: 67 additions & 0 deletions basic-python-flask/files/builds/jenkins-slave-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: v1
kind: Template
labels:
template: jenkins-slave
metadata:
annotations:
description: Template for Jenkins slave
iconClass: icon-jenkins
tags: instant-app,jenkins
name: jenkins-slave
objects:
- kind: BuildConfig
apiVersion: v1
metadata:
labels:
application: ${SLAVE_NAME}
name: ${SLAVE_NAME}
namespace: ${NAMESPACE}
spec:
output:
to:
kind: ImageStreamTag
name: ${SLAVE_NAME}:latest
source:
type: Git
git:
uri: ${SOURCE_REPOSITORY_URL}
ref: ${SOURCE_REPOSITORY_REF}
contextDir: ${CONTEXT_DIR}
strategy:
dockerStrategy:
from:
kind: DockerImage
name: ${JENKINS_IMAGE}
triggers:
- type: ConfigChange
- apiVersion: v1
kind: ImageStream
metadata:
annotations:
slave-label: python
labels:
application: ${SLAVE_NAME}
role: jenkins-slave
name: ${SLAVE_NAME}
namespace: ${NAMESPACE}
parameters:
- description: The name for the application.
name: SLAVE_NAME
required: true
- description: The namespace to deploy into
name: NAMESPACE
required: true
- description: Git source URL for application
name: SOURCE_REPOSITORY_URL
required: true
value: https://github.com/pabrahamsson/jenkins.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: The Jenkins source image
name: JENKINS_IMAGE
required: true
value: openshift/jenkins-slave-base-centos7
4 changes: 4 additions & 0 deletions basic-python-flask/files/builds/jenkins-slave/params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SLAVE_NAME=slave-python
NAMESPACE=basic-python-flask-build
CONTEXT_DIR=slave-python
SOURCE_REPOSITORY_REF=slave-python
109 changes: 109 additions & 0 deletions basic-python-flask/files/builds/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
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_URL}
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:
type: Git
git:
uri: ${SOURCE_REPOSITORY_URL}
ref: ${SOURCE_REPOSITORY_REF}
contextDir: ${CONTEXT_DIR}
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: ${IMAGE_STREAM_TAG_NAME}
namespace: ${IMAGE_STREAM_NAMESPACE}
type: Source
- apiVersion: v1
kind: ImageStream
metadata:
labels:
application: ${APPLICATION_NAME}
name: ${APPLICATION_NAME}
namespace: ${NAMESPACE}
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 URL for application
name: SOURCE_REPOSITORY_URL
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
2 changes: 2 additions & 0 deletions basic-python-flask/files/deployments/build/params
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSTALL_PLUGINS=cobertura:1.12,sonar:2.6.1
MEMORY_LIMIT=512Mi
4 changes: 4 additions & 0 deletions basic-python-flask/files/deployments/dev/params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
APPLICATION_NAME=flask-rest
NAMESPACE=basic-python-flask-dev
SA_NAMESPACE=basic-python-flask-build
READINESS_RESPONSE=status.:..success
195 changes: 195 additions & 0 deletions basic-python-flask/files/deployments/jenkins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
apiVersion: v1
kind: Template
labels:
app: jenkins-ephemeral
template: jenkins-ephemeral-template
metadata:
annotations:
description: |-
Jenkins service, without persistent storage.

WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing.
iconClass: icon-jenkins
openshift.io/display-name: Jenkins (Ephemeral)
openshift.io/documentation-url: https://docs.openshift.org/latest/using_images/other_images/jenkins.html
openshift.io/long-description: This template deploys a Jenkins server capable
of managing OpenShift Pipeline builds and supporting OpenShift-based oauth login. The
Jenkins configuration is stored in non-persistent storage, so this configuration
should be used for experimental purposes only.
openshift.io/provider-display-name: Red Hat, Inc.
openshift.io/support-url: https://access.redhat.com
tags: instant-app,jenkins
name: jenkins-ephemeral
objects:
- apiVersion: v1
kind: Route
metadata:
annotations:
template.openshift.io/expose-uri: http://{.spec.host}{.spec.path}
name: ${JENKINS_SERVICE_NAME}
spec:
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: ${JENKINS_SERVICE_NAME}
- apiVersion: v1
kind: DeploymentConfig
metadata:
annotations:
template.alpha.openshift.io/wait-for-ready: "true"
name: ${JENKINS_SERVICE_NAME}
spec:
replicas: 1
selector:
name: ${JENKINS_SERVICE_NAME}
strategy:
type: Recreate
template:
metadata:
labels:
name: ${JENKINS_SERVICE_NAME}
spec:
containers:
- capabilities: {}
env:
- name: OPENSHIFT_ENABLE_OAUTH
value: ${ENABLE_OAUTH}
- name: OPENSHIFT_ENABLE_REDIRECT_PROMPT
value: "true"
- name: KUBERNETES_MASTER
value: https://kubernetes.default:443
- name: KUBERNETES_TRUST_CERTIFICATES
value: "true"
- name: JENKINS_SERVICE_NAME
value: ${JENKINS_SERVICE_NAME}
- name: JNLP_SERVICE_NAME
value: ${JNLP_SERVICE_NAME}
- name: INSTALL_PLUGINS
value: ${INSTALL_PLUGINS}
image: ' '
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 30
httpGet:
path: /login
port: 8080
initialDelaySeconds: 420
timeoutSeconds: 3
name: jenkins
readinessProbe:
httpGet:
path: /login
port: 8080
initialDelaySeconds: 3
timeoutSeconds: 3
resources:
limits:
memory: ${MEMORY_LIMIT}
securityContext:
capabilities: {}
privileged: false
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /var/lib/jenkins
name: ${JENKINS_SERVICE_NAME}-data
dnsPolicy: ClusterFirst
restartPolicy: Always
serviceAccountName: ${JENKINS_SERVICE_NAME}
volumes:
- emptyDir:
medium: ""
name: ${JENKINS_SERVICE_NAME}-data
triggers:
- imageChangeParams:
automatic: true
containerNames:
- jenkins
from:
kind: ImageStreamTag
name: ${JENKINS_IMAGE_STREAM_TAG}
namespace: ${NAMESPACE}
lastTriggeredImage: ""
type: ImageChange
- type: ConfigChange
- apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}'
name: ${JENKINS_SERVICE_NAME}
- apiVersion: v1
groupNames: null
kind: RoleBinding
metadata:
name: ${JENKINS_SERVICE_NAME}_edit
roleRef:
name: edit
subjects:
- kind: ServiceAccount
name: ${JENKINS_SERVICE_NAME}
- apiVersion: v1
kind: Service
metadata:
name: ${JNLP_SERVICE_NAME}
spec:
ports:
- name: agent
nodePort: 0
port: 50000
protocol: TCP
targetPort: 50000
selector:
name: ${JENKINS_SERVICE_NAME}
sessionAffinity: None
type: ClusterIP
- apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}",
"namespace": "", "kind": "Service"}]'
service.openshift.io/infrastructure: "true"
name: ${JENKINS_SERVICE_NAME}
spec:
ports:
- name: web
nodePort: 0
port: 80
protocol: TCP
targetPort: 8080
selector:
name: ${JENKINS_SERVICE_NAME}
sessionAffinity: None
type: ClusterIP
parameters:
- description: The name of the OpenShift Service exposed for the Jenkins container.
displayName: Jenkins Service Name
name: JENKINS_SERVICE_NAME
value: jenkins
- description: The name of the service used for master/slave communication.
displayName: Jenkins JNLP Service Name
name: JNLP_SERVICE_NAME
value: jenkins-jnlp
- description: Whether to enable OAuth OpenShift integration. If false, the static
account 'admin' will be initialized with the password 'password'.
displayName: Enable OAuth in Jenkins
name: ENABLE_OAUTH
value: "true"
- description: Maximum amount of memory the container can use.
displayName: Memory Limit
name: MEMORY_LIMIT
value: 512Mi
- description: The OpenShift Namespace where the Jenkins ImageStream resides.
displayName: Jenkins ImageStream Namespace
name: NAMESPACE
value: openshift
- description: Name of the ImageStreamTag to be used for the Jenkins image.
displayName: Jenkins ImageStreamTag
name: JENKINS_IMAGE_STREAM_TAG
value: jenkins:latest
- description: Comma-separated list of additional plugins to install on startup. The format of each plugin spec is 'plugin-id:version'
displayName: Additional Jenkins plugins to install
name: INSTALL_PLUGINS
value: ''
4 changes: 4 additions & 0 deletions basic-python-flask/files/deployments/postgresql/params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POSTGRESQL_DATABASE=sonar
VOLUME_CAPACITY=5
POSTGRESQL_PASSWORD=sonar
POSTGRESQL_USER=sonar
Loading